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: 

simple selection script

Message 1 of 3
1411 Views, 2 Replies

simple selection script



I'm really struggling here. All I want to do is to select 1 solidbody only and then display some of the brep/component/whatever properties of that selected solid body.


All the examples are really complicated and involve loops and other forms of selection and as I am new to Python, the Fusion API and coding in general, I am really struggling with the concept that almost everything is an object in python.


I've spent hours going thru code trying to understand it and see how one thing links to another.


Even getting a basic input interface is very confusing. 


I can create a messagebox and I can modify the command input sample code and modify the inputs in there (but only with the tabbed interface)


There are no very simple sample scripts that show how to do something really simple, without all the extra validation and a billion other options that you might want in the future.


I don't want to check what language, I don't want to use loops, I don't want multiple selection types, I don't want tabs, I don't want tables, I don't want to check if the user entered the correct value.


I don't want any of that right now. Because it confuses the learning process. I can't clearly see how one thing leads to another.


I would want to have all that stuff at a later stage as I build my script, but I'm finding to just get my head around everything and even be slightly confident with what I am writing that all that stuff is just getting in the way and it's really taking all the fun out of it.


A lot of these provided samples aren't made for absolute beginners, they are for seasoned programmers.


I watched a bunch of youtube videos teaching basic python and while most of what they were doing was just printing answers, it was infinitely more simple and straight forward to follow and fun.


I'm sorry if this sounds whiny, I've spent 3 full days trying to figure it all out myself and have hit the wall. I'm not a programmer, but I do have a little experience and I was excited to commit to learning programming and apply it to my design background. 


Any help would be greatly appreciated. Thanks.

Message 2 of 3
in reply to: mjobson32CFL

I think what you're asking for, as far as documentation, sounds completely reasonable and would benefit a lot of other people too. We have some new material that is hopefully coming out soon, but with documentation there's always room for improvement.


To address your specific question in this case.  What you've been looking at is the creation of a command that contains a SelectionCommandInput to get a selection.  This is reasonably complicated to implement, although it is also very powerful.  However, you don't have to go through all of that to do a simple selection and in the majority of my simpler scripts I don't create an add-in or a command and use some simpler ways to get the input I need.  It's not as clean as a command but much quicker to implement and if it's only me that's using it, I don't really care about the UI.


The UserInterface object supports a few simple functions to get or display input to the user.  You already mentioned the messageBox method, but there are also the inputBox and selectEntity methods, which are both demonstrates in the simple script below that prompts the user to select a face, enter a diameter, and it creates a hole at the centroid of the selected face.


import adsk.core, adsk.fusion, traceback

_app = adsk.core.Application.cast(None)
_ui  = adsk.core.UserInterface.cast(None)

def run(context):
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        # Have a face selected.
        faceSel = _ui.selectEntity('Select a face', 'Faces')
        if faceSel:
            face = adsk.fusion.BRepFace.cast(faceSel.entity)
            # Get the hole diameter.
            (diam, cancelled) = _ui.inputBox('Enter hole diameter', 'Hole Diameter', '0.5 in')
            if cancelled:
            # Create the hole.
            des = adsk.fusion.Design.cast(_app.activeProduct)
            root = des.rootComponent
            holeInput = root.features.holeFeatures.createSimpleInput(adsk.core.ValueInput.createByString(diam))
            holeInput.setPositionByPoint(face, face.centroid)
            hole = root.features.holeFeatures.add(holeInput)
        if _ui:





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

Thanks Brian,


I managed to figure out how to simplify (totally butcher) the SelectionCommandInput up to a point, but still need to figure out a few more things.


What you sent here was a much simpler way to do it; which is really cool to know and will help me in my travels.


Really appreciate all the support you provide on here.



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