Scripting: Doing a scale and then rotate on the same object

Next
 From:  achmey (ACHIM)
11421.1 
Hi, I'm new to the forum, have been using Moi for a while now (and of course loving it) but just dived into scripting a couple of Days ago.
I understood that the scripting-doc. is mainly the existing scripts and commands - but so far I could't get a hint how to solve this seemingly simple problem:

I'd like to do multiple (at least two) transforms on the same object (a curve). But when i run the (stripped) code following below I always end up with 2 curves - one scaled
(but not rotated) and the other rotated (but not scaled). The "make copy" flag does not seem to have any effect.

So my concept of what the factories do seems to be too simple. Does anyon have a clue what's going on under the hood here (history-sideeffects?) and what
is needed to get it right - or can point me to a script that does something similar (multiple transforms on same object)? Thanks in advance for any effort!

Achim

var scaleFactory = moi.command.createFactory( 'scale' );
scaleFactory.setInput( 0, curve );
scaleFactory.setInput( 1, pointpicker.pt );
scaleFactory.setInput( 2, 2.0 ); // scale-factor
scaleFactory.setInput( 5, false ); // "make copy" false
scaleFactory.update();
scaleFactory.commit();

var rotFactory = moi.command.createFactory( 'rotate' );
rotFactory.setInput( 0, curve );
rotFactory.setInput( 1, rotFrame );
rotFactory.setInput( 2, 5 ); // angle
rotFactory.setInput( 5, false );
rotFactory.update();
rotFactory.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:  Michael Gibson
11421.2 In reply to 11421.1 
Hi Achim, check out an example here:
http://moi3d.com/forum/index.php?webtag=MOI&msg=5416.5

- 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:  achmey (ACHIM)
11421.3 
Thank you so much for the super-duper quick reply Michael!
That script has exactly the info i needed to get it running.

To summarize it quickly: The "trick" is basically to call factory.calculate() (and then cancel())
instead of .commit() and use the returned object-list as input for the next
transform-factory:


var scaleFactory = moi.command.createFactory( 'scale' );
scaleFactory.setInput( 0, curve );
scaleFactory.setInput( 1, pointpicker.pt );
scaleFactory.setInput( 2, 2.0 ); //scale
scaledCopyCurve = scaleFactory.calculate(); // (actually an list of objects)
scaleFactory.cancel();

var rotFactory = moi.command.createFactory( 'rotate' );
rotFactory.setInput( 0, scaledCopyCurve );
rotFactory.setInput( 1, rotFrame );
rotFactory.setInput( 2, 5 ); // angle
rotFactory.commit(); // either like this or use .calculate()/.cance() again (if more transforms follow)

Achim
  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:  pressure (PEER)
11421.4 In reply to 11421.3 
Hi Achim,

Re:
> The "trick" is basically to call factory.calculate() (and then cancel())

The cancel part probably isn't necessary here. The reason to cancel is if something like .update() causes stuff to be added to the scene while the plugin is running and you want to remove that stuff for a subsequent step of the plugin.

For a command (run from the commands folder) any active factory that hasn't had .commit() called will get canceled when the command exits. So, another time when you might need to cancel a factory is if your plugin is run as an instant script rather than as a command.

- Peer
  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:  achmey (ACHIM)
11421.5 In reply to 11421.4 
Hi Peer,

thanks for the clarification. So the .cancel() step could be left out when used in a command-script because there is a kind of final cleanup when the command ends. On the other hand it does not seem to hurt and would make the code reusable in a plugin/instant-script - or do you know of a caveat with this (other than bloated code - which of course might become a problem at some point)?

Achim
  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
 From:  pressure (PEER)
11421.6 In reply to 11421.5 
I don't think calling .cancel() will cause any technical problem Achim.

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