Scripting

 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