- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm pretty new to scripting within Fusion and as such am sure there is a simple explanation for the error I am receiving. I am attempting to, utilizing a Command, get a user to select a component within a given design. I then want to use this component selection and its associated attributes (name) within the script to do some additional work (transformations, etc.). I am currently using the InputChangedEventHandler to handle this selection based event and have everything working up until the point where I attempt to get the selected components name -- at which point I get an AttributeError: 'NoneType' object has no attribute 'name' error. The component I am selecting is not the root component of the design, but I am unsure if this matters in this scenario.
My InputChangedHandler is as follows:
class MyCommandInputChangedHandler(adsk.core.InputChangedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
global fileButtonPressed
command = args.firingEvent.sender
cmdInput = args.input
inputs = command.commandInputs
if cmdInput.id == inputs.itemById(commandId + '_fileButton').id:
fileButtonPressed = True
elif cmdInput.id == inputs.itemById(commandId + '_bodySelector').id:
selectionIn = adsk.core.SelectionCommandInput.cast(cmdInput)
if selectionIn.selectionCount == 1:
bodySelected = adsk.fusion.Occurrence.cast(selectionIn.selection(0).entity)
# simple check to see if the appropriate body is selected
ui.messageBox(bodySelected.name)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
I should note that everything executes as expected up until I attempt to retrieve the name attribute of the selected component
Thanks in advance for any help,
Dylan
Solved! Go to Solution.
