Listing object attributes

Listing object attributes

Anonymous
Not applicable
1,158 Views
5 Replies
Message 1 of 6

Listing object attributes

Anonymous
Not applicable

Fairly new to Python. Definitely new to Fusion and Spyder. Trying to get more familiar with the object model. 

 

How can I get a list of attributes for objects in the API Object Model Hierarchy? 

So far tried variations on 

 

>>> app = adsk.core.Application.get()
>>> app.UserInterface.CommandDefinitions.ComandDefinition.CommandCreatedEvent.Command.CommandInputs.ImageCommandInput.dir()

 

Not very successfull 😞

 

Any suggestions for better way handle this task are much appreciated. 

 

0 Likes
Accepted solutions (1)
1,159 Views
5 Replies
Replies (5)
Message 2 of 6

KrisKaplan
Autodesk
Autodesk
Accepted solution

I think what you are looking for is:

dir(adsk.core.ImageCommandInput)

This will just list the attributes of the class, but since there are no significant instance attributes that are not also class attributes, this should be all you need.  However, this will include a lot of 'implementation detail' attributes that you likely want to ignore, and these all start with an underscore.  So you could use a list comprehension to filter these out.

[k for k in dir(adsk.core.ImageCommandInput) if not k.startswith('_')]

Of course, this just lists the key names of the attributes.  If you want these formattted with the docstrings associated with them, then you would use 'help' instead of 'dir'.

help(adsk.core.ImageCommandInput)

Of course, if your goal is to get more familiar with the object model, I would probably recomend using the online documentation in the Programming Interface topic in the Fusion 360 Help.  But if you do want to dynamically use dir or help in the Python interpreter at runtime, I would recomend using the Python text command window in Fusion.  Use the File-->View-->Show TextCommands menu command to display the command window, and make sure the 'Py' radio button is enabled.

 

Kris



Kris Kaplan
Message 3 of 6

Anonymous
Not applicable
Thank you. Looking through online documentation now. "Show TextCommands" is an awesome feature. Hacking onward!
0 Likes
Message 4 of 6

Anonymous
Not applicable

Could you give an example on how to get a list of attributes of UserInterface.ToolbarPanelList ?

 

Would ideally like to figure out toolbar naming schema so I can programmatically switch between them using 

ui.allToolbarPanels.itemById() method

 

 

 

0 Likes
Message 5 of 6

ekinsb
Alumni
Alumni

I believe you're wanting to know the names of the various UI elements so you can find them using the itemByName methods.  You need to use the API to query Fusion at runtime to find out what's available in the UI.  There's a sample program in the API help that does this and writes out the entire UI into a text file.

 

http://help.autodesk.com/view/NINVFUS/ENU/?guid=GUID-d2b85a7e-fd08-11e4-9e07-3417ebd3d5be

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 6 of 6

Anonymous
Not applicable

Thank you Brian. 

 

This sheds light on the matter. I just wanted to walk up and down the hierarchy of objects exposed by the API. Looking at the code makes perfect sense and gives me an ability to list members of arrays from Text Commands terminal. 

 

My one suggestion would be to clean up capitalization in the http://help.autodesk.com/cloudhelp/ENU/Fusion-360-API/images/Fusion.pdf 

 

For example --> "Application::Data" is actually lower case "data" 

If there's an official bug report area will def file. 

If this is Python specific, appologize in advance for my ignorance. 

 

Best and Thank you again

0 Likes