Scripting  1-20  21-40  41-55

Next
 From:  eric (ERICCLOUGH)
7238.1 
First, thanks to everyone who has contributed scripts to this forum. Some I use every day.

It has been many years since I have done any programming at all, though I did once write a bunch of engineering programs when they weren't available commercially yet.

I would like to find a tutorial or book that will start at the beginning so that I can learn basic scripting ... any suggestions?

thanks,
eric
  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:  Frenchy Pilou (PILOU)
7238.2 In reply to 7238.1 
Scripting for Moi or in general ?
---
Pilou
Is beautiful that please without concept!
My Gallery
  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:  eric (ERICCLOUGH)
7238.3 In reply to 7238.2 
Hi Pilou ..

I specifically want to use scripting for MoI but would also like to understand scripting in general.

chyeers.
eric
  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
7238.4 In reply to 7238.1 
Hi eric, so unfortunately currently there isn't any MoI-specific tutorials and such for script writing. To do it basically requires studying existing scripts and figuring things out from that.

There is some very minimal information and a few links here: http://moi3d.com/wiki/Scripting

At some point in the future I expect to do a lot more work to make both using and learning MoI scripting a lot easier than it currently is, but there is a lot of time consuming work involved in doing that and it hasn't yet risen to the top of my priorities yet. I'm still a lot more focused on more "regular end user" things rather than "power user scripting" type stuff as of yet.

One thing that can help is if you get familiar with the JavaScript language - that's the language that MoI uses for scripting. There is quite a lot of general information out there on the web on JavaScript since it is the main language used by web browsers for doing scripting in a web page. So doing a search for something like "html javascript tutorials" can get you some stuff for getting started on JavaScript putting it in a web page to start with. For example: http://www.w3schools.com/js/

- 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:  eric (ERICCLOUGH)
7238.5 In reply to 7238.4 
Thanks Michael ..

I'm pleased to know that Java script is what MoI uses. I am a little familiar with Java Script and will explore it further.

cheers,
eric
  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:  Martin (MARTIN3D)
7238.6 In reply to 7238.5 
Hi Eric there is a MoI JavaScript documentation by David Morill that helps a lot when you're familiar with JavaScript.
http://moi.maxsm.net/api/

Here are some examples how to do some things in MoI using factories. Just look up the command you want to use and see what inputs are required. For instance for a line the factory requires two points.

Draw a line
code:
script:
var factory = moi.command.createFactory( "line" );
factory.setInput( 0, moi.vectorMath.createPoint( 0, 0, 0 ) );
factory.setInput( 1, moi.vectorMath.createPoint( 40, 40, 40 ) );
factory.commit();


Draw a circle on xz (Front) plane
code:
script:
var factory = moi.command.createFactory( 'circle' );
factory.setInput( 1, moi.vectorMath.createFrontFrame() );
factory.setInput( 3, 10 );
factory.commit();


Draw a box
code:
script:
var factory = moi.command.createFactory( 'box' );
factory.setInput( 0, moi.vectorMath.createFrame() );
factory.setInput( 2, 20 );
factory.setInput( 3, 20 );
factory.setInput( 4, 20 );
factory.commit();


Draw some text
code:
script:
var factory = moi.command.createFactory( 'text' );
factory.setInput( 0, moi.vectorMath.createTopFrame() );
factory.setInput( 1, "Hello World" ); 
factory.setInput( 2, "Arial" ); 
factory.setInput( 3, false ); 
factory.setInput( 4, false );
factory.setInput( 5, 'Curves' );
factory.setInput( 6, 10 ); 
factory.commit();



Just copy each script to the clipboard, hit TAB in MOI, paste the script and press ENTER.
Experiment and enjoy
Martin
  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:  dune1982
7238.7 In reply to 7238.6 
Hello,
I made a script that draws a triangle (3 curves), now i want the network command to make a surface inside of that triangle. I just cant get it to work.
The end of my script now (everything that works) is that the cuves are selected, I just can't get the network command to work.

How would you scripting experts do that?
  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
7238.8 In reply to 7238.7 
Hi dune1982, can you post your current script that shows what you are trying to do to make the network which is not working for you?

You basically need to take the guts of the regular Network command from Network.js and do the same thing in your own script, like create a network factory, set the inputs on it, etc...

- 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:  dune1982
7238.9 In reply to 7238.8 
Hello Michael,
this is what works so far:

function drawLine(x1,y1,z1,x2,y2,z2)
{
var linefactory = moi.command.createFactory( "line" );
linefactory.setInput( 0, moi.vectorMath.createPoint( x1, y1, z1 ) );
linefactory.setInput( 1, moi.vectorMath.createPoint( x2, y2, z2 ) );
linefactory.commit();
}

drawLine(0,0,0,10,0,0);
drawLine(10,0,0,10,10,0);
drawLine(10,10,0,0,0,0);

moi.selection.setFilter( 'Types', 'Curves', true );
var objects = moi.geometryDatabase.selectAll();
moi.selection.clearSelectionFilters();

Now I need the stuff from the network.js, but I don't want any manual input.

This is what i took from network.js

var objectpicker = moi.ui.createObjectPicker();
objectpicker.allowCurves();

var objects = objectpicker.objects;
objects.sortBySelectionOrder();

var factory = moi.command.createFactory( 'network' );
factory.setInput( 0, objects );

moi.ui.bindUIToInput( 'mode', 'value', factory.getInput(4) );
factory.commit();

There is no meaning to this script, I'm just trying to understand.
  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
7238.10 In reply to 7238.9 
Hi dune1982, Network probably fails unless you have some more of the inputs set on it, I'll see if I can adjust your example to make it work.

This line for instance is for connecting a checkbox value to the factory input, it won't do anything if you don't have a UI element with id="mode":
moi.ui.bindUIToInput( 'mode', 'value', factory.getInput(4) );

Also it's not too good to rely only on things like "select all" because if you happen to have other curves in the model instead of it starting out totally blank it will gather those other ones up too. I'll see about adjusting that as well.

- 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
7238.11 In reply to 7238.9 
Hi dune1982, so your example failing not because network needs more inputs set on it, but because your object list is empty.

That's because the object picker is really meant for user interactive object picking - objectpicker.objects will only be populated if you call GetObject( objectpicker ) , which can return immediately though if there are preselected objects.

If you just want to grab the current selected objects rather that waiting with an event loop where the user could modify the selection, you don't need to use the object picker you could instead call moi.geometryDatabase.getSelectedObjects(). Similarly if you want to get all curves you don't need to do it by selection you can do moi.geometryDatabase.getObjects().getCurves()

But anyway instead of grabbing all curves you probably should only grab the specific lines that you are creating, see the attached file for a demo of that.

Hope this helps!

- 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:  wastzzz
7238.12 In reply to 7238.11 
Anyone could post an example of the offset command via script?
I am trying to make an offset of a line I have calculated but I can't get it to work.
Any help would be appreciated..


[...]
var factory = moi.command.createFactory( 'line' ); //Calculating a line from previous points
factory.setInput( 0, crv.getStartPt() );
factory.setInput( 1, crv.getEndPt() );
var output = factory.calculate();

var factory = moi.command.createFactory('offset'); //Calculating the offset of line
factory.setInput( 0, output);
factory.setInput( 1, 3);
factory.commit();

M.
  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
7238.13 In reply to 7238.12 
Hi Max, re: offset

One problem there is that offset is one of the factories that does an "asynchronous" calculation - that's where it the work actually happens over on a separate moi_commandprocessor.exe process which is used for potentially long running calculations so the main UI does not just freeze while the long calculation is happening.

For async factories it is required that the objects that it use should be in the geometry database and not just a "loose object" which is what .calculate() returns back.

I'll try in v4 to remove this restriction, but for now if you put in moi.geometryDatabase.addObjects( output ); before doing the offset that will be one step that will be needed.

Then in addition to that there is another input that is required on the offset factory in order for it to work, which is the coordinate frame input. The various inputs on the offset factory are like this:

Offset inputs:
0 : object list - objects to offset
1 : number - distance to offset for distance mode, leave unset for "through point" mode.
2 : coordinate frame - point and coordinate frame for "through point" or "which-side" point for distance mode with curve offset
3 : string - corner type for curve offset either "sharp" or "round".
4 : boolean - Trim, true = trim curve results
5 : boolean - Flip, true = flip offset side (for solid/surface offsets not curve offsets)
6 : boolean - Both sides, true = offset curves to both sides
7 : boolean - Cap ends, true = add line segments between ends of open offsets.

Here's an offset example that works:

var factory = moi.command.createFactory( 'line' );
factory.setInput( 0, moi.vectorMath.createPoint( 3,1,0 ) );
factory.setInput( 1, moi.vectorMath.createPoint( 10,10,0 ) );
var output = factory.calculate();
moi.geometryDatabase.addObjects( output );

var factory = moi.command.createFactory('offset'); //Calculating the offset of line
factory.setInput( 0, output);
factory.setInput( 1, 3 );

// Creates a coordinate frame with origin at 0,0,0 and with x/y axes along world x/y axis directions.
var frame = moi.vectorMath.createTopFrame();
factory.setInput( 2, frame );

factory.commit();





- 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:  wastzzz
7238.14 In reply to 7238.13 
Thank you Michael.
Keep up the good work.
M.
  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:  dune1982
7238.15 In reply to 7238.11 
Thank you for your TestNetwork script, that really helped me understanding.

But now I'm at the next thing.
`var objlist = moi.geometryDatabase.createObjectList();
objlist.addObject( linea );
objlist.addObject( lineb );
objlist.addObject( linec );


var factory = moi.command.createFactory( 'network' );
factory.setInput( 0, objlist );

factory.commit();
`
What does the 0 stand for?

I tried to make this script with 9 lines ergo 3 triangles with network command one triangle at a time, this only seems to work it the objlist is created new for each triangle, so for each triangle I have to make a new var objlist = moi.geometryDatabase.createObjectList();

Does the network always take the first three objekts in the list? Is there a way to empty the list so it is not necessary to recreate it?

Last question what exactly does factory.commit(); do? As far as I understand it makes MoI Display the network on the UI. I have recognized that it takes the computer some time to do the factory.commit(); for each network again and again. Can't I let the network command create the three networks and then do the factory.commit(); at the end to only update the ui once?
  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:  bemfarmer
7238.16 In reply to 7238.15 
  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
7238.17 In reply to 7238.15 
Hi dune1982,

> What does the 0 stand for?

It's the index number for which specific factory input to set.

Geometry factories can have various different inputs in them, they are in a list and when you call factory.setInput() that number tells it which of the different inputs you want to set for this particular call.


> Does the network always take the first three objekts in the list?

It uses whatever objects are put in the list - if it has 3 objects in the list it will use those 3 objects. If you have 11 objects in the list it will use those 11 objects.


> Is there a way to empty the list so it is not necessary to recreate it?

Creating a list is not an expensive operations so there is no need to worry about avoiding creating one. The easiest way to get an empty list is to make a new one - you can remove objects from an object list by calling list.removeObject(obj); but you would need to loop through the object list and call this on each object in order to do it that way.


> Last question what exactly does factory.commit(); do?

First it calls factory.update() automatically if it has not been called previously. factory.update() creates the new object and puts it in the geometryDatabase so that it can be seen. Also factory.update() deals with hiding any input objects if the factory is one that removes some existing object (like for example Transform > Move removes the original object being moved and creates a new moved object). If the command ends without factory.commit() being called these changes are reverted, with the newly added objects removed and the objects to be removed shown again. When you call factory.commit() it finalizes the factory's action and actually deletes the objects to be removed and will keep the newly created objects.

With a normal command, as you adjust various options factory.update() will be called so you can see the result on screen. Then at the end when the command is finished it called factory.commit() to make the last update stick. If the command is canceled in any way without .commit() ever being called any changes it made are reverted.


> Can't I let the network command create the three networks and then do the factory.commit(); at the end to only update the ui once?

No, not with the regular factory.update() and factory.commit() mechanism, because that mechanism is oriented around the workflow of the regular Network command and there is no way in the regular Network command to build 3 networks in one shot.

But instead of calling update() and commit(), it is possible to use a different mechanism which is called factory.calculate() - if you call factory.calculate() it will return an object list of what the factory generates but it does not automatically put it in the geometry database like update/commit does, so you can then batch up the results and then call moi.geometryDatabase.addObjects( objectlist ); to add them in one shot.

- 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:  dune1982
7238.18 In reply to 7238.17 
Thank you Michael for explaining all this for me.

I had a look at http://moi.maxsm.net/ because I wanted MoI to draw a cylinder.

I thought I had understood it, but it seems that I have not.

This is what I came up with:

`script:
var factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, moi.vectorMath.createFrame() );

factory.setInput( 3, 20 );
factory.setInput( 5, 10 );


factory.commit();`

which ends with MoI drawing a circle.
  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:  bemfarmer
7238.19 In reply to 7238.18 
I'm guessing that the frame is not set up?

So is your height zero?

I need to find the bits of scripting documentation I've saved in the past, put it together and organize it... :-)
- Brian
  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:  dune1982
7238.20 In reply to 7238.19 
As far as I understand it, factory.setInput( 5, 10 ); should give it a height of 10
  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-55