MoI discussion forum
MoI discussion forum

Full Version: Script help?

Show messages:  1-20  21-32

From: Paul (AIRGLASS)
24 Sep 2007   [#1]
Hi Michael:
I decided to try putting together a "nudge" script the other day using a variation of the "move" command, with the base point and target point set in the script. The idea is to select an object and use the Alt+ArrowKeys to move an object a set distance. I can't figure out tho, which properties for the movefactory that I can access to move an object (or if it's even possible).
I was thinking the base point could be an arbitrary point on the object (the midpoint maybe?) and the target point would be set by the nudge_dist variable.
Any advice on any movefactory properties I can use? (If you have time that is, I realize you're buried in the documentation work right now - )

The following is my rough outline so far :


#include "GetObjects.js"

function DoNudge()
{
var objectpicker = moi.ui.createObjectPicker();

objectpicker.allowEditPoints();

if ( GetObjects( objectpicker ) )
{
var nudge_dist = 1;
var objects = objectpicker.objects;
var movefactory = moi.command.createFactory( 'move' );

switch ( test for which arrow key? ){
case : 'LeftArrow'
nudge_dist = -1 ; break;
case : 'RightArrow'
break;
case : 'UpArrow'
nudge_dist = -1 ; break;
case : 'DownArrow'
break;
default : ;
}

movefactory.setInput( 0, objects );

switch (moi.ui.mainWindow.viewpanel.mode)
{
case 'front' :
movefactory.setInput( 1, objects.x);
movefactory.setInput( 2, objects.x + nudge_dist );
break;
case 'top' :
movefactory.setInput( 1, objects.x);
movefactory.setInput( 2, objects.x + nudge_dist );
break;
case 'right' :
movefactory.setInput( 1, objects.y);
movefactory.setInput( 2, objects.y + nudge_dist );
break;
default : ;
};

movefactory.commit();
}
}

DoNudge();


Thanks! Paul
From: Michael Gibson
24 Sep 2007   [#2] In reply to [#1]
Hi Paul, I've got to head out here in a minute so just a quick overview for now:

The move factory can take 4 inputs. Input 0 is the list of objects to transform. Input 1 is the base point, Input 2 is the offset point, and input 3 is an optional boolean input for whether to drop copies or not.

The points can actually be anywhere, the base point does not have to be actually snapped on to the object, it is only the relative difference between the base point and offset point that is used.

So you'll probably want to put your base point in your case just at 0,0,0 .

Then using an offset point of 1,0,0 for example would end up transforming the objects by the difference between 0,0,0 and 1,0,0 - in this case moving it by one unit over in x.

It may be a bit tricky to detect the arrow keys while in the command, at the moment that may require a bit of coordination with the .htm UI file.

I'll take a bit closer look later on.

- Michael
From: Michael Gibson
24 Sep 2007   [#3] In reply to [#1]
Hi Paul, here you go.

Take the attached Nudge.zip, unzip it to get Nudge.js and copy that into your \commands folder under your MoI folder in c:\Program Files.

Then go to Options / Shortcut keys, and add some new entries, like:

Key Command

LeftArrow Nudge Left
RightArrow Nudge Right
UpArrow Nudge Up
DownArrow Nudge Down

For the command, put a space after Nudge, so it's 2 words like "Nudge Left".

The Nudge command will look at those parameters when it runs.



You can also add some more for doing a larger or smaller step, like:

Ctrl+LeftArrow Nudge Left Large

Alt+LeftArrow Nudge Left Small

etc...

I think that should do it!

- Michael

Attachments:
Nudge.zip


From: Paul (AIRGLASS)
24 Sep 2007   [#4] In reply to [#3]
Wow Michael !,
Just d/l the zip file and took a look at the script -- very nice!
Small, clean and to the point. Much better than my clumsy attempts!
Now to try it out....
Thanks much --

Paul

p.s. - I also wanted to compliment you on the docs you've written so far -
you have a talent for explaining the functions and concepts very clearly!
That's something not seen very often --
From: tyglik
25 Sep 2007   [#5] In reply to [#3]
Hi Michael,

Nice!

By the way, I guess Bernard wished that nudge command for moving a control points many months ago.

It's pitty that you have no time to spare in order to start writing a documentation for MoI scripting...

Petr
From: Paul (AIRGLASS)
25 Sep 2007   [#6]
Hi Michael,
Tried out your nudge script and it works great!
I started playing around with the script and ended up adding in a test for the viewport the mouse is in (when in split viewport mode). This variation will adjust the object axis movement according to the viewport the pointer is in. Thanks again for the script and help!

Paul

Attachments:
Nudge_variation.zip


From: Schbeurd
14 Nov 2007   [#7] In reply to [#5]
>>> By the way, I guess Bernard wished that nudge command for moving a control points many months ago.

Exactly ! ;-)
I don't have much time to use MoI these days but I was able to try it today and it's exactly what I requested !
Thanks to Michael and Paul. Very useful script. I'm very happy with it ! ;-)
From: Frenchy Pilou (PILOU)
14 Nov 2007   [#8]
What happen when a same key (the arrow keys) are yet use for other thing (rotation in my case of the space work for example)
What is the first script used? (alphabetic order) ?
(if I don't change the shortkey of course)
From: Michael Gibson
14 Nov 2007   [#9] In reply to [#8]
Hi Pilou, there can be only one command or script attached to one particular key combination.

If you try to add more than one into the editor, you will find that only one of them has been actually used when you open the editor again - the one that was defined first in the editor list will be the one that is kept.

If you want to use the arrow keys to do different things, you can use some modifier keys.

Like for instance you can use just the plain arrow keys for rotation, and then use Ctrl+Arrow keys for nudging.

You can use Shift, Alt, or Ctrl either alone or in combination with one another as modifiers.

- Michael
From: Jesse
10 Mar 2008   [#10] In reply to [#9]
Hi Michael,

I installed the Nudge script and added some shortcut keys.
It worked, but I couldn't move objects up or down in Z in any viewport.

Then I took the Nudge script out of the command folder
so I could try the NudgeViewAxis script, using the same
shortcut keys, but it would not work at all.

Are there a different set of commands needed for the NudgeViewAxis script?

I'd prefer to use the the Nudge script, but I couldn't get either one
to move things in the Z axis...maybe I'm missing something?

Perhaps I could assign PageUp and PageDown for the Z axis if there's
a special command for it.

Thanks,

Jesse
From: Michael Gibson
10 Mar 2008   [#11] In reply to [#10]
Hi Jesse - that Nudge script was just never set up to handle moving in the z direction.

I've tweaked the attached version to support it. If you use this new version, you can set PageUp and PageDown for z nudging, like:

PageDownNudge zdown
PageUpNudge zup


You should also be able to set up Ctrl+PageUp/down and Alt+PageUp/down for larger or smaller steps same as mentioned here: http://moi3d.com/forum/index.php?webtag=MOI&msg=952.3

Please let me know if you have any problems setting it up!

- Michael

Attachments:
Nudge_z.zip


From: tyglik
10 Mar 2008   [#12] In reply to [#10]
Hi Jesse,


I prefer to use a Paul's script - NudgeViewAxis. From my point of view, it makes more sense to me to move a points in "cplane coordinate system" than world one...

>>I could try the NudgeViewAxis script, using the same
>>shortcut keys, but it would not work at all.

You must define a shortcut like:
LeftArrow NudgeViewAxis Left

or rename the file from "NudgeViewAxis.js" to "Nudge.js" if you don't want to change the command part of shortcuts.

I guess I should rename the js file in zip file itself and let only the different name of zip file on my webpage....

Petr
From: Jesse
12 Mar 2008   [#13] In reply to [#11]
Thanks Michael,

I'll give it a try.

Jesse
From: Jesse
12 Mar 2008   [#14] In reply to [#12]
Hi Petr,

I'll try this one too... for some reason I've always set up
Nudge in Rhino to work from the world view, so I guess I'm
just used to that way.

Either script really helps...

Thanks,

Jesse
From: Dymaxion
15 Apr 2008   [#15]
The nudge script is nice, but it'd be nice to have it default to move by the smallest snap step, instead of 1 unit. How do you get at the current snap step sizes? Altering the script looks trivial, given that.
From: Michael Gibson
15 Apr 2008   [#16] In reply to [#15]
Hi Dymaxion,

If you want to set your arrow keys to go by the smallest step size when you push them without any modifiers (like Alt or Ctrl) , then that should be possible by modifying your keyboard shortcut.

Put in keyboard shortcuts like this:

LeftArrow Nudge Left Small
RightArrow Nudge Right Small
UpArrow Nudge Up Small
DownArrow Nudge Down Small

By adding that parameter "Small" at the end there, that should cause the plain arrow keys to move by the small increment amount.

If that doesn't do what you want, can you please describe it a bit more, and maybe attach or show a link to which version of the Nudge script you are using? (because there are a few variations of it).

- Michael
From: Michael Gibson
15 Apr 2008   [#17] In reply to [#15]
Or do you mean you want to move it by the current grid size setting, the one that is set under Options / Grid?

You can retrieve that value in a script by using this: moi.grid.snapSize

- Michael
From: Dymaxion
16 Apr 2008   [#18] In reply to [#17]
Great! That's exactly what I was hoping for -- works just fine. I'm using the global-axis version from Petr's page. Petr, if you read this, you might think about making the change -- just change the fixed value of 1.0 on line 17 to "moi.grid.snapSize".

One more question -- I know you haven't had time to write docs for the scripting APIs (and believe me, you've got my sympathy there), but do you have a list of them? I've been pondering messing around with reflection and generating a list, but it seems like a waste of time if you already have one. If so, it'd be great if you could, say, toss it up on the wiki -- I know I'd be happy to at least document things piecemeal as I find my way around.

/Ella
From: Michael Gibson
16 Apr 2008   [#19] In reply to [#18]
Hi Ella,

There is a list of all the stuff available to scripts, check out the moi_idl.zip file attached to this post: http://moi3d.com/forum/index.php?webtag=MOI&msg=1078.13

When you unzip that you will get the moi.idl file which is the definition of all the scripting interfaces for MoI. It's basically a list of all the properties and methods available.

I've been meaning to put up something for this in the wiki for a while, I'll see if I can figure out a good spot to carve out for that tomorrow.

- Michael
From: wheel
17 Apr 2008   [#20]
Hi, I quite like the idea of changing the nudge distance to whatever the "grid snap" is set to, but am having problems getting it to work. I have tired setting the " var dist = moi.grid.snapSize; " in both Petr and Michaels nudge script versions. Should the hotkey settings be the same for Petrs and Michaels versions , the four arrow keys and page up and down ?

Show messages:  1-20  21-32