Set limit on inputvalues

theartezt
Explorer
Explorer

Set limit on inputvalues

theartezt
Explorer
Explorer

Hi,

 

I'm looking for a solution where I can limit the input range of values. My goal is to rule out negative numbers and numbers higher than a set limit. For example: input is valid when between 10 and 100. Let's say someone tries 1000, it's not valid and an errormessage is displayed.

 

My ideas of doing this:

In the CommandValidateInputsHandler, but I can test on (e.g.) toplimit but not the lower limit at the same time.

 

Second idea: this must be done in the creation of the input as a isValidExpression.

 

What I've tried, but not seems to be working..

 

# Event handler for the validateInputs event.
class SampleCommandValidateInputsHandler(adsk.core.ValidateInputsEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            app = adsk.core.Application.get()
            ui  = app.userInterface     
            
            eventArgs = adsk.core.ValidateInputsEventArgs.cast(args)
            inputs = eventArgs.firingEvent.sender.commandInputs
            
            
            # Verify .
            scaleInput = inputs.itemById('scale')
            if 10 < scaleInput.value < 100 :
                eventArgs.areInputsValid = True
            else:
                scaleInput = inputs.itemById('value')
                if 10 < scaleInput.value < 100 :
                    eventArgs.areInputsValid = True
                else:    
                    eventArgs.areInputsValid = False
                    
            
        except:
            if ui:
                ui.messageBox('Failed ValidateInputsHandler:\n{}'.format(traceback.format_exc()))

 

 

 

 

Could you point me in the right direction?

0 Likes
Reply
300 Views
1 Reply
Reply (1)

MichaelT_123
Advisor
Advisor

Hi Mr. TheArterzt,

 

Consider :

 

class SampleCommandChangedInputsHandler(adsk.core.InputChangedEventHandler):
bla, bla bla,...
            if scaleInput.value < 10 :
                scaleInput.value = 10

bla, bla bla

Regards

MichaelT

MichaelT
0 Likes