- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'd like to create a persistent display to show some numbers derived from the currently selected body's mass. How can I determine when something new is selected?
My approach thus far has been to try to add a handler to the select command, but I'm having trouble figuring out how to do this. This is my current attempt, added to my add-in's startup code:
def hook_into_select_command(args: adsk.core.ApplicationCommandEventArgs):
futil.log("command starting.")
if args.commandId != "SelectCommand":
futil.log(f"was {args.commandId}")
return
futil.log("Select command starting. Attempting to do weird stuff.")
def tmp(args: adsk.core.CommandCreatedEventArgs):
futil.log(f"Event: {args.firingEvent.name} Command: {args.command}")
futil.add_handler(args.command.execute, do_things_on_select_change)
futil.add_handler(
args.commandDefinition.commandCreated, tmp, local_handlers=local_handlers
)
futil.log("set handler")
futil.add_handler(ui.commandStarting, hook_into_select_command)
I can get the log messages to print when the select command is in use, but I haven't figured out how to get code to run when something is actually selected. My idea was to add a handler to the select command's execute event, but I can't figure out how to get access to the command itself. The inner `tmp` function I defined on line 9 never fires.
Any advice? Is there a better approach I could be taking?
Solved! Go to Solution.