Scripting
 1-15  16-35  36-55  56-68

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

Previous
Next
 From:  Michael Gibson
7238.48 In reply to 7238.47 
Hi dune1982,

> 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.

It's possible I had a typo in there that needs to be corrected since I just typed that example out into a message rather than making a running example that was tested.

Please post your complete runnable script that triggers an error and then I'll be able to check it out and see what the error is.

- 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.49 In reply to 7238.48 
Hello Michael,
its been some time since we talked about this, but I have been traveling a lot for the past 10 weeks.

I could send you my running code, but now it has gotten a little big since the whole thing contains at least two files. I'm not sure if you whant to dig into that.

But here is the errormessage which whas kind of hard to get as MoI closes the messagebox right away and freeses.



Attachments:

  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.50 In reply to 7238.49 
Hi dune 1982, well the error message there says "Invalid return statement". I think that the only way you'd get that is if that return statement is not inside of a function.

Does your code in schra.js just start off a bunch of direct global code? If so then you can't use a return statement in it. If you take a look at the scripts that are distributed with MoI you'll usually see (unless it's very simple code with no "bail outs" needed) the main code is in a function and then at the bottom of the file the function is called - it's structured that way so that it's a bit easier to bail out of the code at anytime by putting in a return statement like the one in your error message.

See for example commands\Trim.js - it's set up like this:

code:
function DoTrim()
{
      <.... Whole bunch of code goes here .... >
}

// Call the function, any code inside of DoTrim can bail out by a return statement.
DoTrim();


But if your code is not in a function you will get an error message like you post if you try to use a return statement...

Does that explain what you're seeing? If not then yes please send me the code so I can take a look, you can post it here or e-mail it to me at moi@moi3d.com if you want to keep it private.

- 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.51 In reply to 7238.50 
Thank you Michael, that was the problem. It is working now.
I will post the scripts when they are done, some fine day ;-)

Just found out that I don't need to publish my script, as Max Smirnov published a script with similar and more functions on the 22 Jun 2015 and to be honest his script wipes floors with mine. (In case it is not clear my script sucks compared)

EDITED: 28 Aug 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:  LAWRENCE
7238.52 
hi

a silly question...
how to debug script ?
we can't use a debugger, isn't 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
7238.53 In reply to 7238.52 
Hi Lawrence - sorry no there isn't any way currently to run a script in a debugger, you have to debug it old fashioned style by calling moi.ui.alert( 'msg' ) in places where you want to see what a particular variable holds.

In the future I do want to try and make some kind of integrated debugger that would help make scripting easier. There will be quite a lot of work involved to make that happen 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:  Bryan (BCGREEN24)
7238.54 In reply to 7238.6 
"Just copy each script to the clipboard, hit TAB in MOI, paste the script and press ENTER.
Experiment and enjoy
Martin"



Martin-- pressing TAB in MoI3D just moves the cursor between the input fields at the bottom of the interface. So-- I'm confused as to how these snippets are pasted into and run within MoI...

Thanks!
Bryan

EDITED: 6 Dec 2016 by BCGREEN24

  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:  Bryan (BCGREEN24)
7238.55 In reply to 7238.54 
Never mind! I didn't realize that the 'location' input field doubled as a command line!

Bryan
  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-15  16-35  36-55  56-68