Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)
Solved! Go to Solution.