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

Next
 From:  Martin (MARTIN3D)
5441.1 
Hi Michael,

I can now draw lines:
script:
var factory = moi.command.createFactory( "line" );
factory.setInput( 0, moi.vectorMath.createPoint( 0, 0, 0 ) );
factory.setInput( 1, moi.vectorMath.createPoint( 40, 40, 40 ) );
factory.commit();


Also drawing a circle works fine:
script:
var factory = moi.command.createFactory( 'circle' );
factory.setInput( 1, moi.vectorMath.createFrame() );
factory.setInput( 3, 10 );
factory.commit();


But drawing a cylinder gives a parse error:
script:
var factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, moi.vectorMath.createFrame() );
factory.setInput( 3, 10.0) );
factory.setInput( 5, 40.0) );
factory.commit();


What is wrong?
I searched but I can't find any example scripts that create solids.
  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.2 In reply to 5441.1 
you have unbalanced parentheses, too many ( or )

(Consider this a preliminary response, I have limited knowledge.)
  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.3 In reply to 5441.2 
Thanks a lot benfarmer, I was blind. The error is gone but the script still isn't correct because
it produces just a circle:
script:
var factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, moi.vectorMath.createFrame() );
factory.setInput( 3, 10.0 );
factory.setInput( 5, 40.0 );
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)
5441.4 In reply to 5441.3 
But at least I can draw a box! This script also had unbalanced parantheses. Hurray!

Draw box
script:
var factory = moi.command.createFactory( 'box' );
factory.setInput( 0, moi.vectorMath.createFrame() );
factory.setInput( 2, 20 );
factory.setInput( 3, 20 );
factory.setInput( 4, 20 );
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:  bemfarmer
5441.5 In reply to 5441.3 
If you look at the documentation by David Morrill, there are 6 index types.

Edit, seems like your script should work. Maybe try some permutations of index numbers.

(Based upon my very limited knowledge, as I do not understand much.)

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.6 
For some reason, my copy paste only does one line at a time. Maybe there is some hidden formatting?
Maybe the code should be in a code box?
I cannot get box script to work, get data type mismatch.
Cylinder script does not do anything.
How are you running these scripts?

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:  Martin (MARTIN3D)
5441.7 In reply to 5441.6 
I'm using OS X and I copy the script from my text editor, press TAB in MoI, paste the script and hit ENTER without problems. I just tried it and copied and pasted directly from the browser window and it also worked fine. Maybe there's a clipboard setting in Windows to copy rich formatted text or something like this.

Unfortunatetly I don't know how to put scripts into a code box but here they are again with all line breaks removed. I chose the formated versions because it's easier to read.

script: /*draw box*/ var factory = moi.command.createFactory( 'box' ); factory.setInput( 0, moi.vectorMath.createFrame() ); factory.setInput( 2, 20 ); factory.setInput( 3, 20 ); factory.setInput( 4, 20 ); factory.commit();

script: /*draw cylinder*/ var factory = moi.command.createFactory( 'cylinder' ); factory.setInput( 1, moi.vectorMath.createFrame() ); factory.setInput( 3, 10 ); factory.setInput( 5, 40 ); factory.commit();


The first one draws a 20x20x20 box at the worlds origin axis the second one just 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
5441.8 In reply to 5441.7 
Thanks Martin. I'll try again later, after work. (Windows 7)
  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.9 In reply to 5441.8 
Okay, I managed to get a cylinder:

script: /*draw cylinder*/ var factory = moi.command.createFactory( 'cylinder' ); factory.setInput( 1, moi.vectorMath.createFrame() ); factory.setInput( 2, moi.vectorMath.createPoint( 0, 10, 0 ) ); factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 40 ) ); factory.commit();

Other than the box script creating x,y,z points is required to get it to work. Radius and height values obviously don't work.
I'm looking forward to your feedback bemfarmer.

Update:
Setting only the height value as x,y,z point also works:

script: /*draw cylinder*/ var factory = moi.command.createFactory( 'cylinder' ); factory.setInput( 1, moi.vectorMath.createFrame() ); factory.setInput( 3, 10 ); factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 40 ) ); factory.commit();

EDITED: 1 Oct 2012 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:  Michael Gibson
5441.10 In reply to 5441.9 
Hi Martin, it sounds like you've got it all figured out now?

Basically these factories are set up to work with the draw commands, so their input behavior will generally work the same as how the drawing command works.

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


These map to the different possible options and steps in the drawing command.

- 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.11 
:-)
A few little details makes a big difference.

I suppose if a person had the time, they could go through the forum, wiki, documentation, and create a tutorial or book about scripting.
Probably still a lot more to learn though.
  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.12 In reply to 5441.11 
Hi Brian,

> Probably still a lot more to learn though.

There's also a lot more to be done in MoI itself to make things more friendly for scripting - right now all the methods for creating geometry are all set up just specifically for how the regular drawing commands use them. I do want to add various other methods that would be easier for people doing automated scripts where they already know all the parameters instead of gathering them interactively like the drawing commands do.

But right now though more sort of regular feature work is still taking precedence over scripting related work. At some point in the future I do expect to focus some effort on scripting improvements though.

- 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.13 In reply to 5441.12 
>4 = top point of the cylinder, this is required and also the orientation of the cylinder will be modified to point towards this point

Hi Michael, thank you. Yes now everything makes sense.
  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.14 In reply to 5441.12 
Thanks Michael.

Well, for what it is worth, none of these scripts work (for me) in MoI, in Windows 7 64 bit.
Neither in Tab entry, nor in Shortcut key.
Keep getting data type mismatch. Spent a couple of hours experimenting, no success.
Maybe something very simple, Mac vs WindowsPC ?


Also, copy/paste, Ctrl+C and Ctrl+V, only copy up to the first invisible CR/LF, when entering in MoI shortcut keys, but
the entire text is pasted in Notepad, or Notepad++.










Maybe I can blame it on .Net 4.5 (Joke)

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:  Michael Gibson
5441.15 In reply to 5441.14 
Hi Brian, things may get confused when you're pasting in a long multi-line script into a keyboard shortcut, the keyboard shortcut is going to expect to have just one line of text.

It can be better to put the script into its own file (with .js file extension) in some folder like c:\scripts and then in the keyboard shortcut put the full path to the script file in there instead of pasting in inline script text.

If you're still having problems with doing it that way please post the script files here and I can test them.

- 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.16 In reply to 5441.15 
Thanks Michael,
I'll try some more, tomorrow. :-)
  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:  stevecim
5441.17 In reply to 5441.15 
I just tried what Michael suggested, used notepad++ , created a line.js file in c:\scripts,
In MoI tab-> full path to script , worked ok for me... Win 7 64 bit, MoI 2.0. Don't have ver3 here at work


Cheers, steve

correction, create line works, but circle and box don't, type mismatch error... this could be a moi version 2.0 error?

EDITED: 1 Oct 2012 by STEVECIM

  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.18 In reply to 5441.14 
Hi Brian, its time to get a Mac (just kidding).
I'm sorry to hear it's not working for you. Please try this one:

script: var factory = moi.command.createFactory( 'box' ); factory.setInput( 0, moi.vectorMath.createFrame() ); factory.setInput( 2, 20.0 ); factory.setInput( 3, 20.0 ); factory.setInput( 4, 20.0 ); factory.commit(); moi.view.resetAll;

The inputs require floating point numbers and that's the only "Type mismatch" I see. Maybe Windows is more picky than Mac.
Another thing to try is to put standard quotes around box like so: "box"


Also if you put the script into a .js file you should leave out the word script: at the beginning (I think).

I used the scripts successfully in version 2.5 and the newest 3 Beta.
  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.19 In reply to 5441.17 
>correction, create line works, but circle and box don't, type mismatch error...

The line script above is the only one with standard quotes. Maybe this is it.
  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.20 In reply to 5441.18 
It appears to be the call to moi.vectorMath.createFrame() - that function takes 3 optional arguments for an origin point and x and y axis directions, but those optional parameters are not behaving the same way between Windows and Mac at the moment, it's not working on Windows to omit those arguments right now.

If you switch that to call moi.vectorMath.createTopFrame() instead then it should probably work everywhere, like this:

script: var factory = moi.command.createFactory( 'box' ); factory.setInput( 0, moi.vectorMath.createTopFrame() ); factory.setInput( 2, 20.0 ); factory.setInput( 3, 20.0 ); factory.setInput( 4, 20.0 ); factory.commit(); moi.view.resetAll;

- 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