External program using Moi tools/algo/commands

Next
 From:  Defcon
10884.1 
Hello fellow CAD nerds

I would like to know if the API of moi3D allow an external program to do operations ?

The operation would be to import multiple STEP files, and just exporting them in OBJ with a high topology, just that.

Like, let's say I have 40 STEP files in one folder, just drag & drop all my files on a CMD or exe (don't know how that works) and it just convert them in OBJ with high topology using Moi3D tools/algo/whatever it is.

I'm only using Moi3D for that feature, and it's pretty annoying to do all that same procedures by hands.

Thanks
  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
10884.2 In reply to 10884.1 
Hi Defcon, the way you can do something like that is the external program can write out a .js script file that calls into MoI's API and then it can launch moi.exe giving it the path to the script file as a command line parameter.

When launched in that way MoI can be used to process files without showing any of the regular program UI.

There's an example for this type of batch file processing here:
http://kyticka.webzdarma.cz/3d/moi/#Batch

- 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:  Defcon
10884.3 In reply to 10884.2 
Hi Michael,
thank you for your help! I'm gonna take a look and try couple things :)
  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:  Defcon
10884.4 In reply to 10884.2 
I tried that batch file. It's working great and it's what I need!

Just couple things I can't make working.

This is my settings:

NoUI=true
Angle=1
Output=1
MaxLength=0.0
MaxLengthApplyTo=1
MinLength=0.0
AspectRatio=0.0
Weld=true

I was getting some errors while using words "triangles" or "curved", so I replaced them by numbers and it fixed the crashes.
The thing is, whatever angle's value I write, it's always the same density on the exported OBJ, same if I try to export with NGONS.

Could you guide me on this please ? :D

Thanks!
  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
10884.5 In reply to 10884.4 
Hi Defcon, can you post the script code?

- 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:  Defcon
10884.6 In reply to 10884.5 
Yeap!

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.0
// AspectRatio=0.0
// Weld=true
// Display=shadedwithedges | shadednoedges | wireframe
// ExpandedDialog=false

NoUI=true
Angle=1
Output=1
MaxLength=0.0
MaxLengthApplyTo=1
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 );
}

it's the script from the link you posted, I gave it a try to see how it was working, and it fit my need :)
  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
10884.7 In reply to 10884.6 
Hi Defcon, so the parameters need to go into this spot, separated by semicolons:

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

So it should look like 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.0
    // AspectRatio=0.0
    // Weld=true
    // Display=shadedwithedges | shadednoedges | wireframe
    // ExpandedDialog=false

    gd.saveAs( OBJFileName, 'NoUI=true;Angle=1.0;Output=ngons;MaxLength=0.0;MaxLengthApplyTo=curved;MinLength=0.0;AspectRatio=0.0;Weld=true' );

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


Does that get it working how you need?

- 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:  BurrMan
10884.8 In reply to 10884.7 
I think part of the issue might be that at some type of geometry changing the “angle” doesn't create any new polygons.

He may want to start using “divide larger than” to generate more poly’s.

Kindof just guessing from the original “doesnt create more poly’s” info…
  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
10884.9 In reply to 10884.8 
Hi Burr, well also the angle parameter was not actually getting applied in the script code here:
http://moi3d.com/forum/index.php?webtag=MOI&msg=10884.6

It needs to be sent in as a parameter to the moi.geometryDatabase.saveAs() function.

- 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:  Defcon
10884.10 In reply to 10884.7 

I just gave it a try, and it's working perfectly!
Thank you so much :D

Is there a way to remove the need of the BatchConvert.js script, and make it work on just a drag/drop way on the moi3D.exe who have the script path in it ? or through a CMD maybe ?

Or, in the BatchConvert script, a way to tell him to convert every compatible files in that folder.

The idea would be to remove the need of writing the path of each files.

Defcon

EDITED: 27 Oct 2022 by DEFCON

  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
10884.11 In reply to 10884.10 
Hi Defcon,

re:
> Is there a way to remove the need of the BatchConvert.js script, and make it work on just a drag/drop
> way on the moi3D.exe who have the script path in it ?

I don't think there is a way to make it work with drag/drop on moi.exe because that already does something different - MoI will launch and will try to open the file that you dropped and there isn't a way to make your script intercept that.


> or through a CMD maybe ?

That's probably possible. You can make a .CMD batch file get filenames that were drag/dropped onto it like this:
https://taeguk.co.uk/blog/drag-and-drop-batch-files/

Then you'd probably need to make the batch file generate the .js script file with those names in it and then it can launch moi.exe giving it the .js file that was just written.


> Or, in the BatchConvert script, a way to tell him to convert every compatible files in that folder.

It's possible in a MoI script to retrieve a list of all files matching a wildcard pattern inside of a given folder.

Check here for an example:
https://moi3d.com/forum/index.php?webtag=MOI&msg=2100.48

- 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:  Defcon
10884.12 In reply to 10884.11 
Hi Michael,

Awesome!
I added the function to the BatchConvertScript, and it converted the 41 parts in a matter of seconds, where it took me a good 30min manually the other day :D

Thank you so much for your help!
  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
 From:  HansChristian
10884.13 In reply to 10884.1 
If something like making a batch program and using Moi's API in the future isn't possible for some reason you could use an automation program like Uipath (free for individual developers), AutoIt or another one where the software uses a robot to interact with the GUI.
  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