Difference between revisions of "Snippet:Setting min/max values for command attributes"

From The Foundry MODO SDK wiki
Jump to: navigation, search
(Created page with "{{Snippet |summary=A mostly useless command for the sole purpose of illustrating how limiting the user input range for a command's float attribute inside can be achieved. |cod...")
 
 
Line 22: Line 22:
 
     def basic_Execute(self, msg, flags):
 
     def basic_Execute(self, msg, flags):
 
         '''
 
         '''
         The second argument to dyna_Float defines a default which is used if the  
+
         The second argument to dyna_Float defines a default which is set when the  
         attribute's value is not set.
+
         attribute's argument or value was not passed in.
 
         '''
 
         '''
 
         floatValue = self.dyna_Float(0, DEFAULTVALUE)
 
         floatValue = self.dyna_Float(0, DEFAULTVALUE)
 +
        lx.out(floatValue)
  
 
     def arg_UIHints(self, index, hints):
 
     def arg_UIHints(self, index, hints):

Latest revision as of 09:09, 1 September 2016

Description:

A mostly useless command for the sole purpose of illustrating how limiting the user input range for a command's float attribute inside can be achieved.

Code:

import lx
import lxifc
import lxu.command
 
DEFAULTVALUE = 0.0
 
class CmdMinMaxExample(lxu.command.BasicCommand):
    '''
    A mostly useless command for the sole purpose of illustrating how limiting the user input range 
    for a command's float attribute inside can be achieved.
    '''
 
    def __init__(self):
        lxu.command.BasicCommand.__init__(self)
        self.dyna_Add('units', lx.symbol.sTYPE_FLOAT)
 
    def cmd_Flags(self):
        return lx.symbol.fCMD_MODEL | lx.symbol.fCMD_UNDO
 
    def basic_Execute(self, msg, flags):
        '''
        The second argument to dyna_Float defines a default which is set when the 
        attribute's argument or value was not passed in.
        '''
        floatValue = self.dyna_Float(0, DEFAULTVALUE)
        lx.out(floatValue)
 
    def arg_UIHints(self, index, hints):
        '''
        We are being passed a UIHints object which we can manipulate
        '''
        if index == 0:
            hints.MinFloat(0.0)
            hints.MaxFloat(0.5)
 
    def cmd_DialogInit(self):
        '''
        Here we set initial values for the attributes as they appear in the UI dialog
        '''
        if not self.dyna_IsSet(0):
            self.attr_SetFlt(0, DEFAULTVALUE)
 
'''
After the command is blessed, type minmax into the command prompt. 
When changing the spinner, it won't let you go higher than 0.5 or lower than 0
Also when you pass a value and inspect the Event Log history you can see that the value has 
been clamped accordingly.
'''
lx.bless(CmdMinMaxExample, "minmax")