Script outputs a circle but not a cylinder
 1-20  21-39

Previous
Next
 From:  Martin (MARTIN3D)
5441.21 In reply to 5441.20 
Thanks for figuring this out Michael! And again I learned something new.
Instead of

Draw circle on xz (Front) plane
script:
var frame = moi.vectorMath.createFrame(
		moi.vectorMath.createPoint( 0, 0, 0 ),
		moi.vectorMath.createPoint( 1, 0, 0 ),
		moi.vectorMath.createPoint( 0, 0, 1 ) );
var factory = moi.command.createFactory( 'circle' );
factory.setInput( 1, frame );
factory.setInput( 3, 10 );
factory.commit();


I'll now use the much simpler

script:
var factory = moi.command.createFactory( 'circle' );
factory.setInput( 1, moi.vectorMath.createFrontFrame() );
factory.setInput( 3, 10 );
factory.commit();


Edit: The former script is still required if the center of the circle has to be elsewhere.
The line moi.vectorMath.createPoint( 0, 0, 0 ) determines the center.
  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.22 In reply to 5441.21 
Hi Martin, you can also createFrontFrame() and then set just the origin of the frame by setting the .origin property on the frame.

So something like:

var frame = moi.vectorMath.createFrontFrame();
frame.origin = moi.vectorMath.createPoint( 5, 10, 2 );


Also for the next v3 beta I've tweaked moi.vectorMath.createFrame() so that the optional arguments there will work ok on Windows too when they are left out, there seems to be a little difference in behavior with how optional arguments are handled between the regular Windows OLE automation mechanism and the one in Wine, but it only takes a minor modification for me to make it work ok on both.

- 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
5441.23 In reply to 5441.20 
That looks right. I replaced the line "factory.setInput( 1, moi.vectorMath.createFrame() );"
with the code used in Mirror script. The following script works in either of a shortcut key to c:\Script\DrawCircle.js
or with the whole script in a shortcut key line pasted from Notepad++ DrawCircle.js.

I forgot, (again), how to do \code or whatever it was.

The following is for Right view, and it works in Windows7:

code:
script:/*DrawCircle*/var factory = moi.command.createFactory( 'circle' );var FrameOrigin = moi.vectorMath.createPoint( 0, 0, 0 );var FrameXAxis = moi.vectorMath.createPoint(0, 1, 0 );var FrameYAxis = moi.vectorMath.createPoint( 0, 0, 1 );var Frame = moi.vectorMath.createFrame( FrameOrigin, FrameXAxis, FrameYAxis );factory.setInput( 1, Frame );factory.setInput( 3, 10 );factory.commit();


It has been a good learning experience. :-)
That Dave Morrill documentation could use some upgrade, with lots of examples...

EDITED: 1 Oct 2012 by BEMFARMER

  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
5441.24 
Okay, it is "less than sign" code "greater than sign,
and to end 'less than sign" /code "greater than sign.
  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.25 In reply to 5441.22 
>frame.origin = moi.vectorMath.createPoint( 5, 10, 2 );

Excellent, thank you again Michael.

This Dave Morill documentation helps a lot! What a huge effort! But I agree what's missing are the simple "Hello World"-type examples. On the other hand I fully understand that scripting or it's documentation can't have priority in the MoI development at this time.

Nevertheless one more question if it's okay:
I found moi.ui.propertiesPanel.editName() which brings up a dialog to edit the name of the selected object but I can't find out how to give an object a name directly without dialog.
  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.26 In reply to 5441.24 
Code looks good. Can you use it with copy and paste formated like this Brian? :-)

Boolean Union of selected objects:
code:
script: /*boolean union*/
var factory = moi.command.createFactory( 'booleanunion' );
factory.setInput( 0, moi.geometryDatabase.getSelectedObjects() );
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:  Michael Gibson
5441.27 In reply to 5441.25 
Hi Martin,

> I found moi.ui.propertiesPanel.editName() which brings up a dialog to edit the name of the selected
> object but I can't find out how to give an object a name directly without dialog.

Objects have a .name property that you can set directly using script. So for example:

obj.name = 'my name';

- 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.28 In reply to 5441.27 
Thank you Michael, now I can create an object and name it immediately. A huge help for selecting certain objects for use with createFactory.
I use selectAll() / invertSelection() because I can't get moi.geometryDatabase.selectLastCreated(false) to work.

Name those innoccent, newborn objects:
code:
script:
moi.geometryDatabase.selectAll();
var factory = moi.command.createFactory( 'circle' );
factory.setInput( 1, moi.vectorMath.createFrontFrame() );
factory.setInput( 3, 10 );
factory.commit();
moi.geometryDatabase.invertSelection();
moi.geometryDatabase.getSelectedObjects().item(0).name = "My little circle";


Select them by object name:
code:
script:
moi.geometryDatabase.selectNamed( 'My little 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:  Martin (MARTIN3D)
5441.29 In reply to 5441.28 
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?
  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
5441.30 In reply to 5441.29 
Using the Tab method to run the script creates two circles.
Using the Shortcut key method only creates one circle.

Similarly for the line script.

Paste into shortcut keys only works up to the first CR LF (carriage return, linefeed).
  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
5441.31 In reply to 5441.29 
I'll hazard a guess, probably wrong.
Javascript is an interpreter, scans the script (causing a copy), then runs the
script (causing another copy), in TAB mode. Shortcut works properly. Just a wild guess.

Edit: MoI version two also does double copies.
  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
5441.32 In reply to 5441.25 
I agree, Assign scripting a lower priority than interactive MoI development. :)
  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.33 In reply to 5441.28 
Hi Martin,

> because I can't get moi.geometryDatabase.selectLastCreated(false) to work.

This is probably because you're not creating the objects in the context of a "command" - there are various things that the command mechanism sets up before and at the end of a command, and the mechanism for recognizing the last created objects is one of those, as well as stuff for setting up undo units, etc...

If you want those kinds of things to work you will need to put your script into a file in the commands folder and then run it as a command rather than as inline instant executed 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

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-20  21-39