View Full Version : Reset and Set Key Buttons On Sliders
thaumaturge
06-25-2010, 03:34 PM
I have been struggling to find a way to put sliders under a tab, when i finally get it, i cannot put set key buttons and reset buttons at the right side of the slider. before i could have these buttons but i couldnt have sliders.
here is the script, it should work just fine if you run it on a empty maya scene.
//sphere-------------------------------------------------------
proc cm_mySliderContents (){//Open procedure…
string $col = "myColumnL";
//Create a collapsible frame containing wrapped buttons:
columnLayout $col;
// use loop to create 10 sliders:
{//open loop…
string $sphere [] = `sphere`;
columnLayout;
//HELP ME PUT RESET AND SET KEY BUTTONS ON THIS SLIDER!!!!!!!!!!------------------------- <<<<<< LOOK <<<<------------
attrFieldSliderGrp -l " sphere" -cal 1 "left"
-min 0.0 -max 1.0 -s 1 -at ($sphere[0] + ".tx");
}//Close loop.0
setParent $col;
setParent..;
}//End procedure.
//-------------------------------
//create window with two tabs
string $facial;
if (`window -ex $facial`) deleteUI $facial;
window -t "facial" -wh 500 400 $facial;
string $form = `formLayout`;
string $tabs = `tabLayout -imw 5 -imh 5`;
formLayout -e -af $tabs "top" 0 -af $tabs "left" 0
-af $tabs "bottom" 0 -af $tabs "right" 0 $form;
//create 1st tab contents using slider procedure
string $tab1 = `columnLayout` ;
cm_mySliderContents;
setParent $tabs;
//create 2st tab contents using slider procedure
string $tab2 = `columnLayout` ;
cm_mySliderContents;
setParent $tabs;
//add labels for the tabs:
tabLayout -e -tl $tab1 "Slider Tab1" -tl
$tab2 "sliders Tab2" $tabs ;
showWindow $facial;
perna
08-23-2010, 05:55 PM
/*
hey there thaumaturge,
If I understand you correct you want to make an attrFieldSliderGrp and a reset button for it.
Here is how I would go about it.
Sorry but I dont want to go through your code it takes me too long.
However I have tried to make as many comments in my code as possible to make it easy to read.
Cheers and best of luck
-Perna
*/
//////////////////////////////////////////////////////////////////////////////
//check for window and delete
if (`window -ex sliderTest`)
{
deleteUI -window "sliderTest";
}
//UI for window
string $testWindow = `window
-title "the title"
-rtf true
-s true
-widthHeight 500 500
sliderTest`;
//Creates a sphere we will control with the slider.
string $objName[] = `sphere`;
//This string will hold the slider name and path.
string $slider;
//Defines the layout number of columns = 2
rowColumnLayout -numberOfColumns 2 - columnWidth 1 50 - columnWidth 2 400;
//Buttons and sliders Row 1.
//Column 1
button -h 30 -label "reset" -command "resetSlider($slider, $objName)";
//Column 2
string $slider = `attrFieldSliderGrp -label "sliderName" -cal 1 "center" -min 0.0 -max 10.0 -s 1 -at ($objName[0]+".tx")`;
proc resetSlider(string $slider, string $objName[]){
setAttr ($objName[0] + ".tx") 0;
}
showWindow sliderTest;
duongy
09-05-2010, 09:13 AM
I have a similar problem on my window, I am trying to set up a simple reset and set key buttons using a floatSliderButtonGrpm
The problem I get is that, the set and reset keys work, but only if the object itself is selected in the viewport, if a different object is selected then the slider will still work but the buttons will not. It comes up with an error.
can anyone help me as I am new to mel scripting and Maya in general.
below is the code I am trying to use.
//Slider-button Group GUI EXamples:
global proc cm_mySlider (string $label, int $min, int $max,
string $objAttr, int $reset, string $name)
{//open procedure...
// create slider using arguments:
floatSliderButtonGrp -l $label -f 1 -s .01 -min $min - max $max
-cal 1 left -cw5 100 40 160 50 35 -bl "Reset"
-bc ("setAttr " + $objAttr + " " + $reset)
-sbc ("setKeyframe " + $objAttr) -sbd 1
-i "SETKEYFRAME.xpm" $name;
//connect slider to the node attribute:
connectControl $name $objAttr;
}//close procedure.
//run procedures in window to animate object:
string $pcube1[] =`select -r cc_ship_top `;
if ( `window -exists MyWindow` ) {
deleteUI MyWindow;
}
string $filePath = "C:/Users/Duongy/Desktop/FYP_mel/";
window -t "Space Ship Controls"MyWindow;
columnLayout -adjustableColumn true;
image -w 400 -h 100 -i ($filePath + "ship_header.BMP");
text- l "";
// run slider procedure to create and connect sliders:
cm_mySlider (" Top Stretch",-1,1,($pcube1[0] + ".ty"),0,"mySlider1");
string $ccbottom[] =`select -r cc_ship_bt `;
cm_mySlider (" Bottom Stretch",-1,1,($ccbottom[0] + ".ty"),0,"mySlider2");
string $pcube1[] =`select -r cc_ship_top `;
showWindow;
Any help would be great
gutterFish
09-05-2010, 04:04 PM
what is the error?
what happens if you call the UI without anything being selected?
chrisg
09-06-2010, 05:07 PM
Hi duongy,
The issue is that you're not actually setting $pcube1[0] or $ccbottom[0] to anything. So, you're passing nothing to the cm_mySlider command and what happens is, whatever is selected gets keyed/reset.
edit: so to fix this, you need to actually set the variables to the strings you want them to. Instead of using a selection command, I just passed the names in, since that's all you needed.
//Slider-button Group GUI EXamples:
global proc cm_mySlider (string $label, int $min, int $max,
string $objAttr, int $reset, string $name)
{//open procedure...
// create slider using arguments:
floatSliderButtonGrp -l $label -f 1 -s .01 -min $min - max $max
-cal 1 left -cw5 100 40 160 50 35 -bl "Reset"
-bc ("setAttr " + $objAttr + " " + $reset)
-sbc ("setKeyframe " + $objAttr) -sbd 1
-i "SETKEYFRAME.xpm" $name;
//connect slider to the node attribute:
connectControl $name $objAttr;
}//close procedure.
//run procedures in window to animate object:
if ( `window -exists MyWindow` ) {
deleteUI MyWindow;
}
string $filePath = "C:/Users/Duongy/Desktop/FYP_mel/";
window -t "Space Ship Controls"MyWindow;
columnLayout -adjustableColumn true;
image -w 400 -h 100 -i ($filePath + "ship_header.BMP");
text- l "";
//set variables
$pcube1[0] = "cc_ship_top";
$ccbottom[0] = "cc_ship_bt";
// run slider procedure to create and connect sliders:
cm_mySlider (" Top Stretch",-1,1,($pcube1[0] + ".ty"),0,"mySlider1");
cm_mySlider (" Bottom Stretch",-1,1,($ccbottom[0] + ".ty"),0,"mySlider2");
showWindow;
I'm not sure why you're storing them in arrays either. It could just be $pcube1 = "cc_ship_top"; $ccbottom = "cc_ship_bt"; , then wherever you have the [0] you remove it in the rest of your code.
Let me know if you have any questions!
duongy
09-09-2010, 02:21 AM
Thanks everyone for your replies I have amended the problem all is well in my world haha :) :bow