Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

NoneType error when using SelectionCommandInput

Message 1 of 3
769 Views, 2 Replies

NoneType error when using SelectionCommandInput



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):
    def notify(self, args):
            global fileButtonPressed
            command = args.firingEvent.sender
            cmdInput = args.input
            inputs = command.commandInputs    
            if == inputs.itemById(commandId + '_fileButton').id:
                fileButtonPressed = True
            elif == 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
            if ui:


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,



Message 2 of 3
in reply to: dylan.k.scott

It's difficult to say what the problem is with the code you've posted here.  I would suggest debugging your add-in and putting a break point on the messageBox line.  Once you've hit that break point using the Console window and enter "bodySelected".  It will display the type of the object you have.  Actually it will probably return nothing indicating that it's None which most likely means that the cast failed.  In the Console window enter "selectionIn.selection(0).entity" to see what the entity type really is.  I'm guessing that the settings you have for the selection input aren't set correctly to pick and Occurrence.

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3
in reply to: ekinsb

Hello Brian,


Thanks for the very quick reply, I wasn't certain exactly what portions of my code to post so I went with a minimal set -- fortunately for me you solved my problem with your guess that I had set an inappropriate selection filter and as such the cast wasn't working -- I have fixed this and it now works as expected.


Thanks again,



Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th

Autodesk Design & Make Report