Message 1 of 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Slowly progressing toward my first addin creation.
for now I have a single commandInputs, to select a sketchLine, and this is working as expected. But I want this selected line to be a construction line, so I am attempting to check if this is he case inside a ValidateInputs event, but does not seem to work, meaning a regular line is OK too...
Here is the code involved:
# Event handler for the commandCreated event.
class onCommandCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
# Verify that a sketch is active.
app = adsk.core.Application.get()
if app.activeEditObject.objectType != adsk.fusion.Sketch.classType():
ui = app.userInterface
ui.messageBox('A sketch must be active for this command.')
return False
eventArgs = adsk.core.CommandCreatedEventArgs.cast(args)
#Get the command
cmd = eventArgs.command
# Get the CommandInputs collection associated with the command.
inputs = cmd.commandInputs
constructionLine = inputs.addSelectionInput('constructionLineUniqueID','Select a Construction Line', 'The line you select will be the Chord of your Airfoil' )
constructionLine.addSelectionFilter('SketchLines')
# Connect to the execute event.
onExecute = SampleCommandExecuteHandler()
cmd.execute.add(onExecute)
handlers.append(onExecute)
# #Connect to the ValidateInputs Event
onValidate = SampleCommandValidateInputsHandler()
cmd.validateInputs.add(onValidate)
handlers.append(onValidate)
class SampleCommandValidateInputsHandler(adsk.core.ValidateInputsEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
eventArgs = adsk.core.ValidateInputsEventArgs.cast(args)
inputs = eventArgs.firingEvent.sender.commandInputs
selLine = inputs.itemById('constructionLineUniqueID')
if selLine.objectType == adsk.fusion.SketchLine.classType():
myLine = adsk.fusion.SketchLine.cast(selLine)
if myLine.isConstruction:
eventArgs.areInputsValid = True
return
else:
eventArgs.areInputsValid = False
return
Checking with the debugger, I can see the objectType for selLine is NOT sketchLine....Guess I have to find the way to make it so?
Solved! Go to Solution.

