Dec 2014
1 / 15
Dec 2014
Jan 2015

Hi everyone, , \n  is it possible to make a script that changes the behave of the 3 Mouse Buttons?  \n  I'd like a script "MOVE" that when activated moves the selected object in X when I press the LMB, in Y when I press the MMB and in Z when I press the RMB.if yes it possible to do this in Python also?    \n      I want to start learning about Maya scripting but if the above is not posible i'd rather avoid to loose months of reading before discovering so.       \n   Thanks!Sergio

  • created

    Dec '14
  • last reply

    Jan '15
  • 14

    replies

  • 4.8k

    views

  • 1

    user

  • 4

    links

You might want to scratch the "\n" for forum posting. Haha... 

If you really want to do something like this, you'll need to mess with the API, which is actually not a good thing to do.

I'm pretty new to scripting and programming, in general, but I've been scripting in Mel for the past year. You can't change it using MelScript. Python brings better functionality from its end, to Maya, and is essentially emulated, for all intents and purposes, in Maya.

When coding with Python, you end up calling out MelScripts and Mayas functions (or the ones it allows you to use, when using Python). It doesn't actually let you mess with the mouse buttons.

If you want to mess with the API, which is the actual code that Maya utilizes for running, then you need to know C++. Mel runs off of C++, but C++ functionality and usage is not brought directly into Maya. From what I've learned, it's so the user doesn't actually screw up the program or have full access to Mayas internals.

TL;DR

No, not really. There might be a way, but I haven't found anything in relation to it.

Why would you though? You'd end up not being able to deselect, reselect or select a new object, unless you were intending to do everything through melscript. AKA:

select object,
move it with new mouse buttons,
click inside mel-coding box, 
type "select -clear"
enter
select next object
repeat inefficient workflow 

Thanks, your reply clarified many things already.

All I want is to recreate the Alias Autodesk system.

In Alias you select an object, activate the MOVE tool, and move the object until you want with the three mouse buttons.

This allows a much faster modeling process expecially when you got to reaorganise many vertex, which happens a lot in Maya.
Unfutunately Maya as this lame method of using the manipulator that slows down the process massively.

I see what you mean and it is probably going too difficult to reorganise the API code for my scope.

Maybe I can though create three different script something like:
MOVE X
MOVE Y
MOVE Z

so that I can activate each of them by a different hotkey and then use only the left mouse button to move in the choosen direction.

Of course when the move has ended I should terminate the script which will deselect the selection and I could move on to the next Vertex to be moved.

Would that all be possible by Python?

I honestly don't think so. You'd be lucky if you could.
However, why use that when you can click one of the manipulator tool arrows and just mm-drag the object in that direction?

There is a mouse and keyboard interaction setting, so there is room for a plugin to change how the mouse works. Where a download is for that, beats me. 

because to press an hotkey would be far faster and cleaner than selecting the manipulator.

It is a small thing if considered as a single action, but trust me, when you have to move 50 vertex in a minute id does make a massive difference. In the field I work is all about modeling fast and precise, and they want us to use Maya to be even faster so I am quite diappointed with this less effective method.

The manipulator is such a lame concept:

Manipulator method:
1.select object
2.select arrow to move (2b.which some time gets also dodgy because of bad viewing angles that overshadow one arrow with the other or because other vertexes are in the way, it just adds an operation that makes the worflow really dirty)
3.move mouse

3 Mouse Buttons method:
1.select object
2.move mouse pressing chosen button/direction

That is why in Alias they have a very well advanced move vertex set of tools 

Yeah, sorry. I'd offer a bit more help, but I'm still new to some of this stuff. C++ (API) is probably your best bet.

There might be a way to do it through Python, but I don't want you to waste your time in the case that it doesn't work...

It would be cool, if you could, to set up hotkeys like this:

Press X and mm-drag: selects X axis on manipulator and drags in that direction
Press Y and mm-drag: Same but on Y axis
Press Z and mm-drag: Same but on Z axis

I mean, it's a bit inefficient, so you'd have to set up hotkeys elsewhere... zxc perhaps...
I think that'd be a bit more doable unless you can figure out how to set up a toolbar/ window with specific functions that allow you to select the axis you want to move on.

that's great thanks a lot for your help.

one last thing where would y ou say I should start from to learn about API?

would you reccomend this book?
Complete Maya Programming - An Extensive Guide to MEL and C++ API 1st Edition . Jan 2003

Audoesk has been progressively making maya manipulators lamer over the years. Anyway:

Maya sort of has this already when you hold shift down and middle mouse button (MMB) with move tool on maya picks the axis direction closest to your mouse movement direction. The middle mouse in maya is all powerful super manipulator. Same applies if you for example have the cv curve tool active and hold MMB down... etc etc... MMB, manipulates whet you have selected so the active axis is allays MMB where ever you are.  (autodesk does not seem to be aware of this feature as they reinvented this feature in 2014 to a worse version)

You can also do the keyboard affect the active axis. Thus you can make keyboard toggles for Middle mouse drag will move the object will move in active axis direction, see the documentation of manipMoveContext11, you can toggle to whatever you want. Example sey the y axis active:

manipMoveContext -e -activeHandle 1 Move; // 0 for x 1 for y and 2 for z

While you can make your own context its not really worth it, its a insane investement on your time. Just use the methods you have.

Would you reccomend this book?
Complete Maya Programming - An Extensive Guide to MEL and C++ API 1st Edition . Jan 2003

NO, the book is good for 5 pages. Which admittedly are golden, invaluable in fact, but the rest of the book is completely waste of time. It also does not cover context programming the way you need it to.

one last thing where would y ou say I should start from to learn about API?

6http://docs.autodesk.com/MAYAUL/2014/ENU/Maya-API-Documentation/index.html6

Start by reading the introduction first. But now im am gone for a month again.

thanks a lot Joojaa! 

MMB+shift using the camera in orthographic mode works just great.. plus using Twick Mode and disabling the "remember active handles" had a big improvement for me in respect to the default autodesk workflow.

Not like Alias but much better now!

You are right it would be a too big waste of time for me to make my own context. I think I only need to mastera littel of python/MEL and create some script/hotkey to get a more efficient interface.

Autodesk seems always working for people who are newbie, is concentrated in making life easier to whom knows nothing of the software. Unfortunately the easiness for a newbie is inversely proportional to the efficiency for professionals.

I suppose this is what happens when software companies become too big corporation and politics/marketing gets in front of the product quality. I suppose a crap coded software with fancy icons sells more than a very efficient engineering looking like interface.
Small teams can create more quality than armies of coders that loose the big picture and just look after their own harses rather than the overall product quality.

JooJaa, thanks for the valuable piece of information! Yet another thing I hadn't figured out with Maya (even after working with it for going on three years!).

Sergio, if I get some time, I'll make a small little interface implementing what JooJaa posted if you want... and post it up here for you (Christmas Present?). That way, if it's stable enough, you can try to extract the code from it and mess with it to your liking. MEL is very powerful (not in the context of all the scripting language possible, but for Maya).

Most maya users dont know how to use even 10% of maya, dont worry. After 13 years i still dont know more than 50% of the things functions. Let alone what you could do with them.

Hehe, thank you Joojaa. I'm sure you know more than you're willing to admit.

thanks a lot Crisosphinx, that would be very much appreciated :wink:

//Run this script LOCALLY and not through source <-- It'll cause an error due to the procedure and strings being set to local.
//Deletes window if it's already there
if(`window -exists $window`)
{
    deleteUI -window $window;
}
//Define window
string $window = `window -title "XYZ Window" -toolbox true -widthHeight 140 160`;
//Define layout
string $form = `formLayout -numberOfDivisions 10`;
//Define buttons and their functions
string $b1 = `button -backgroundColor 1 0 0 -width 60 -height 30 -label "Move X" -command "manipMoveContext -e -activeHandle 0 Move;"`;
string $b2 = `button -backgroundColor 0 1 0 -width 60 -height 30 -label "Move Y" -command "manipMoveContext -e -activeHandle 1 Move;"`;
string $b3 = `button -backgroundColor 0 0 1 -width 60 -height 30 -label "Move Z" -command "manipMoveContext -e -activeHandle 2 Move;"`;
string $b4 = `button -backgroundColor 0 0 0 -width 60 -height 30 -label "Close" -command "deleteUI $window;"`;
formLayout -edit
    -attachForm     $b1     "top"    5
    -attachForm     $b1     "left"   5
    -attachControl  $b1     "bottom" 5 $b3
    -attachControl  $b1     "right"  5 $b2
    -attachForm     $b2     "top"    5
    -attachNone     $b2     "left"
    -attachControl  $b2     "bottom" 5 $b3
    -attachForm     $b2     "right"  5
    -attachNone     $b3     "top"
    -attachForm     $b3     "left"   5
    -attachControl  $b3     "bottom" 5 $b4
    -attachForm     $b3     "right"  5
    -attachNone     $b4     "top"
    -attachForm     $b4     "left"   5
    -attachForm     $b4     "bottom" 5
    -attachForm     $b4     "right"  5
$form;
//Run the window
showWindow $window;

Hopefully that'll help you a little bit Sergio! Merry Belated-Christmas/ Holidays!!! Take this code, plop it into your script editor, highlight it all, middle click it into your shelf and it should work.

(Just so you know, you can find a few examples of this type of thing on the Mel commands documentation found here:
http://download.autodesk.com/global/docs/maya2013/en\_us/Commands/index.html4

FormLayout --> http://download.autodesk.com/global/docs/maya2013/en\_us/Commands/formLayout.html5

Easy peasy stuff, once you get the hang of it!)

-Criso 

13 days later

Update:

I feel stupid mentioning this a few weeks later, but there is a script command called, "getModifiers".

I'm not sure if you could edit the mouse buttons  thought it, but it could be worth a try!

You can use getModifier like this:

int $mods = `getModifiers`;
if ($mods==1)
{	
print("Shift is pressed \n");
}
if ($mods==4)
{
print("Ctrl is pressed \n");
}
if ($mods==5)
{
print("Ctrl + Shift are pressed \n");
}
if ($mods==8)
{
print("Alt is pressed \n");
}
if ($mods==9)
{
print("Alt + Shift are pressed \n");
}
if ($mods==12)
{
print("Ctrl + Alt are pressed \n");
}
if ($mods==13)
{
print("Ctrl + Shift + Alt are pressed \n");
}

This is helpful, because now you can add the manipulators to it, potentially.

SO, you could designate that ctrl = x, shift = y and alt = z.

I have yet to try it out, but at least it's a little bit of a push into the right direction.

Tried it out, it works. I set it up as a button in a window.

-Criso