Script outputs a circle but not a cylinder
 1-17  18-37  38-39

Previous
Next
 From:  Martin (MARTIN3D)
5441.38 In reply to 5441.37 
Hi Michael,

what is the correct way to assign objects to variables? So far I use factory.commit which adds the object to the scene, then I select it somehow (which is not always easy) and assign the selection to a variable. It works but I think there must be a better way. I saw that you use factory.calculate() to assign an object to a variable followed by factory.cancel() and tried the following script:

code:
/*draw cylinder*/
var factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, moi.vectorMath.createFrame() );
factory.setInput( 3, 20 );
factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 40 ) );
var cylinder1 = factory.calculate();
cylinder1.name = 'Zylinder 1';
factory.cancel();
moi.geometryDatabase.addObject(cylinder1);


The script above crashes MoI so I assume my understanding of how this all works is wrong :-)
  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
5441.39 In reply to 5441.38 
Hi Martin, it's possible for some factories to return more than one object as the result of their operation so because of that the factory.calculate() method does not just return a single object like your code there is expecting, it actually returns an "object list".

You can then retrieve the object out of that object list by something like this:

var objlist = factory.calculate();
var cylinder1 = objlist.item(0);

- 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-17  18-37  38-39