Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Set limit on inputvalues

1 REPLY 1
Reply
Message 1 of 2
theartezt
300 Views, 1 Reply

Set limit on inputvalues

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?

1 REPLY 1
Message 2 of 2
MichaelT_123
in reply to: theartezt

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report