Scripting
 1-17  18-37  38-57  58-68

Previous
Next
 From:  dune1982
7238.18 In reply to 7238.17 
Thank you Michael for explaining all this for me.

I had a look at http://moi.maxsm.net/ because I wanted MoI to draw a cylinder.

I thought I had understood it, but it seems that I have not.

This is what I came up with:

`script:
var factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, moi.vectorMath.createFrame() );

factory.setInput( 3, 20 );
factory.setInput( 5, 10 );


factory.commit();`

which ends with MoI drawing 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
7238.19 In reply to 7238.18 
I'm guessing that the frame is not set up?

So is your height zero?

I need to find the bits of scripting documentation I've saved in the past, put it together and organize it... :-)
- Brian
  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:  dune1982
7238.20 In reply to 7238.19 
As far as I understand it, factory.setInput( 5, 10 ); should give it a height of 10
  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)
7238.21 In reply to 7238.20 
Here's an example that works:

code:
frame = moi.vectorMath.createTopFrame();
frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, 100 ); //diameter
factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 300 ) ); //length
factory.commit();


You must be more specific where you create the frame (Top, Bottom, Left ...) and you must give the factory two points for the cylinder direction not just the height.


-Martin

EDITED: 19 Apr 2015 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:  Max Smirnov (SMIRNOV)
7238.22 
dune1982
You can't use input 5 without input 4 setting.
Check this two examples:

code:
var radius = 10;
var height = 15;
var frame = moi.vectorMath.createFrame();
var direction = frame.evaluate( 0, 0, 1 );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, radius );
factory.setInput( 4, direction );
factory.setInput( 5, height );
factory.commit();

code:
var radius = 10;
var height = 15;
var frame = moi.vectorMath.createFrame();
var direction = frame.evaluate( 0, 0, height );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, radius );
factory.setInput( 4, direction );
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)
7238.23 In reply to 7238.22 
Thanks Max, frame.evaluate is cool.

Here's an explanation by Michael regarding the cylinder factory inputs:

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

http://moi3d.com/forum/index.php?webtag=MOI&msg=5441.10


-Martin
  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:  dune1982
7238.24 In reply to 7238.23 
Thank you so much Martin and MAX, this helped a lot understanding more and more. I wonder how you find these answers in the forum? everytime I use the search function it returns nothing interesting.

I hate to bother you guys again with my questions, I tried to figure it out by my self put didn't solve it.

I'm still learning the basics. So I made this script which should draw a polygon and then extrude it to 5

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.commit();
}
drawpolygon(); //until here It works, I see the polygon

var objects = moi.geometryDatabase.selectAll(); // the polygon is selected


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();

Where is my mistake?
  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
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
  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:  dune1982
7238.26 In reply to 7238.25 
Thank you Michael, I think I'm understanding more and more.

Your reply http://moi3d.com/forum/lmessages.php?webtag=MOI&msg=5461.10 helped me a lot understanding booleandiffrence. But if I run this script it looks fine at fist. But when I click on the resulting cylinder and move it, suddenly the result from the first booleandiffrence apears again.

Why is that?
  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
7238.27 In reply to 7238.26 
Hi dune1982,

> But when I click on the resulting cylinder and move it, suddenly the result from the
> first booleandiffrence apears again. Why is that?

Hmmm, I don't know why that would happen. I tried running that script over here and I can't seem to get the reappearing behavior to happen when I move the booleaned cylinder result.

Maybe you're seeing the result of a history update, what happens if you select everything and run Edit > History > "Disable update" button before trying to move the object does that make any difference?

- 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:  dune1982
7238.28 In reply to 7238.27 
Hello Michale
>Maybe you're seeing the result of a history update, what happens if you select everything and run Edit> History > "Disable update" button before trying to move the object does that make any difference?
Yes that helped after Disableing Update the result does not appear. What does that say now?
Thank you
  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
7238.29 In reply to 7238.28 
Hi dune1982,

re:
> What does that say now?

I guess it says that the effect you saw was due to a history update - there is a mechanism in MoI where if you edit an object, if it was one of the inputs that were used to generate some other object in the current model, the command that created it is basically re-run for you and the outputs regenerated. This can sometimes cause unexpected results if pieces were moved so that they do not intersect one another at all or things like that.

- 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:  dune1982
7238.30 
Hello
Everytime when I think: well now you know it. I seem to hit a script that I cant handle.

Today I'm trying to make a sweep:

var factory = moi.command.createFactory( 'sweep' );
factory.setInput( 0, triangle ); //is a objectList with three lines joined to a triangle
factory.setInput( 1, helix ); //is a objectList with a helix in it
factory.setInput( 2, ); //no idea what to set here
factory.setInput( 3, ); //no idea what to set here
factory.setInput( 4, 'none' );
factory.setInput( 5, 'flat' );
factory.setInput( 6, true );
factory.setInput( 7, true );
factory.setInput( 8, true );
// I stoped here as I have no and whant no scaling
factory.commit();

I only get a calculation failed out of this, i guess it is because auf 2 and 3 missing.
  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
7238.31 In reply to 7238.30 
Hi dune1982, here are the inputs for sweep:


0 : ObjectList - Profile curves.
1 : ObjectList - Rail curves.
2 : Orientation List - List of IMoiCurveOrientation objects for profiles, for history updates leave empty on first run.
3 : Orientation List - List of IMoiCurveOrientation objects for rails, for history updates leave empty on first run.
4 : String - Point end mode, one of: 'none', 'pointystart', 'pointyend', or 'pointystartandend'
5 : String - twist type - 'freeform' or 'flat'
6 : Boolean - Maintain height true = maintain height for two-rail sweep (stretch profiles instead of uniformly scale).
7 : Boolean - cap ends true = do planar end caps.
8 : Boolean - Maintain tangent - true = use tangent preserving sweep if possible.
9 : Object - scaling rail - If set this defines a scaling curve.
10: String - Profile synch type - Options for synchronizing profiles: Auto, Exact, Refit, or NumPoints.
11: Int - Number of points to use for profile numpoints synchronization mode.
12: Point - "Flat direction" - Direction vector for twist=flat mode.

If you're still stuck could you post a complete script that has the other pieces like your helix and triangle curve being generated so I can run it over here and see what's wrong?

- 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
7238.32 In reply to 7238.30 
Pipe2 has some clues, and input 1 of factory.setInput( 1, WrapWithObjectList(rail) );

? Brian
  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:  dune1982
7238.33 
Thank you Michael but I'm still stuck,
Here is the whole code.

var length = 100;
var sradius = 28
var pitch = 5

factory = moi.command.createFactory( 'helix' );
var frame = moi.vectorMath.createFrame();
frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
factory.setInput( 0, frame);
factory.setInput( 1, moi.vectorMath.createPoint( 0, 0, length ));
factory.setInput( 2, moi.vectorMath.createPoint( 1, 0, 0 ));
factory.setInput( 3, sradius);
factory.setInput( 5, sradius);
factory.setInput( 7, steigung);
factory.setInput( 8, 'pitch');
factory.setInput( 9, false);
var helix = factory.getCreatedObjects();
factory.commit();

function drawLine(x1,z1,x2,z2)
{
var linefactory = moi.command.createFactory( "line" );
linefactory.setInput( 0, moi.vectorMath.createPoint( x1, 0, z1 ) );
linefactory.setInput( 1, moi.vectorMath.createPoint( x2, 0, z2 ) );

var objlist = linefactory.calculate();
var line = objlist.item(0);
moi.geometryDatabase.addObject( line );
return line;
}

var linelist = moi.geometryDatabase.createObjectList();
linelist.addObject(drawLine(sradius, -steigung/2, sradius, steigung/2));
linelist.addObject(drawLine(sradius, steigung/2, sradius+5, 0));
linelist.addObject(drawLine(sradius+5, 0, sradius, -steigung/2));

var factory = moi.command.createFactory( 'join' );
factory.setInput( 0, linelist );
var triangle = factory.getCreatedObjects();
factory.commit();

//erstellt sweep
var factory = moi.command.createFactory( 'sweep' );
factory.setInput( 0, triangle );
factory.setInput( 1, helix );
factory.setInput( 4, 'none' );
factory.setInput( 5, 'flat' );
factory.setInput( 6, true );
factory.setInput( 7, true );
factory.setInput( 8, true );
factory.commit();

Thank you for all the help
  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
7238.34 In reply to 7238.33 
Hi dune1982, it seems that script there is not complete, I get an error:

ReferenceError: Can't find variable: steigung on line 13, is there some previous part of the script that is missing in your post?

Looking over your last calls to the sweep, the problem might be that you are specifying twist = "flat" but not providing the flat direction which is on input index 12 : Point - "Flat direction" - Direction vector for twist=flat mode.

But I can't tell for sure if that is why it's failing because I'm not able to run the script over here due to the variable named steigung missing from the 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:  dune1982
7238.35 In reply to 7238.34 
Oh yes, my mistake,
just rename the variable pitch to steigung or the other way ;-)
  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
7238.36 In reply to 7238.35 
Hi dune1982 - the problem is that your triangle and helix object lists are empty. That's because the factory has not created anything yet at the time that you call factory.getCreatedObjects(). Insert a call to factory.update() before you call factory.getCreatedObjects() and that should fix up your script, here I've marked the added lines with >>> <<<<<:

code:
var length = 100;
var sradius = 28
var steigung = 5

factory = moi.command.createFactory( 'helix' );
var frame = moi.vectorMath.createFrame();
frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
factory.setInput( 0, frame);
factory.setInput( 1, moi.vectorMath.createPoint( 0, 0, length ));
factory.setInput( 2, moi.vectorMath.createPoint( 1, 0, 0 ));
factory.setInput( 3, sradius);
factory.setInput( 5, sradius);
factory.setInput( 7, steigung);
factory.setInput( 8, 'pitch');
factory.setInput( 9, false);
>>>>factory.update();<<<<
var helix = factory.getCreatedObjects();
factory.commit();

function drawLine(x1,z1,x2,z2)
{
var linefactory = moi.command.createFactory( "line" );
linefactory.setInput( 0, moi.vectorMath.createPoint( x1, 0, z1 ) );
linefactory.setInput( 1, moi.vectorMath.createPoint( x2, 0, z2 ) );

var objlist = linefactory.calculate();
var line = objlist.item(0);
moi.geometryDatabase.addObject( line );
return line;
}

var linelist = moi.geometryDatabase.createObjectList();
linelist.addObject(drawLine(sradius, -steigung/2, sradius, steigung/2));
linelist.addObject(drawLine(sradius, steigung/2, sradius+5, 0));
linelist.addObject(drawLine(sradius+5, 0, sradius, -steigung/2));

var factory = moi.command.createFactory( 'join' );
factory.setInput( 0, linelist );
>>>>factory.update();<<<<
var triangle = factory.getCreatedObjects();
factory.commit();

//erstellt sweep
var factory = moi.command.createFactory( 'sweep' );
factory.setInput( 0, triangle );
factory.setInput( 1, helix );
factory.setInput( 4, 'none' );
factory.setInput( 5, 'flat' );
factory.setInput( 6, true );
factory.setInput( 7, true );
factory.setInput( 8, true );
factory.commit();


- 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:  dune1982
7238.37 In reply to 7238.29 
Hello Michael, we have talked about this before. But now as my script is getting bigger, the history or whatever seems to be makeing funny things. Is there a way to turn this off? I have cylinders and booleanunions and other things in my script. After running it I have some of the things twice on the screen and now they wont dissapear when I do something new.
  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-57  58-68