Batch file conversion
 1-20  21-40  41-48
Thread Split: Some posts in this thread were moved from here

Next
 From:  the_captain (JOHNZAPF)
2100.1 
Hi there guys,

I just bought Moi, nice program. I was reading through your posts, thanks for making the batch conversion utility. I actually bought moi to import geometry from Rhino to C4d using the obj format. Nice tessellation. I figured it out but I would suggest posting instructions on how to call a script. I ended up editing a shortcut of the moi.exe that I made for the script specifically. Also, would it be possible to tailor the script to just convert all the files in one directory instead of having to manually make a line for each file you need to convert?

I run a rhino script that saves each layer out to a separate file, would be nice to just save out all files in a folder from moi.

Thanks much

John Zapf

EDITED: 20 Oct 2008 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:  Michael Gibson
2100.2 In reply to 2100.1 
Hi John, thanks very much for your order of MoI, I'm glad that the tessellation will be useful to you!

I think it should be possible to script the conversion of everything in one particular folder by using the FileSystemObject object that is built into Windows, it enables script code in general to gather information about files and folders:

http://msdn.microsoft.com/en-us/library/6kxy1a51(VS.85).aspx

I'll see if I can make up a small example.

- Michael


(P.S. Broke this out into its own separate message thread)
  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.3 In reply to 2100.2 
Here is some sample code from MSDN on using the FileSystemObject to enumerate the files inside of a folder (http://msdn.microsoft.com/en-us/library/18b41306(VS.85).aspx):

code:
function ShowFolderFileList(folderspec)
{
   var fso, f, fc, s;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   f = fso.GetFolder(folderspec);
   fc = new Enumerator(f.files);
   s = "";
   for (; !fc.atEnd(); fc.moveNext())
   {
      s += fc.item();
      s += "<br>";
   }
   return(s);
}


something along those lines should do what you want, I'll see if I can cook that down a bit.

- Michael

EDITED: 20 Oct 2008 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:  the_captain (JOHNZAPF)
2100.4 In reply to 2100.3 
Hi there Michael,

thanks very much for the quick reply, I'll look through it. One other question though, sorry I'm such an inexperience programmer, can you send me an example of the convert script that uses some of the other mesh dialogue options that you have listed such as 'angle=3.0' or something like that?

I tried this,

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

and a couple of other things and didn't seem to work.

Thanks

John
  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.5 In reply to 2100.4 
Hi John, here is the function that can convert everything in a particular folder:
code:
function ConvertFolder( FolderName, FileExtensionToLoad )
{
    // Convert all files within a given folder, that have the given file extension.
    // For example, convert all .3dm files inside of the folder c:\test :
    // ConvertFolder( 'c:\\test', '3dm' );

    // Create the FileSystemObject to get access to files and folders.
    var FSO = new ActiveXObject( 'Scripting.FileSystemObject' );
    var Files = FSO.GetFolder( FolderName ).Files;

    // Go through every file in the folder.
    for ( var FilesEnum = new Enumerator(Files); !FilesEnum.atEnd(); FilesEnum.moveNext() )
    {
        var File = FilesEnum.item();
        var FileName = File.Path;
        var FileExtension = FSO.GetExtensionName( FileName );

        // If the extension matches the kind we are converting, call Convert() on it.
	if ( FileExtensionToLoad.toLowerCase() == FileExtension.toLowerCase() )
            Convert( FileName )
    }    
}


That goes just below the Convert() function, it will call the Convert() function for each matching file that it finds within that folder.

I've also attached an updated version of the BatchConvert.zip file that has the scripts all together in them.

Note - one thing that is easy to get messed up on is that in JavaScript code, the \ character starts an escape sequence which is how you represent certain special characters like return is \r etc... So when you want an actual \ character in a string you have to put in 2 of them, so make sure your file and folder names look like this: 'c:\\test\\folder' when they are in the script code.

- Michael
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.6 In reply to 2100.4 
Hi John,

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

The way it works is that you glue those options together all within the same '    ' quotes, putting semi-colons in between them, like this:


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


Everything between '    ' quotes is considered to be one string object - the options should be one string that has semi-colons in between the different individual options.


Another example with more parameters:


gd.saveAs( OBJFileName, 'NoUI=true;Angle=3.0;Weld=true;MaxLength=4;Output=quads' );


Also another note on the options - in the comments there are some things that are listed as separated by an | - that means "or", so you should only use one of those in those case. Like for instance the description of Output is like this:
// Output=ngons | quads | triangles
That means you can have one of Output=ngons or Output=quads or Output=triangles
Don't put in the actual | character for those ones.


Hopefully that will get you all set up?

- Michael

EDITED: 20 Oct 2008 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:  the_captain (JOHNZAPF)
2100.7 
Michal, thanks so much for responding to me so quickly. I can't wait to try it out. I know that another friend of mine, Jean-Pierre of Moka will be happy with this work. We both do arch-viz. me in LA, him in Germany.

I'll let you know if I have any questions.

Real nice to make your aquaintance.

Thanks much

John
  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:  the_captain (JOHNZAPF)
2100.8 In reply to 2100.7 
Hi there Michael,

works great, I figured out to put the convertfolder call into the batchconvert.js and it seemed to work. That's right right? I'm pretty dense when it comes to programming.

This will really help my workflow


Cheers

John
  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.9 In reply to 2100.8 
Hi John,

> works great, I figured out to put the convertfolder call into the
> batchconvert.js and it seemed to work. That's right right?

yup that's right.

I'm glad this will help!

- 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:  the_captain (JOHNZAPF)
2100.10 In reply to 2100.9 
Hi there Michael,

John here again.

I tried using the batch convert folder setup that you made me yesterday and today but it doesn't seem to work. It runs moi but doesn't save any files. I know it runs it cause when I open moi, and look at recently opened file list, all the layers are there. Could you take a look at my code and make sure that I haven't messed anything up? I tried it on my laptop yesterday and now on my tower at work and no dice.

thanks

John
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.11 In reply to 2100.10 
Hi John, all the code in your script seems to be fine. All the stuff for passing options, etc.. is all set up correctly.

I tried using your same script and shortcut to launch it over here, just with a different folder being passed to ConvertFolder() and everything seemed to work fine.

You've got a really pretty long folder listed there, it's got 8 subfolders in that one path...

It is pretty easy to have a typo in such a long path, and I noticed you've got the first folder in the path repeated twice, is that possibly a typo there?

I'd recommend moving all the files you want to convert over to a more simple folder, like c:\convert - then alter your the line for ConvertFolder in the BatchConvert.js file to say (again, notice the double \\ that is inside of the quote marks, your other version seemed to do that part fine but it is easy to forget this):

ConvertFolder( 'c:\\convert', '3dm' );

That will just make it a lot less likely that you would have any typos in there.


And remove the 3 lines after it that call Convert( 'c:\\scripts\\test\\test1.igs' ) - those were files only on my system so you can just remove those 3 lines for your version.


Does using a more simple folder like c:\convert work any better for you?

- 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:  the_captain (JOHNZAPF)
2100.12 In reply to 2100.11 
Hi there Michael, I had tried that but will give it a shot again.

I'll let you know how it turns out.

Thanks much

John
  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:  the_captain (JOHNZAPF)
2100.13 In reply to 2100.12 
Hi there Michael,

I tried it againl, even with the long file name path and it worked fine. That's the weirdest thing. Must have been some kind of bug on my end. Thanks much again for your help and quick responses.

John
  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.14 In reply to 2100.13 
No problem John, I'm glad it is working for you now!

At some point I should be able to make a plugin that will have a UI for batch file conversion instead of needing to use that typed-in script.

But for now it should get the job done...

- 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.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
 

Reply to All Reply to All

 

 
Show messages:  1-20  21-40  41-48