Batch file conversion
 1-14  15-34  35-48
Thread Split: Some posts in this thread were moved from here

Previous
Next
 From:  Micha
2100.15 In reply to 2100.14 
Hello,

I try to export a geometrie from Rhino to MOI3D for meshing and reimport. My Rhino button script is:

_-export "d:\temp\moi.3dm" _enter _enter
_-run "C:\Program Files (x86)\MoI 2.0\batchconvert.js"

and the script at batchconvert.js is

// This is the script file that you would generate, put one line in
// for each file you want to convert.

#include "Convert.js"

Convert( 'd:\\Temp\\moi.3dm' );


moi.exit( true ); // Pass true to suppress save changes prompt.

but I get the Windows error message


What did I wrong?

Ciao,
Micha
Attachments:

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  BurrMan
2100.16 In reply to 2100.15 
It could be the script is hard coded to the "C" drive.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Micha
2100.17 In reply to 2100.16 
The problem seem to be the first character of

#include "Convert.js"

PS: I use XP64
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
2100.18 In reply to 2100.15 
Hi Micha, you need to run MoI.exe as the primary program that is launched, and then that should take the batchconvert.js as a command-line parameter to MoI.exe

So for example your _run command in Rhino should look something more like this:

_-run "C:\Program Files (x86)\MoI 2.0\MoI.exe C:\Program Files (x86)\MoI 2.0\batchconvert.js"


By trying to run the batchconvert.js directly, that means that it is running the "Windows script host" script processor which is by default the program that is associated in the Window shell with files that end in .js .


But I'm not quite sure if the Run command is going to work completely properly with both a file name and command line options which each have spaces in them, you may need to do something like put quotes around the file name and the command-line part separately, but I'm not sure if that can be done properly with Rhino's run command.


If the above doesn't work because of not having the .exe and the command-line options have separate quotes, then a work-around that should probably work would be to make a Windows batch file (with a .bat or .cmd file extension) which will do the actual launch of MoI with the command line parameter and have the Rhino _run command call the batch file instead of calling MoI.exe directly.

Let me know if you still need some help getting set up.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Micha
2100.19 In reply to 2100.18 
The problem is still alive if I start the batchconvert.js without Rhino. The batch file should work per double click or? I get the error, that this line dosn't work.

#include "Convert.js"

If the #include dosn't work, could I start a single *.js without a call of an extern code?
Something like this:

function Convert(...here the name of the *.3dm file...)
{
var gd = moi.geometryDatabase;

// Open the file, set 2nd param to true to suppress any save changes prompt.
gd.open( FileName, true );

// Create the output file name by breaking off the file extension and adding 'obj'.

OBJFileName = FileName.substr( 0, FileName.lastIndexOf('.') + 1 ) + 'obj';

// Save out to the output file, passing the option to suppress the UI. You
// add other options separated by semi-colons with no spaces. These
// options are available for controlling the meshing:
// NoUI=true
// Angle=12.0
// Output=ngons | quads | triangles
// MaxLength=0.0
// MaxLengthApplyTo=curved | planes | all
// MinLength=0.0
// AspectRatio=0.0
// Weld=true
// Display=shadedwithedges | shadednoedges | wireframe
// ExpandedDialog=false

gd.saveAs( OBJFileName, 'NoUI=true' );

// Let's clear out and suppress any save changes prompt again.
gd.fileNew( true );
}

moi.exit( true ); // Pass true to suppress save changes prompt.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
2100.20 In reply to 2100.19 
Hi Micha - the problem is that you can't try to start the batchconvert.js file all by itself directly.

For example if you go to Start / Run in Windows and type in "batchconvert.js" there, or if you were to double-click on "batchconvert.js" in the Windows explorer, that is not going to work because your system will have the "wscript.exe" program (windows script host) set up to execute when any file with a ".js" extension is launched. So that will launch wscript.exe and not MoI.

This is similar to how double-clicking on a file that ends with ".doc" will open Microsoft word, etc...

Instead of running the windows script host, you want to run the MoI.exe program and tell MoI.exe to load the .js file by passing the file name as a parameter to MoI.exe.

You can't make this happen by trying to run the .js file directly (unless you change the file associations for .js files for your computer) - the primary thing you need to launch is "MoI.exe" and then you tell it to load batchconvert.js by giving a command-line parameter to MoI.exe .

To do this with the Rhino "Run" command, I think you will need to set up a separate batch file that runs MoI.exe, because I don't know if there is a way for Rhino's run command to group the MoI.exe path and the .js file path properly with " " characters around each of them.

I've attached a batch file here which I think will work for you - unzip the attached .zip file to get the file named LaunchMoIBatchConvert.cmd - that is a batch file which is set up to launch MoI.exe and pass it the batchconvert.js as a command line parameter, with the 2 parts grouped with quotes as required for things with spaces in them.

So to make it all work you can have Rhino's run command run that LaunchMoIBatchConvert.cmd and it should then work for you.

If you open up LaunchMoIBatchConvert.cmd in notepad you can see that it is just one line that says:

code:
"C:\Program Files (x86)\MoI 2.0\MoI.exe" "C:\Program Files (x86)\MoI 2.0\batchconvert.js"


Note how there are 2 statements grouped with " " characters - the first one is for the path to Moi.exe which is the program you need to launch, and you need to put quotes around its path because there are spaces in it.

Then after the .exe is the path to batchconvert.js, which will be sent as a command-line parameter to MoI.exe after it is launched and MoI will see that and then load and execute that script file.

Does that make sense? Please let me know if you still have any problems.

- Michael

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
2100.21 In reply to 2100.19 
Hi Micha, just one more note:

> The batch file should work per double click or? I get the error,
> that this line dosn't work.

The double-click on a .js from Windows file explorer does not work with MoI.

You could make it work that way if you want by changing the file association for .js files (to do this, right-click on one and pick the "Open with" menu item and then pick MoI.exe as the program to use, and check the "Always use the selected program to open this kind of file"). But I wouldn't really recommend that.

.js is a kind of common generic file extension meaning "JavaScript file" - MoI doesn't use a special purpose extension for script files, which maybe you are used to since Rhino uses a custom ".rvb" file extension I guess?

For MoI it is expected that you run MoI.exe and then pass it the name of the script file, rather than trying to launch the script file on its own independently.

I guess I could make a special extension for a "MoI script file", rather than the generic .js extension, but it is sort of nice to not add a whole bunch of customized file types if they are not necessary...

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Micha
2100.22 In reply to 2100.20 
Thank you very much - it works phantastic!

Here some code I change, maybe useful for other user.
I edit the convert.js file, so that the meshing UI popup and I can choose specific parameters:

---------------
function Convert(FileName)
{
var gd = moi.geometryDatabase;

// Open the file, set 2nd param to true to suppress any save changes prompt.
gd.open( FileName, true );

// Create the output file name by breaking off the file extension and adding 'obj'.

OBJFileName = FileName.substr( 0, FileName.lastIndexOf('.') + 1 ) + 'obj';

// Save out to the output file, passing the option to suppress the UI. You
// add other options separated by semi-colons with no spaces. These
// options are available for controlling the meshing:
// NoUI=true
// Angle=12.0
// Output=ngons | quads | triangles
// MaxLength=0.0
// MaxLengthApplyTo=curved | planes | all
// MinLength=0.01
// AspectRatio=0.0
// Weld=true
// Display=shadedwithedges | shadednoedges | wireframe
// ExpandedDialog=false

gd.saveAs( OBJFileName, 'Angle=12.0;MinLength=0.01;MaxLength=1000;AspectRatio=20;Weld=true;Output=quads');

// Let's clear out and suppress any save changes prompt again.
gd.fileNew( true );
}
------------

My Rhino button scripts are:

_-export "d:\temp\moi.3dm" _enter _enter
_-run "C:\Program Files (x86)\MOI 2.0\LaunchMoIBatchConvert.cmd"

_delete
_-import "d:\temp\moi.obj" _enter

The second button script delete the NURBS object and place the mesh at the same place. Here a simple button image to make it complete.


For quick meshing I create an automatic button, that doe's all this without meshing UI.

The modified scripts are attached and here the button script:

_-export "d:\temp\moi.3dm" _enter _enter
_-run "C:\Program Files (x86)\MOI 2.0\LaunchMoIAutoConvert.cmd"
_delete
_-import "d:\temp\moi.obj" _enter

There is a problem with the automatic button - the moi.obj is imported before the meshing is finished. I think, it could be good to add a command or switch, so that the script wait until the meshing is finished. I would like to avoid a wait command with a fixed time. Anybody has an idea? ;)

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
2100.23 In reply to 2100.22 
Hi Micha, I guess for the automatic version to work you would need some different behavior for the Rhino _run command.

You'd want a version that ran the program and also waited for that program to exit before it let Rhino continue on normally.

You might want to ask in the Rhino newsgroup if anyone out there has developed a plugin to do that task already.

If not, that may be a good enhancement request for the regular Rhino _run command to be able to take an optional scriptable "WaitForExit=true" or something like that.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Micha
2100.24 In reply to 2100.23 
Thank you for the hints. I will ask at the Rhino forum.

Michael, is it possible to pack all scripts in one *.cmd file, so that I could create different files for

* open MOI3D with a 3dm model
* meshing with UI
* meshing full automatic

I have the feeling the convert.js and the batchconvert.js could be packed in one file and maybe this script could be packed in the *.cmd file.
I try to get it clearly arranged. :)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
2100.25 In reply to 2100.24 
Hi Micha - some pieces can be combined into one - the 2 .js files can be combined into a single .js file.

To do that, just find the spot where one file is doing an #include of the other file, and remove that line and paste in the contents of that included file.

#include is just a way of saying "paste the contents of this other file here".


However, I don't think there is a good way to combine the .cmd file with the .js ones - those are being used and run by different things.

The .cmd file is being run by the Windows shell, and the .js files are run by MoI.exe .

Since they are run by different programs, I don't think that you can combine them, that is kind of like saying how can you combine this Word .doc file with this .3dm rhino file - they are both files with data in them but they are used by different things so they can't necessarily be combined.

But it may be possible to actually eliminate the .cmd file entirely if you can figure out a way to make Rhino's _run command take 2 sets of parameters surrounded by quotes - one for the path to moi.exe and one for the command-line arguments to give to moi.exe .

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Micha
2100.26 In reply to 2100.25 
Sorry, so much questions. I try to send a file to MOI, so that it is shown and the meshing dialog is open. It's like this script, but in the background should be visible the MOI interface for a visible control of the meshing. Is this possible? I found no option to enable the general UI.


function Convert(FileName)
{
var gd = moi.geometryDatabase;

// Open the file, set 2nd param to true to suppress any save changes prompt.
gd.open( FileName, true );

// Create the output file name by breaking off the file extension and adding 'obj'.
OBJFileName = FileName.substr( 0, FileName.lastIndexOf('.') + 1 ) + 'obj';

// Save out to the output file, passing the option to suppress the UI. You
// add other options separated by semi-colons with no spaces. These
// options are available for controlling the meshing:
// NoUI=true
// Angle=12.0
// Output=ngons | quads | triangles
// MaxLength=0.0
// MaxLengthApplyTo=curved | planes | all
// MinLength=0.01
// AspectRatio=0.0
// Weld=true
// Display=shadedwithedges | shadednoedges | wireframe
// ExpandedDialog=false
gd.saveAs( OBJFileName, 'Angle=12.0;MinLength=0.01;MaxLength=1000;AspectRatio=20;Weld=true;Output=quads');

// Let's clear out and suppress any save changes prompt again.
gd.fileNew( true );
}
Convert('d:\\Temp\\moi.3dm');
moi.exit( true ); // Pass true to suppress save changes prompt.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
2100.27 In reply to 2100.26 
Hi Micha, sorry no there is not currently any way to make the main window displayed when you run MoI with a command-line script.

This method of launching a script given with a command-line parameter was mostly intended as a way to have MoI silently process things in the background.

But I don't think it should be difficult for me to add another parameter that you can specify on the command line options that will make MoI show its regular user interface for this, I'll give that a try for the next v2 beta.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Micha
2100.28 In reply to 2100.27 
Thank you for all your effort. :)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
2100.29 In reply to 2100.26 
Hi Micha,

> It's like this script, but in the background should be
> visible the MOI interface for a visible control of the meshing.

I've updated the next v2 beta so that it will now be possible to make this work (to have the full UI displayed so you can see the viewports and mesh result while running the batchconvert.js script).

The way it works is you specify /showwindow as an additional command-line parameter for MoI.exe .

For example I have attached an updated LaunchMoIBatchConvert.cmd file that has this set in it.

Again this will work not in the existing Jan-19 current beta, but should work in the next released one. Hopefully it will not be too much longer before the next one is ready maybe something like a week but it is hard to say exactly.

Once the next beta is out, please let me know if you run into any problems with this new option.

- Michael

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Micha
2100.30 In reply to 2100.29 
I'm curious - thank you.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Micha
2100.31 In reply to 2100.30 
Hi Michael,

I tried the new command now. My workflow was, that I select a NURBS object at Rhino and press my "Moi" button

_-export "d:\temp\#moi.3dm" _enter _enter
_-run "C:\Program Files (x86)\MOI 2.0\MOIConvert.cmd"

than the CMD was started

"C:\Program Files (x86)\MoI 2.0\MoI.exe" "C:\Program Files (x86)\MoI 2.0\MOIConvert.js"

and the MOI meshing UI pop up.

But if I add the /showwindow to the CMD file, than I get the MoI UI only, without NURBS object and meshing UI. Do you have an idea what's wrong here?

The MOIConvert.js contain this code:

function Convert(FileName)
{
var gd = moi.geometryDatabase;

// Open the file, set 2nd param to true to suppress any save changes prompt.
gd.open( FileName, true );

// Create the output file name by breaking off the file extension and adding 'obj'.

OBJFileName = FileName.substr( 0, FileName.lastIndexOf('.') + 1 ) + 'obj';

// Save out to the output file, passing the option to suppress the UI. You
// add other options separated by semi-colons with no spaces. These
// options are available for controlling the meshing:
// NoUI=true
// Angle=12.0
// Output=ngons | quads | triangles
// MaxLength=0.0
// MaxLengthApplyTo=curved | planes | all
// MinLength=0.01
// AspectRatio=0.0
// Weld=true
// Display=shadedwithedges | shadednoedges | wireframe
// ExpandedDialog=false

gd.saveAs( OBJFileName, 'Angle=12.0;MinLength=0.01;MaxLength=1000;AspectRatio=20;Weld=true;Output=quads');

// Let's clear out and suppress any save changes prompt again.
gd.fileNew( true );
}
Convert('d:\\Temp\\#moi.3dm');
moi.exit( true ); // Pass true to suppress save changes prompt.

And other question to this topic - could it be possible, that an automatic reset of the views is done after a file is opened? The problem is, if I try to mesh an object from Rhino, than the object could be outside the default view.

An other poblem, but not so important - the display mesh show some artefacts at this opended Rhino sphere. Is it normal? The exported mesh looks good, so it no problem for the daily workflow here.

Regards,
Micha

Attachments:

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
2100.32 In reply to 2100.31 
Hi Micha,

> Do you have an idea what's wrong here?

I suspect something may not be right with your MOIConvert.cmd - make sure when you add the /showwindow parameter that it has a space character separating it from any other parameters. Otherwise if things are not separated by spaces they become glued together into one parameter.

So for instance a .cmd file with content like this should work (this is tested with my machine):
code:
"c:\program files\MoI 2.0 beta Apr-12-2009\moi.exe" "c:\scripts\MOIConvert.js" /showwindow

If that is not what was going wrong, please show me exactly what content you have for your .cmd file.


> And other question to this topic - could it be possible, that an
> automatic reset of the views is done after a file is opened?

Yup, this is easy to add - modify your MOIConvert.js file to have a new line of code added with a call to moi.view.resetAll(), after the call to open(), like this:

// Open the file, set 2nd param to true to suppress any save changes prompt.
gd.open( FileName, true );

moi.view.resetAll();



> An other poblem, but not so important - the display mesh
> show some artefacts at this opended Rhino sphere. Is it normal?

No, that is not supposed to happen. It looks like a bug, similar to one that I had thought was fixed up.

Does this happen to any sphere or only one in a particular location?

Can you please post the sphere so I can double check that? If that bug is still in there, it could possibly have an effect on exports in other situations so it would be good for me to take a look at it.


By the way, I think that now with this new release all the bugs you reported in that other thread should be fixed up - there were a few different ones like "Avoid smaller than" sometimes not working well and increasing polygon count when there were long skinny parts, aspect ratio not working well with that one surface with a pole, also incorrect normals on that same one with a pole also fixed, I think there was a triangle leak thing that was fixed (your Mesh#5 example), and also some quads that were split into triangles which will now stay as quads. Also one that had a flat plane with a couple of small spikes coming up from it. I don't think that there are any bugs left that you reported there. But I have not yet had a chance to add in new meshing parameters yet though.

- Michael

EDITED: 15 Apr 2009 by MICHAEL GIBSON

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Micha
2100.33 In reply to 2100.32 
:) That's great, thank you for the hints. Anything works like expected now, the workflow makes fun.

Sorry, something was wrong with my new beta install path and so the sphere mesh issue was, because the old beta was opened. I fix my install error and anything is fine now. :)

A question for further improvements of the Rhino2MoI meshing. Do you see a chance to keep the Rhino layers so that the imported meshes are back to the original layers? If I remember me right I read that you plan to name the mesh material names by style names? I don't know so much about Rhino scripting, but could it be possible per Rhino script, that the reimported meshes are saved to layers with the material name?
Best would be, if the Rhino material and layers could be keeped during MoI meshing. I know, that's not your job, but maybe you have an idea. ;)
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
2100.34 In reply to 2100.33 
Hi Micha, that's great that it is working for you now.

> Do you see a chance to keep the Rhino layers so that the
> imported meshes are back to the original layers?

Well, I guess it depends on what kinds of things Rhino's OBJ importer will read from the OBJ file.

I don't know if it will read in material definitions or not... These are "usemtl" statements in the OBJ file, which I do plan to generate from the style assignments in MoI (not working quite yet though).

If Rhino's OBJ importer is able to construct layers from material assignments, then I guess you will be all set up.

But if it doesn't, maybe there will be some other possibilities, like if it does read in an object name maybe before generating meshes the export script can be modified so that each object is given a name for the style/layer that it is on, then if that information is read into Rhino it would be possible to have a script in Rhino that would look at object names and put those objects on those layers.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
Show messages:  1-14  15-34  35-48