Community
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.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Fusion 360 Python script - determine if an open document is an "Assembly or a Part"

1 REPLY 1
SOLVED
Reply
Message 1 of 2
isocam
144 Views, 1 Reply

Fusion 360 Python script - determine if an open document is an "Assembly or a Part"

Can anybody help?

 

Is it possible, using a Fusion 360 Python script to determine if an open document is a "Assembly or a Part"?

 

I am able to check if the open document is a drawing using:

 

if isinstance(doc,adsk.drawing.DrawingDocument):
ui.messageBox("DRAWING", 'Fusion 360', 0, 3)

 

But I need to know if the open document is an "Assembly" or a "Part"

 

Many thanks!!!!

 

Darren

 

Darren

1 REPLY 1
Message 2 of 2
BrianEkins
in reply to: isocam

Fusion is odd in that it doesn't differentiate between a part and assembly and in fact, you can easily create a weird hybrid design. Typically, parts just contain geometry and assemblies just contain instances of other assemblies and parts.

 

You also mentioned you want to determine if a document is an assembly or part. A document itself can contain multiple assemblies and parts, so it would only be a special case where the document is one or the other.

 

Here are some examples. You create a new document and in the top-level component (root component) you create a sketch and extrude it.  Using the API we can check to see that the Sketches collection obtained from the root component has a count greater than 0 and we can also check that the BRepBodies collection on the root component is greater than zero. Finally, we can check that the Occurrences collection of the root component is zero. This implies the root component is not an assembly and because there is only one root component per document, also infers the document is a part. You have to decide what constitutes a part. Maybe a part can contain only a sketch and doesn't have to have a body, or even a part can be empty and as long as it doesn't reference any other components it can be a part.

 

If you create a new document and then insert another document into it, the Occurrence collection of the root component will return a count of 1, which implies the root component and document now represent an assembly.

 

Because you can create multiple components within a single document, this logic can be done for every component, not just the root component. This means a document can contain both parts and assemblies. 

 

The weird case is where a component contains geometry that would make it a part but also has references to other components, which make it an assembly. This is possible but something you should avoid in your designs.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

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