I am new to using MEL to write scripts.
I have two radio buttons, one and two. When radio button 'two' is selected, I want the script to select the two cube objects I have created in my scene (cube1 and cube2), so that when I use my 'rotate' button (a regular push button), both of the cubes rotate.
On the other hand, if the radio button 'one' is selected, then only one of them (cube1) should rotate when I press the rotate button.
I have my radio buttons as follows:
$radio1 = `radioCollection`;
//my radio buttons
$one = `radioButton -label "1 cube"`;
$two = `radioButton -label "2 cubes"`;
radioCollection -edit -select $one $radio1; //so that this one is selected by default
and for the rotate button I have this that rotates the cube object 'cube1' by 30 degrees. This is currently NOT linked to my radio buttons.
button -label "rotate" -command "setAttr cube1.rotateZ `floatSliderGrp -q -value 30.0`";
Thoughts? Should I query the radio button's state? This would be so much easier for me in another language! I could see myself saying something like "if $radiotwo.pressed, then cube1.rotateZ && cube2.rotateZ"
All Maya UI items are completely imperative: you have to issue commands and get results, there is no 'state': the 'button' or whatever will just be the string name of the object you'll use for issuing the commands
To get the state of the radiocollection you call radioCollection -q -select on the collection, which will return the name of the selected radio button; you'd use that to drive your logic.
string $w = `window`;
string $c = `columnLayout`;
string $radiocol = `radioCollection "radio buttons"`;
string $one_cube = `radioButton -label "1 cube"`;
string $two_cube = `radioButton -label "2 cubes"`;
radioCollection -edit -select $one_cube $radiocol;
showWindow $w;
global proc string get_radio_state(string $radio)
{
string $selected = `radioCollection -q -select $radio`;
return `radioButton -q -label $selected`;
}
print `get_radio_state($radiocol)`;
fiddle with the radio buttons and get_radio_state($radiocol); it should return the name of the selected button.
If you're already familiar with other languages, you should probably skip MEL and jump straight to maya python: it's much more capable and less tweaky. Lots of discussion here and here
For comparison, here's a python version of the same idea:
w = cmds.window()
c =cmds.columnLayout()
rc = cmds.radioCollection()
cmds.radioButton('one', label="1 cube")
cmds.radioButton('two', label = "2 cubes")
def print_selected(*ignore):
print "selected", cmds.radioCollection(rc, q=True, select=True)
btn = cmds.button("print selected", command=print_selected)
cmds.showWindow(w)
Here the button does the same thing as the print statement in the earlier example
Related
Is there any way to create a drop down toolbar button(Like Paste button in MS Word) using Tcl/TK?.I have googled a lot but nothing found.Any help will be appreciable.
You probably want to use a menubutton and a menu, probably with radiobutton entries if I've understood which UI element in Word you're talking about. (Or maybe a ttk::menubutton and menu.) Now, if you're doing something very simple with it then you can make do with just tk_optionMenu as a way to combine those commands, but that's just a simple procedure; if you're doing something complicated with the menu, it's probably easier to write it yourself or at least to get the code for tk_optionMenu and to customise it how you want it to work.
The source code for tk_optionMenu isn't very long; I'll paste the non-comment parts of it here:
proc ::tk_optionMenu {w varName firstValue args} {
upvar #0 $varName var
if {![info exists var]} {
set var $firstValue
}
menubutton $w -textvariable $varName -indicatoron 1 -menu $w.menu \
-relief raised -highlightthickness 1 -anchor c \
-direction flush
menu $w.menu -tearoff 0
$w.menu add radiobutton -label $firstValue -variable $varName
foreach i $args {
$w.menu add radiobutton -label $i -variable $varName
}
return $w.menu
}
You probably want to pay attention to how the menubutton and menu are connected to each other. ttk::menubutton is mostly a drop-in replacement for menubutton, except for different look-and-feel configuration options.
I have an app using shoes. In the model, I have
def run()
query = get_queries
executeQuery(query)
run()
end
Then this get_queries will append some buttons to stack, say
button "do 1"
button "do 2"
button "do 3"
button "do 4"
If the user clicks on the button, get_queries should return the corresponding query (Sometimes it may ask the user for more info, so basically, it returns an array containing query and info). And then the buttons are removed.
However, I am confused as to how to let the buttons return value for that function. I thought of using a variable and check if the variable is updated by busy waiting, but I don't think that is the efficient/right way to do it.
Any suggestions? Or is there another way to this?
I think you need to make your program work somewhat differently. Make get_queries append the buttons to the stack, as it does now, but move the other things from the run method into another method that is called only after the button receives a click-event.
def on_click(button_number)
executeQuery(button_number)
run()
end
button "do 1" do
on_click 1
end
button "do 2" { on_click 2 }
button "do 3" { on_click 3 }
...
I have a form which consists of six radio buttons within a frame which are mutually exclusive and one command button.
I already gave different tab-index to each radio button but at the run time by pressing tab focus skipped out of the radio buttons.
so how to give focus to another radio button by pressing TAB?
As others have said above this is intended behaviour. If you really wish to achieve this then the only way I can think to do this is place each radio button on a separate picture box (BorderStyle = None, TabStop = False). This will then work but you won't be able to use arrow keys to move between the radio buttons, only tabbing.
Private Sub Option1_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
Option2.SetFocus
End If
End Sub
KeyAscii=9 is the code for the Tab key. But you must do it for all of your radio buttons.
If you add your radio buttons belonging to the same radio button having indices 0, 1, 2 you can do it like this:
Private Sub Option1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 9 Then
If Index < Option1.Count - 1 Then
Option1(Index + 1).SetFocus
Else
Option1(0).SetFocus
End If
End If
End Sub
I made a form and created a command button control. I would like to make it so that when the user presses the command button it sends a keystroke to a listbox of my choice.
Specifically, I want the command button to send a "down" arrow keystroke to a listbox (which will have focus) so that it goes from the current item to the next item.
How do I do this?
Let's say the name of my listbox is "lstFruits". I gave it focus, then tried SendKey.
Form.lstFruits.SetFocus.
SendKeys.Send ("{DOWN}")
Got the error "Argument not optional".
There is no need to emulate a keystroke, you can control the listbox in code;
lstFruits.SetFocus
if ((lstFruits.listindex + 1) < lstFruits.listcount) then
lstFruits.listindex = lstFruits.listindex+ 1
endif
Edit
Dim strName As String
strName = "lstFruits"
Dim lst As VB.ListBox: Set lst = TheForm.Controls(strName)
lst.SetFocus
If ((lst.ListIndex + 1) < lst.ListCount) Then
lst.ListIndex = lst.ListIndex + 1
End If
In VB6 I need to know how to call a button click event on anther form. The another form part is easy but how to pass the click event the proper method to "click" the right button on the toolbar is the real issue.
Here is the vent on the main form - i need to call the click event case "Copyfrom".
MainForm
Public Sub tbrMain_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Index
Case ToolBarItem.tbPrint
'(some code)
Case ToolBarItem.tbSave
'(some code)
Case ToolBarItem.tbCopyFrom
'(some code)
Case ToolBarItem.tbNEW
'(etc)
I tried
Mainform.tbrMain_ButtonClick()
and even tried passing the index number and key - no dice.
The event handler is expecting to receive a reference to an actual toolbar button, so you have to pass the toolbar button itself, not it's Caption or Key, e.g.:
Form1.tbrMain_ButtonClick Form1.tbrMain.Buttons(1)
Or, using the Call statement:
Call Form1.tbrMain_ButtonClick(Form1.tbrMain.Buttons(1))
If you set the Key properties on your toolbar buttons, you can use the Key property of the desired button in place of the (1):
Form1.tbrMain_ButtonClick Form1.tbrMain.Buttons("PrintButton")
Private Sub Toolbar1_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
If ButtonMenu.Key = "A" Then
MsgBox "Button-1"
ElseIf ButtonMenu.Key = "B" Then
MsgBox "Button -2"
ElseIf ButtonMenu.Key = "C" Then
MsgBox "Button -3"
ElseIf ButtonMenu.Key = "D" Then
MsgBox "Button -4"
ElseIf ButtonMenu.Key = "E" Then
MsgBox "Button -5"
End If
End Sub