Home Coding, Scripting, Shaders

(MEL) Reset Value of floatSlderGrp?

polycounter lvl 16
Offline / Send Message
onionhead_o polycounter lvl 16
        float $CBVal = `getAttr ($operation[1] + ".fraction")`;
        floatSliderGrp -label "Corner Bevel " -field true -adjustableColumn 3
        -minValue 0 -maxValue 1 -value $CBVal -precision 3 -cc ("updateValues(\""+$operation[1]+"\", \"floatCtrl1\")") floatCtrl1;
        popupMenu -parent floatCtrl1 cornerResetPopup;
        menuItem -label "Reset" -command "floatSliderGrp -edit -value ($CBVal) floatCtrl1;";

for some reason when right click the menu item to reset. It says "$CBVal" is an undeclared variable. when i clearly declared it at the start of the code.







Replies

  • Eric Chadwick
    Options
    Offline / Send Message
    Yuck, code blocks do indeed seem to be borked. Only way I got it to work:
    1. Toggle HTML view
    2. Paste your code
    3. Disable HTML view
    4. Select code
    5. Format > Code
    That's certainly not optimal. I'll dig further.
    float $CBVal = `getAttr ($operation[1] + ".fraction")`;
    floatSliderGrp -label "Corner Bevel " -field true -adjustableColumn 3
    -minValue 0 -maxValue 1 -value $CBVal -precision 3 -cc ("updateValues(\""+$operation[1]+"\", \"floatCtrl1\")") floatCtrl1;
    popupMenu -parent floatCtrl1 cornerResetPopup;
    menuItem -label "Reset" -command "floatSliderGrp -edit -value ($CBVal) floatCtrl1;";
    
  • Deadly Nightshade
    Options
    Offline / Send Message
    Deadly Nightshade polycounter lvl 10
    Spelling error?
    Scope error?
    If neither: Have you confirmed that you actually get a float value returned from getAttr?

    Either way you should put the code for resetting the UI control (floatSliderGrp) in a separate function and then call that function (cc flag) instead of having everything in the same place. Try and do as few things as possible within one scope (function, for loop, whatever) - that is a good practice to do for most code-related things. If something is too complex - move it to a separate function. It's easier to maintain as well.
  • onionhead_o
    Options
    Offline / Send Message
    onionhead_o polycounter lvl 16
    thanks Nightshade, Ill take a another look at the code
Sign In or Register to comment.