Script outputs a circle but not a cylinder
 1-13  14-33  34-39

Previous
Next
 From:  Michael Gibson
5441.34 In reply to 5441.29 
Hi Martin,

> I just discovered something strange. Every single script in this thread actually creates two
> objects on top of each other. I move the generated circle and there's another one below.
> Can anyone confirm this?

Looks like this happens only when you push Tab and then paste in your script - the script ends up getting evaluated twice because it first tries to evaluate it to see if it generates a numeric result that could be used for setting distance constraint, and then again when it tries to execute it as a command.

The distance constraint stuff is where you can type in a number like 5 to limit things like a line being drawn to be a length of 5 units from the previous point. You can also put in a script expression for that as well like 22/7 or 5 * Math.sin(50) or things like that.

So because of this you shouldn't paste in your scripts using that tab method, I'll adjust the xyz input parser to make it avoid trying to evaluate the text as a numeric expression if it starts with 'script:' so the next v3 beta should not do this anymore.

- 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:  Martin (MARTIN3D)
5441.35 In reply to 5441.34 
Thank you Brian (Benfarmer) it seems you where spot on with your explanation why scripts execute twice when invoked by TAB.

Thank you Michael for taking the time and addressing my issues in detail. I use the TAB method out of convenience because it seems to be the fastest method to quickly try out scripts during development so its great if the next update allows this.
Unless I'm doing something wrong editing a script file in the MoI commands folder required me to restart MoI after each edit in order to get MoI to recognize the changes. I already discovered that it has its advantages to assign objects to variables and to use the variables in factories.
  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
5441.36 In reply to 5441.35 
Hi Martin,

> Unless I'm doing something wrong editing a script file in the MoI commands folder required me
> to restart MoI after each edit in order to get MoI to recognize the changes.

This is because of a caching mechanism - every time MoI loads a text file from disk it keeps a cached version in memory so that it won't have to load it from disk again the next time you run that command or show that same UI.

I've been meaning to add some way to turn that off though, I'll see about adding a setting in moi.ini for disabling caching.

- 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:  Martin (MARTIN3D)
5441.37 In reply to 5441.36 
Hi Michael,

I see, such a setting in moi.ini would be good. In the meantime I will switch back to using .js files and just save each test file with a number added like test1.js for the first version, test2.js for the next. This way MoI is forced to load a new command file.
  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)
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-13  14-33  34-39