PDA

View Full Version : Shift Click using buttons?


mccollom73
10-13-2010, 12:31 AM
Hey everyone,

I have a made a few buttons, and I want the option to Shift click one of them. This way, it'll select more than one object....as you know.

Would a simply if statement work? I know about the `getModifier` tag, but would this work with what I am using?

Thanks,

Josh

NateH
10-13-2010, 04:41 AM
Yeah, use get modifiers, it will work perfectly for doing something like this. You don't even need to use an if statement, just pass the shift modifier state into the add flag:

modifiers = cmds.getModifiers()
shift = bool((modifiers & 1) > 0)
cmds.select(objToSelect, add=shift)

mccollom73
10-14-2010, 05:51 AM
Yeah, use get modifiers, it will work perfectly for doing something like this. You don't even need to use an if statement, just pass the shift modifier state into the add flag:

modifiers = cmds.getModifiers()
shift = bool((modifiers & 1) > 0)
cmds.select(objToSelect, add=shift)

So would it look like this then?


string $myWindow = `window -title "Riggit GUI" -widthHeight 755 727` ;
string $myForm = `formLayout -numberOfDivisions 10`;
string $myBtn0 = `button -label "Head" -command "modifiers = cmds.getModifiers()
shift = bool((modifiers & 1) > 0)
cmds.select(objToSelect, add=shift"`;

formLayout -edit
-attachForm $myBtn0 "top" 80

$myForm;
showWindow $myWindow;



Sorry, still learning.

Josh

NateH
10-14-2010, 09:07 AM
Unfortunately you can't mix my code with yours like that because I wrote mine in python.

Here it is in all MEL (And now I'm absolutely positive MEL sucks compared to python, after being away from MEL for so long... Very clunky)

string $myWindow = `window -title "Riggit GUI" -widthHeight 755 727` ;
string $myForm = `formLayout -numberOfDivisions 10`;
string $myBtn0 = `button -label "Head" -command "string $object=\"head\"; int $mods = `getModifiers`; if (($mods/1)%2==1)select -add $object;else select $object;"`;
showWindow;


Here it is in python:
import maya.cmds as cmds

cmds.window(t='Riggit GUI', wh=[755, 727])
form = cmds.formLayout(numberOfDivisions=10)
cmds.button(l='Head', c='cmds.select("head", add=cmds.getModifiers()&1)')
cmds.showWindow()

mccollom73
10-14-2010, 05:46 PM
I'm trying to finish this rig I am working on, then i am going to move to Pyhton. It just seems easier.

Thank you for the responds, I will let you know how it works here in a few days.

Josh

EDIT:

Works amazingly! I am so excited about this. I am finally understanding how MEL works a little more as well. Slowly I am learning.

Thanks again!

CGTalk Moderation
10-14-2010, 05:46 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.