I tried to make a sample script for this but I cannot seem to get it to work, what have I done wrong here?
ui.messageBox('Test0') is not even triggering here is what i have so far:
import adsk.core, adsk.fusion, adsk.cam
import traceback
handlers = [] # This is where we will keep our event handlers
app = adsk.core.Application.get()
ui = app.userInterface
def run(context):
try:
# Create a command definition.
cmdDef = ui.commandDefinitions.itemById('SelectionFilter')
if not cmdDef:
cmdDef = ui.commandDefinitions.addButtonDefinition('SelectionFilter', 'Selection Filter', 'Creates a selection filter for CAM entities')
# Connect to the command created event.
cmdCreated = CommandCreatedHandler()
cmdDef.commandCreated.add(cmdCreated)
handlers.append(cmdCreated)
# Execute the command.
cmdDef.execute()
# Prevent this module from being terminated when the script returns, because we are waiting for event handlers to fire.
adsk.autoTerminate(False)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
# Get the command.
cmd:adsk.core.Command = args.command
# Get the CommandInputs collection to create new command inputs.
inputs = cmd.commandInputs
# Create a text box input.
textBoxInput = inputs.addTextBoxCommandInput('myTextBox', 'Enter Text', '', 1, False)
textBoxInput.text = 'Default Text'
# Connect to the validateInputs event.
onValidateInputs = ValidateInputsHandler()
cmd.validateInputs.add(onValidateInputs)
handlers.append(onValidateInputs)
# Connect to the execute event.
onExecute = ExecuteHandler()
cmd.execute.add(onExecute)
handlers.append(onExecute)
# Connect to the preSelect event.
onPreSelect = PreSelectHandler()
cmd.preSelect.add(onPreSelect)
handlers.append(onPreSelect)
except:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
selectedOperationName = ''
class PreSelectHandler(adsk.core.SelectionEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
global selectedOperationName
ui.messageBox('Test0')
try:
# Get the selection.
selection = args.selection
# Check if the selected entity is a Operation
if isinstance(selection.entity, adsk.cam.Operation):
args.isSelectable = True
# Store the name of the selected operation.
selectedOperationName = selection.entity.name
else:
args.isSelectable = False
except:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
class ValidateInputsHandler(adsk.core.ValidateInputsEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
global selectedOperationName
try:
#ui.messageBox("Test2")
# Get the command.
cmd = args.firingEvent.sender
# Get the CommandInputs collection.
inputs = cmd.commandInputs
# Get the text box input.
textBoxInput = inputs.itemById('myTextBox')
# Set the text of the text box to the name of the selected operation.
textBoxInput.text = selectedOperationName
except:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Event handler for the execute event.
class ExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
pass
ui.messageBox("Test3")