MEL How-To #16 | ||
| ||
How do I hook up a slider to an attribute so that it updates in real time?There are two ways to do this. Method #1: Use the ‘ // Create a sphere for this example string $sphereA[] = `polySphere -r 10 -sx 16 -sy 8 -ax 0 1 0 -tx 1 -ch 1`; string $sphere = $sphereA[0]; // Our highly complex custom UI if ( `window -exists myWindow` ) deleteUI -window myWindow; window -title "connectControl" myWindow; string $form = `formLayout`; // Create a slider string $label = `text -label "Sphere rotateY" -align "right"`; string $field = `floatField -min 0.0 -max 360.0 -precision 2`; string $slider = `floatSlider -min 0.0 -max 360.0`; // Connect the sphere's Y rotation to the controls connectControl $field ( $sphere + ".rotateY" ); connectControl $slider ( $sphere + ".rotateY" ); // Edit the formLayout formLayout -e -af $label top 6 -af $label left 2 -af $field top 2 -ac $field left 4 $label -af $slider top 2 -ac $slider left 2 $field -af $slider right 2 $form; showWindow; Advantage: Since each control is connected individually it provides complete control over layout of the UI. It's possible to layout the controls with the label on top of the field/slider combo, or with the slider on a line by itself. Disadvantage: No visual indication when the attribute is driven by an animCurve (eg. orange shading) and no RMB menu offering ‘ Method #2: Use ‘ string $sphereA[] = `polySphere -r 10 -sx 16 -sy 8 -ax 0 1 0 -tx 1 -ch 1`; string $sphere = $sphereA[0]; // Our highly complex custom UI if ( `window -exists myWindow` ) deleteUI -window myWindow; window -title "attrFieldSliderGrp" myWindow; columnLayout -adjustableColumn true; // Create a slider string $slider = `attrFieldSliderGrp -label "Sphere rotateY" -adjustableColumn 3 -columnAlign 1 "right" -columnWidth 1 84 -columnWidth 4 1 -min 0.0 -max 360.0 -at ( $sphere + ".rotateY" )`; showWindow; Advantage: Keyframe feedback - field shades in orange if an animCurve is driving the attribute, gray if it's locked, etc. Disadvantage: Minimal layout control. You can tweak the sizes of each group element a bit, but you're stuck with everything on one line, and stuck with two label fields that, unless coerced otherwise, waste a lot of UI space. Which method to use depends on which is more important to you: Better layout control, or more complete feedback. Most animators will pressure you for the latter, so if you're creating the UI for someone else you're best-advised to sacrifice some screen real-estate for the more standard controls. Some tips for optimizing the layout of the ‘
| ||
Copyright ©2005 by Bryan Ewert, maya@ewertb.com Maya is a Registered Trademark of Alias |