Scripting
 1-14  15-34  35-54  55-68

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

Previous
Next
 From:  Michael Gibson
7238.27 In reply to 7238.26 
Hi dune1982,

> But when I click on the resulting cylinder and move it, suddenly the result from the
> first booleandiffrence apears again. Why is that?

Hmmm, I don't know why that would happen. I tried running that script over here and I can't seem to get the reappearing behavior to happen when I move the booleaned cylinder result.

Maybe you're seeing the result of a history update, what happens if you select everything and run Edit > History > "Disable update" button before trying to move the object does that make any difference?

- 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.28 In reply to 7238.27 
Hello Michale
>Maybe you're seeing the result of a history update, what happens if you select everything and run Edit> History > "Disable update" button before trying to move the object does that make any difference?
Yes that helped after Disableing Update the result does not appear. What does that say now?
Thank you
  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.29 In reply to 7238.28 
Hi dune1982,

re:
> What does that say now?

I guess it says that the effect you saw was due to a history update - there is a mechanism in MoI where if you edit an object, if it was one of the inputs that were used to generate some other object in the current model, the command that created it is basically re-run for you and the outputs regenerated. This can sometimes cause unexpected results if pieces were moved so that they do not intersect one another at all or things like that.

- 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.30 
Hello
Everytime when I think: well now you know it. I seem to hit a script that I cant handle.

Today I'm trying to make a sweep:

var factory = moi.command.createFactory( 'sweep' );
factory.setInput( 0, triangle ); //is a objectList with three lines joined to a triangle
factory.setInput( 1, helix ); //is a objectList with a helix in it
factory.setInput( 2, ); //no idea what to set here
factory.setInput( 3, ); //no idea what to set here
factory.setInput( 4, 'none' );
factory.setInput( 5, 'flat' );
factory.setInput( 6, true );
factory.setInput( 7, true );
factory.setInput( 8, true );
// I stoped here as I have no and whant no scaling
factory.commit();

I only get a calculation failed out of this, i guess it is because auf 2 and 3 missing.
  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.31 In reply to 7238.30 
Hi dune1982, here are the inputs for sweep:


0 : ObjectList - Profile curves.
1 : ObjectList - Rail curves.
2 : Orientation List - List of IMoiCurveOrientation objects for profiles, for history updates leave empty on first run.
3 : Orientation List - List of IMoiCurveOrientation objects for rails, for history updates leave empty on first run.
4 : String - Point end mode, one of: 'none', 'pointystart', 'pointyend', or 'pointystartandend'
5 : String - twist type - 'freeform' or 'flat'
6 : Boolean - Maintain height true = maintain height for two-rail sweep (stretch profiles instead of uniformly scale).
7 : Boolean - cap ends true = do planar end caps.
8 : Boolean - Maintain tangent - true = use tangent preserving sweep if possible.
9 : Object - scaling rail - If set this defines a scaling curve.
10: String - Profile synch type - Options for synchronizing profiles: Auto, Exact, Refit, or NumPoints.
11: Int - Number of points to use for profile numpoints synchronization mode.
12: Point - "Flat direction" - Direction vector for twist=flat mode.

If you're still stuck could you post a complete script that has the other pieces like your helix and triangle curve being generated so I can run it over here and see what's wrong?

- 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:  bemfarmer
7238.32 In reply to 7238.30 
Pipe2 has some clues, and input 1 of factory.setInput( 1, WrapWithObjectList(rail) );

? 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.33 
Thank you Michael but I'm still stuck,
Here is the whole code.

var length = 100;
var sradius = 28
var pitch = 5

factory = moi.command.createFactory( 'helix' );
var frame = moi.vectorMath.createFrame();
frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
factory.setInput( 0, frame);
factory.setInput( 1, moi.vectorMath.createPoint( 0, 0, length ));
factory.setInput( 2, moi.vectorMath.createPoint( 1, 0, 0 ));
factory.setInput( 3, sradius);
factory.setInput( 5, sradius);
factory.setInput( 7, steigung);
factory.setInput( 8, 'pitch');
factory.setInput( 9, false);
var helix = factory.getCreatedObjects();
factory.commit();

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

var objlist = linefactory.calculate();
var line = objlist.item(0);
moi.geometryDatabase.addObject( line );
return line;
}

var linelist = moi.geometryDatabase.createObjectList();
linelist.addObject(drawLine(sradius, -steigung/2, sradius, steigung/2));
linelist.addObject(drawLine(sradius, steigung/2, sradius+5, 0));
linelist.addObject(drawLine(sradius+5, 0, sradius, -steigung/2));

var factory = moi.command.createFactory( 'join' );
factory.setInput( 0, linelist );
var triangle = factory.getCreatedObjects();
factory.commit();

//erstellt sweep
var factory = moi.command.createFactory( 'sweep' );
factory.setInput( 0, triangle );
factory.setInput( 1, helix );
factory.setInput( 4, 'none' );
factory.setInput( 5, 'flat' );
factory.setInput( 6, true );
factory.setInput( 7, true );
factory.setInput( 8, true );
factory.commit();

Thank you for all the 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
Next
 From:  Michael Gibson
7238.34 In reply to 7238.33 
Hi dune1982, it seems that script there is not complete, I get an error:

ReferenceError: Can't find variable: steigung on line 13, is there some previous part of the script that is missing in your post?

Looking over your last calls to the sweep, the problem might be that you are specifying twist = "flat" but not providing the flat direction which is on input index 12 : Point - "Flat direction" - Direction vector for twist=flat mode.

But I can't tell for sure if that is why it's failing because I'm not able to run the script over here due to the variable named steigung missing from the script.

- 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-14  15-34  35-54  55-68