Scripting
 1-20  21-40  41-60  61-68

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

Previous
Next
 From:  bemfarmer
7238.56 
Hi Michael,

Is there a simple way to allow the user to chose which mode of a script to run?
For example, one button for mode: unwrap cone,
another button for mode: unwrap frustum?

Another example, one button for "Enter radius points,"
another button for "Enter Mu value".

The Trim command relies on objectpicker to trigger selection of "Add trim points" button.
The Helix command relies on pointpicker to trigger selection of "Flat spiral" button.

I did try a dropdown box, with

code:
		<div id="ModeOptions" class="hiddencommandoptions">
			<table>
				<tr>
					<td>Mode:</td>
					<td>
						<select size = "2" id="Mode" style="width: 155px; height: 50px">
							<option value="radiusSpiral">Enter Radius Points</option>
							<option value="muSpiral">Enter Mu Value</option>
						</select>
					</td>
				</tr>
			</table>
		</div>

Which would need an Update button?
The select size = "2"... shows both options.
There was white space below the two options, which height: 50px removed, but maybe the css would control this?

- 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:  Michael Gibson
7238.57 In reply to 7238.56 
Hi Brian, well it kind of depends on how you want to structure the script - a dropdown (which will display in listbox mode if you use the size attribute like that), is good if you're trying to make things interactive with something updating when the dropdown is changed.

If you want something more simple like you just want the user to decide between 2 different possible modes of operation for the rest of the command, and you're not wanting to make it a choice they can flip back and forth and see something change immediately in response to that, it might be easiest to just make 2 <moi:PushButton> elements and then when the user clicks on one of those buttons that's what controls the mode you use after that. Does that sound like something that would fit? An example would be the Edit > History command, it shows 2 buttons like that.

Let me know if I have misunderstood what you're trying to do or if you need more information.

- 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.58 In reply to 7238.57 
Thank you very much Michael.
Right, different, appropriate, interactivity for different scripts.

I think I'll redo cone unwrap using pointpicker of the apex with frustum selection button as the split between menus.
(The alternative would be two mode buttons at the beginning, using the History style pair of buttons to split into two selection menus.)
(Both seem to be good choices.) (I'll redo the prompts also.)

For my simple 2D curve script, a pair of mode buttons seems a better choice.

Since I've used History button only a couple of times over the last several years, I did not realize it had a pair of buttons.
---unexplored MoI gems---
I'll study the History script today :-)

- 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:  Bravlin
7238.59 
Is there some kind of a "UserData" mechanism in Moid3D ?
In Softimage "UserData" store information available any moment for plugin functions and objects.
Its like a global variable for plugin that lie in dynamic memory.
It helps store information between launches of the plugin.
So your first run plugin result calculations can be transferred to second run etc.
  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.60 In reply to 7238.59 
Hi Bravlin, sorry no there isn't currently any mechanism like that set up for MoI scripting.

- 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-40  41-60  61-68