Scripting
 1-6  7-26  27-46  47-66  67-68

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

Previous
Next
 From:  Martin (MARTIN3D)
7238.21 In reply to 7238.20 
Here's an example that works:

code:
frame = moi.vectorMath.createTopFrame();
frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, 100 ); //diameter
factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 300 ) ); //length
factory.commit();


You must be more specific where you create the frame (Top, Bottom, Left ...) and you must give the factory two points for the cylinder direction not just the height.


-Martin

EDITED: 19 Apr 2015 by MARTIN3D

  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:  Max Smirnov (SMIRNOV)
7238.22 
dune1982
You can't use input 5 without input 4 setting.
Check this two examples:

code:
var radius = 10;
var height = 15;
var frame = moi.vectorMath.createFrame();
var direction = frame.evaluate( 0, 0, 1 );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, radius );
factory.setInput( 4, direction );
factory.setInput( 5, height );
factory.commit();

code:
var radius = 10;
var height = 15;
var frame = moi.vectorMath.createFrame();
var direction = frame.evaluate( 0, 0, height );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, radius );
factory.setInput( 4, direction );
factory.commit();
  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.23 In reply to 7238.22 
Thanks Max, frame.evaluate is cool.

Here's an explanation by Michael regarding the cylinder factory inputs:

For a cylinder there are 6 inputs:

0 = boolean value true = distance input is radius, false = distance input is diameter
1 = frame for cylinder bottom base point and axis directions
2 = point that defines the radius, this can be left out if a numeric radius is supplied instead
3 = numeric radius (or diameter) value.
4 = top point of the cylinder, this is required and also the orientation of the cylinder will be modified to point towards this point
5 = optional numeric height input, if this is supplied the cylinder will point towards the top point but will be this specific height instead of touching the top point

http://moi3d.com/forum/index.php?webtag=MOI&msg=5441.10


-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.24 In reply to 7238.23 
Thank you so much Martin and MAX, this helped a lot understanding more and more. I wonder how you find these answers in the forum? everytime I use the search function it returns nothing interesting.

I hate to bother you guys again with my questions, I tried to figure it out by my self put didn't solve it.

I'm still learning the basics. So I made this script which should draw a polygon and then extrude it to 5

function drawpolygon() {
polygonfactory = moi.command.createFactory( 'polygon' );
var frame = moi.vectorMath.createFrame(); //erzeugt das Koordinatensystem für den Zylinder
frame.origin = moi.vectorMath.createPoint( 0, 0, 0 ); //Uhrsprungspunkt
var direction = frame.evaluate( 7.2, 0, 0 ); //Radius des Poligon
polygonfactory.setInput( 0, frame );
polygonfactory.setInput( 1, direction );
polygonfactory.setInput( 2, 6 );
polygonfactory.commit();
}
drawpolygon(); //until here It works, I see the polygon

var objects = moi.geometryDatabase.selectAll(); // the polygon is selected


var extrudefactory = moi.command.createFactory( 'extrude' );
extrudefactory.setInput( 0, objects ); //in my mind this should take the selected polygon to extrude
extrudefactory.setInput( 2, 5 ); // distance 5mm
extrudefactory.setInput( 3, moi.vectorMath.createPoint( 0, 0, 1 ) ); //direction to extrude
extrudefactory.setInput( 1, true ); //cap ends? yes
extrudefactory.commit();

Where is my mistake?
  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.25 In reply to 7238.24 
Hi dune1982, the problem is with this one line here:

var objects = moi.geometryDatabase.selectAll(); // the polygon is selected

The call to moi.geometryDatabase.selectAll() will select the polygon but it does not return an object list, it returns nothing so 'objects' does not have an object list like you were thinking it would.

Replace that line with these 2 and then your script should work:

moi.geometryDatabase.selectAll(); // the polygon is selected
var objects = moi.geometryDatabase.getSelectedObjects();



It may be better though to not use "select all" for grabbing the output because if you happen to have any other objects in the model before running this script it will select those as well.

You can instead grab an object list of the output from the polygon factory by calling polygonfactory.update() then polygonfactory.getCreatedObjects() before doing the polygonfactory.commit(). That way you won't need to use "SelectAll" as a way to gather the output.

So that would look like this:

code:


function drawpolygon()
{
	polygonfactory = moi.command.createFactory( 'polygon' );
	var frame = moi.vectorMath.createFrame(); //erzeugt das Koordinatensystem für den Zylinder
	frame.origin = moi.vectorMath.createPoint( 0, 0, 0 ); //Uhrsprungspunkt
	var direction = frame.evaluate( 7.2, 0, 0 ); //Radius des Poligon
	polygonfactory.setInput( 0, frame );
	polygonfactory.setInput( 1, direction );
	polygonfactory.setInput( 2, 6 );
	
	polygonfactory.update();
	
	var objects = polygonfactory.getCreatedObjects();
	
	polygonfactory.commit();
	
	return objects;
}
	
var objects = drawpolygon(); //until here It works, I see the polygon


var extrudefactory = moi.command.createFactory( 'extrude' );
extrudefactory.setInput( 0, objects );  //in my mind this should take the selected polygon to extrude
extrudefactory.setInput( 2, 5 ); // distance 5mm
extrudefactory.setInput( 3, moi.vectorMath.createPoint( 0, 0, 1 ) ); //direction to extrude
extrudefactory.setInput( 1, true ); //cap ends? yes
extrudefactory.commit();






But anyway if you do want to use "select all" you'll need to gather the selected objects up using moi.geometry.getSelectedObjects() after you have the selection how you want, the call to moi.geometryDatabase.selectAll() does the selection but does not itself return the object list.

Hope this 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

Previous
Next
 From:  dune1982
7238.26 In reply to 7238.25 
Thank you Michael, I think I'm understanding more and more.

Your reply http://moi3d.com/forum/lmessages.php?webtag=MOI&msg=5461.10 helped me a lot understanding booleandiffrence. But if I run this script it looks fine at fist. But when I click on the resulting cylinder and move it, suddenly the result from the first booleandiffrence apears again.

Why is 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
 

Reply to All Reply to All

 

 
Show messages:  1-6  7-26  27-46  47-66  67-68