ValueCommandInput expression not updating until value read

ValueCommandInput expression not updating until value read

debreuil
Participant Participant
671 Views
4 Replies
Message 1 of 5

ValueCommandInput expression not updating until value read

debreuil
Participant
Participant

It seems the expression of a ValueCommandInput is stale until the value is read. This also may be affecting the keyboard events while typing in a text box (the return key doesn't seem to fire unless the value is read in my code, not certain that hasn't always been the case though, or a bug in my code that this workaround happened to fix).

 

This may be a regression with the latest version? Not sure, but it is a new issue in my code, and I don't think I've changed that area. Also this may be new known behaviour, just documenting it here in case it is useful.

 

Toggling commenting in the two examples in the changed handler should show the difference.

 

import adsk.core, adsk.fusion, traceback

_commandId = 'Test'
_handlers = []

class CommandInputChangedHandler(adsk.core.InputChangedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, eventArgs):
        eventId = eventArgs.input.id
        if eventId == "TestInput":
            # Error case: type in 1234, result of expression is 0mm, 1mm, 12mm, 123mm
            print(eventArgs.input.expression)

            # Working case: type in 1234, result of expression is 1 mm, 12 mm, 123 mm, 1234 mm
            # xx = eventArgs.input.value # seems to trigger expression evaluation
            # print(eventArgs.input.expression)

            # Note: In all cases key events don't fire while typing (unless pressing enter with invalid input)
            # ** Not sure if this is new, I've only been checking for EnterKeyCode and ReturnKeyCode in text edits, but those had stopped working.

class KeyHandler(adsk.core.KeyboardEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, eventArgs:adsk.core.KeyboardEventArgs):
        print(str(eventArgs.keyCode))

class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, eventArgs):
        cmd = eventArgs.command

        onInputChanged = CommandInputChangedHandler()
        cmd.inputChanged.add(onInputChanged)
        _handlers.append(onInputChanged)    

        onKeyUp = KeyHandler()
        cmd.keyUp.add(onKeyUp)
        _handlers.append(onKeyUp)     

        inputs = cmd.commandInputs
        val = adsk.core.ValueInput.createByReal(0)
        valueInput = inputs.addValueInput('TestInput', 'Value', 'mm', val)
        pass

def run(context):
    _app = adsk.core.Application.get()
    _ui = _app.userInterface

    commandDef = _ui.commandDefinitions.itemById(_commandId)
    if commandDef:
        commandDef.deleteMe()
    commandDef = _ui.commandDefinitions.addButtonDefinition(_commandId, _commandId, _commandId)

    onCreated = CommandCreatedHandler()
    commandDef.commandCreated.add(onCreated)
    _handlers.append(onCreated)
    commandDef.execute()

    adsk.autoTerminate(False)

 

Accepted solutions (1)
672 Views
4 Replies
Replies (4)
Message 2 of 5

mikko.husari
Enthusiast
Enthusiast

We are also having trouble with this, our custom parameter dialogs are not working properly any more.

 

Our codebase has not changed in six months and now it seems that "changedInput.expression" holds the previous value, instead of current value. Any idea on possible fixes?

0 Likes
Message 3 of 5

mikko.husari
Enthusiast
Enthusiast

Thanks @debreuil . It seems to "fix" our issue as well.

 

Adding 'test = changedInput.value' BEFORE 'parameter.expression = changedInput.expression' makes things "normal" again.

 
Message 4 of 5

mikko.husari
Enthusiast
Enthusiast

Are we supposed to leave this workaround as a permanent fix? Helloo!

0 Likes
Message 5 of 5

goyals
Autodesk
Autodesk
Accepted solution

This issue is resolved and fix will be available as part of Fusion next update. Thanks.



Shyam Goyal
Sr. Software Dev. Manager