Scripting
 1-7  8-27  28-47  48-67  68

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

Previous
Next
 From:  Michael Gibson
7238.38 In reply to 7238.37 
Hi dune1982,

re: turning off history - there is a property on objects that controls whether they will be a part of history updates or not. You can set it manually by selecting the objects and running Edit > History > "Disable update" button.

You can set it through your script by changing the .updateWithHistory property that's available on an geometry database object.

If you have a single object, set: obj.updateWithHistory = false;

If you have an object list, use: objlist.setProperty( 'updateWithHistory', false );

That will then have the same effect as running Edit > History > "Disable update".

- 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.39 
As I'm learning more and more I always meet a function which doesn't work like I think it would.

Today I tried to do a booleanunion on two cylinders. I get a typeerror, but why and how can I make it better?

var cylinders = moi.geometryDatabase.createObjectList();

/*make cylinder 1*/
frame = moi.vectorMath.createTopFrame();
frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, 30 );
factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 60 ) );
factory.update();
var cyl1 = factory.getCreatedObjects();
factory.commit();
cylinders.addObject(cyl1);

/*make cylinder 2*/
frame = moi.vectorMath.createTopFrame();
frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, 60 );
factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 30 ) );
factory.update();
var cyl2 = factory.getCreatedObjects();
factory.commit();
cylinders.addObject(cyl2);

/*cyl1 plus cyl2*/
moi.geometryDatabase.deselectAll();
factory = moi.command.createFactory( 'booleanunion' );
factory.setInput( 0, cylinders );
factory.update();
factory.commit();

Thanks for all the help so far
  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.40 In reply to 7238.39 
I don't get a type error. My MoI on OS X crashes when I run your latest script.
  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.41 In reply to 7238.39 
  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.42 In reply to 7238.39 
Hi dune1982,

It's due to this type of sequence here:

code:
var cyl1 = factory.getCreatedObjects();
factory.commit();
cylinders.addObject(cyl1);


The variable cyl1 contains an object list, which is what factory.getCreatedObjects() returns back.

Then later on the call to cylinders.addObject() is expecting an individual object to be passed to it, but instead you are passing that object list.

There does not happen to currently be a method on object lists to combine another list with it, you'll need to make a helper function like:

function CombineLists( targetlist, fromlist )
{
for ( var i = 0; i < fromlist.length; ++i )
targetlist.addObject( fromlist.item(i) );
}

and then call that function to combine the lists together.

- 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.43 In reply to 7238.42 
Ok I will try it with the fuction. But isn't there a return blabla missing in the function?

But isn't there a way to add an object to a list. In this case if var cyl1 = factory.getCreatedObjects(); creates the objectlist cyl1 so I could just add the next cylinder to the list cyl1

In my mind i would do cyl1.addObject(factory.getCreatedObjects()); in the factory for the next cylinder, but then I would add a list to a list which is not possible.

I made it this way now, as there are only two objects

/*make cylinder 1*/
frame = moi.vectorMath.createTopFrame();
frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, 30 );
factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 60 ) );
factory.update();
var cyl1 = factory.getCreatedObjects();
factory.commit();


/*make cylinder 2*/
frame = moi.vectorMath.createTopFrame();
frame.origin = moi.vectorMath.createPoint( 0, 0, 0 );
factory = moi.command.createFactory( 'cylinder' );
factory.setInput( 1, frame );
factory.setInput( 3, 60 );
factory.setInput( 4, moi.vectorMath.createPoint( 0, 0, 30 ) );
factory.update();
var cyl2 = factory.getCreatedObjects();
factory.commit();
cyl1.addObject( cyl1.item(0) );


/*cyl1 plus cyl2*/
moi.geometryDatabase.deselectAll();
factory = moi.command.createFactory( 'booleanunion' );
factory.setInput( 0, cyl1 );
factory.update();
factory.commit();

EDITED: 5 May 2015 by DUNE1982

  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.44 In reply to 7238.43 
Hi dune1982

> Ok I will try it with the fuction. But isn't there a return blabla missing in the function?

Functions don't always have to return a value if they are written to just operate on the parameters that are passed to them which is what that little function is set up for.


> But isn't there a way to add an object to a list. In this case if var cyl1 = factory.getCreatedObjects();
> creates the objectlist cyl1 so I could just add the next cylinder to the list cyl1

Yes that would work too.


> In my mind i would do cyl1.addObject(factory.getCreatedObjects()); in the factory for the next
> cylinder, but then I would add a list to a list which is not possible.

Unfortunately the way you want to do it here won't work because the addObject() method only expects to receive an individual object, and you are instead passing it an object list here. In the future I would like to improve this to make things more flexible, like maybe having an .add() method that could take either an individual object or an object list, but that's not how it is set up at the moment 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:  dune1982
7238.45 In reply to 7238.44 
Hello Michael,
the script with the two cylinders is working now.

Now I want the user to set a value for the diamter of the first cylinder.

I replace the value 30 of factory.setInput( 3, 30 ); by a variable lets say diameter.

Then I tried the javascript thing prompt in that way:

var diameter = prompt("Please enter a value", "10");

But nothing happens with prompt, no dialog opens nothing. Does MoI use a different command, or how to I let the user set a value?

I tried to find the answer in existing scripts but, so far found nothing.
  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.46 In reply to 7238.45 
Hi dune1982 - the UI for a command is handled by a .htm document that can contain various controls in it, and your command script can retrieve values from controls in the .htm file.

If you look in the \commands sub-folder you'll see many .htm files in addition to .js files - each of those .htm files is one of these files that is handling the UI for a particular command, look into some of them to see how the UI is set up.

You just give your own .htm file the same base filename as your .js script file, then the command infrastructure will make sure to load that .htm file and show it in the command options area in the upper right corner of the main window before your .js script is launched.

Here's an example .htm file that will have a control in it for putting in a diameter:

code:
<html>
	<body class="commandbody">
		<div class="commandheader">
			<div class="commandprompt">Command options</div>
		</div>
		
		<div class="commandoptions">
			<table>
				<tr>
					<td>Diameter:</td>
					
					<td>
						<moi:DistanceInput id="distanceinput" style="persist:false"/>
					</td>
				</tr>
			</table>
		</div>

		<moi:CommandCancel />
	</body>
</html>




Your .js command script can get access to the .htm document by using moi.ui.commandUI - that returns the global object of the HTML document. If your control has been given an id="" value then you'll be able to access it using that id, like for example to get the value property of the control above with id="distanceinput", your script would call: moi.ui.commandUI.distanceinput.value; - that will return the number of whatever value has been typed in there.

Typically a command that shows UI will wait in an event loop for UI events to be triggered, that way they can pause themselves until some controls are filled in and then the script can continue.

An event loop means the script will call waitForEvent() on a waitable object, some examples of waitable objects are a pointpicker which will trigger events when the point is finished being picked, or an objectpicker which triggers an event when selection is finished, or also another one is moi.ui.commandDialog which can be used to wait on UI events triggered by controls in the command option area. Any control that has an id="" value set on it will trigger a UI event with that id value when the control is activated, like for a button control when it's pushed or for an input control when the user has typed some value in it and pushed enter.

So here's how your script could pause itself and wait until the user typed in a value for the distance input control:

code:
	var commandDialog = moi.ui.commandDialog;
	
	while ( 1 )
	{
		// Wait for user input.

		if ( !commandDialog.waitForEvent() )
			return false; // if waitForEvent returns false the command is being canceled.
			
		if ( commandDialog.event == 'distanceinput' )
			break; // User entered a value in the id="distanceinput" control.
	}

        // Get the value from the control.
	var diameter = moi.ui.commandUI.distanceinput.value;


  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.47 In reply to 7238.46 
Hello Michael,
I can't thank you enough for takeing the time to explain all this to me.

I think I got that now, but your code causes MoI to quit with an error when I cancel the script by clicking on cancel.
  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-7  8-27  28-47  48-67  68