Exploration of Scripting in MOI

Next
 From:  3d2cnc
9490.1 
This is potentially a work in progress.
Any all comments/help are appreciated.
I am new to the API.
This is first attempt at scripting
I just hope this isn't recreating the wheel, and if .nod would not be the wiser choice

Q: Is there a way to automate iteratively the export of an object's rotated silhouette using Silhouette and Autorotate simultaneously?
Looking at the Silhouette and Autorotate scripts to see if a routine could be made / viable?

Is logic any good?
I am starting off with:

MOI open and running.
Start with object. Select object.
Maintain selection of object?

Silhouette, View in 3D, Incrementally rotate , silhouette object, Select silhouette then join/boolean, export silhouette, increment filename..repeat until Max file reached output or break! Show progress?

Notes:
- fstream out or buffer, saving each silhouette as joined or boolean,
- later to import and even if possibly concatenate those imported from the directory. CSV option?
- Do coords change upon incrementation / rotation of world coords ?

...if only I were more savvy, even so would it work?
None the less, it would make for an interesting script I think.

Any tips or help to create this would be appreciated.

Dave
  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
9490.2 In reply to 9490.1 
Hi Dave, well that would probably be possible but that's quite a few steps involved, it would probably be better to do try some simpler individual scripts to start out with.

Scripting is not well documented in MoI as of yet, there is a little information here: http://moi3d.com/wiki/Scripting but it's kind of hard to get started with it.

- 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:  3d2cnc
9490.3 In reply to 9490.2 
Thank you Michael.

I will pursue the links given.

Dave.
  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:  3d2cnc
9490.4 In reply to 9490.3 
Its not much as of yet, but after hunting down scripts and lots of reading, I have come up with the following so far.
A jumble of code snippets:


//Set to 3D View
script: moi.ui.mainWindow.viewpanel.mode = '3D';

//zoom extents
script: moi.view.resetAll();

//rotation
script: moi.ui.mainWindow.viewpanel.getViewport('3D').rotate( 'up', (1.0) );

//SelectClosedBReps – selects all closed surfaces or polysurfaces.
script: moi.geometryDatabase.getObjects().getSolids().setProperty( 'selected', true );

script:moi.geometryDatabase.selectVisible();

//////////////
/*This is where I cannot find where to select(ALL)....only partial selection works?*/
//////////////

//set variable for incremental save and called it /*this only works if a filename.ext is first saved*/
script: var breps = moi.geometryDatabase.getObjects().getBReps();
var gd = moi.geometryDatabase.incrementalSave();
for ( var iBrep = 0; iBrep < breps.length; ++iBrep ) { var brep = breps.item(iBrep); var edges = brep.getEdges();
for ( var iEdge = 0; iEdge < edges.length; ++iEdge ) { var newedge = edges.item(iEdge).clone(); moi.geometryDatabase.addObject( newedge );
newedge.selected = true; } }
gd;

Well it's a start.

Dave
  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
9490.5 In reply to 9490.4 
Hi Dave, for select all try:

moi.geometryDatabase.selectAll();

If you want to do something that is in the regular UI you can look in the .htm files in the UI subfolder to see what it's doing. Most stuff is in SidePane.htm so for example if you search in there for "SelectAll" that would take you to a button with with some script on it's onclick="" handler with the above code in it.

Also if you have your code above in its own .js file you can leave off the "script:" parts in front, that's something that you can put in the start of a shortcut key definition to tell the shortcut key processor that it's a chunk of script code in the shortcut key instead of a command name.

- 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:  3d2cnc
9490.6 In reply to 9490.5 
Hi Michael,

That information was very useful. Thank-you so much.

Have setup hotkeys for the scripts that are working thus far.



Unsuccessfully trying to Imitate your " Include Edge Option " in the Silhouette Script.

Currently cannot get the objects edges silhouette to happen correctly.

Hoping to avoid using the sidepane silhouette icon and having to select "Include edges" checkbox.

Looking for easier solution to script that "Include Edge Option" .

Any tips on what steps to take?

P.S.
Moi has been great for designing structures. "Quickly". Although I haven't used it for any piping designs as of yet, but it looks like a snap.

Dave
Image Attachments:
Size: 1009.5 KB, Downloaded: 40 times, Dimensions: 1364x807px
  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:  3d2cnc
9490.7 In reply to 9490.6 
So far coming out of this endeavor to create this proposed script is...

Combining the freehand from two axis planes, loft and use this

well, create a terrain map on an object?
Attachments:

Image Attachments:
Size: 356.2 KB, Downloaded: 19 times, Dimensions: 806x709px
Size: 428.6 KB, Downloaded: 13 times, Dimensions: 859x745px
  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:  Michael Gibson
9490.8 In reply to 9490.6 
Hi Dave, that's great that you're making good progress!

So for include edges the way to figure out how to replicate that in a script is to first look at the Silhouette.htm file and find the "Include edges" button which is this:

code:
<moi:CheckButton id="includeedges"><moi:Text textid="Include edges checkbox"/></moi:CheckButton>


The key thing that you're looking for is the id value. So then go to the Silhouette command script file (Silhouette.js) and search for includeedges, which is this:

code:
ui.bindUIToInput( 'includeedges', 'value', factory.getInput(4) );


So what the regular command is doing there is making a link between the includeedges checkbox UI controls's value property and the silhouette factory's input with index 4.

In your script you'd want to do something like factory.setInput( 4, true ); to turn it on.

Some UI will set up a binding like that and others will look for a UI event of that id value being triggered if they need to do other stuff in addition to just setting a value on the factory.

Hope that helps!

- 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