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: 

Getting the component that contains an occurrence?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
JesusFreke
559 Views, 3 Replies

Getting the component that contains an occurrence?

I can't seem to find any good way to find the component that contains an occurrence. The only relevant thing I see is Occurrence.fullPathName, and I guess you could parse the names and traverse the Occurrence tree.. but it seems like there's got to be a better way? Is this just something that's currently missing in the API, or am I missing something?

 

 

3 REPLIES 3
Message 2 of 4
JesusFreke
in reply to: JesusFreke

Actually, I just realized it could be either an Occurrence or a Component that contains an occurrence, e.g. if it's an Occurrence from Occurrence.childOccurrence. But in any case, it seems like it would be useful to be able to traverse up the tree, as well as down. 

Message 3 of 4
p.seem
in reply to: JesusFreke

I think the property you're looking for is assemblyContext.

That will return the occurence that 'contains' the occurrence (if there is one), from which you can access the component.

Message 4 of 4
JesusFreke
in reply to: p.seem

Ah, I had missed that, thanks. It doesn't look like you can use assemblyContext to get the component that contains an occurrence though.

 

e.g.

     

parent_occurrence = root().occurrences.addNewComponent(adsk.core.Matrix3D.create())
mybox = box(2, 2, 3, name="mybox") # creates a new component under root and adds a box body created from TemporaryBrepManager
mybox.moveToComponent(parent_occurrence)

print(mybox.assemblyContext)

----

None

 

But in any case, I think I use occurrence.createForAssemblyOccurrence whenever I create a new component, and return that occurrence instead of returning the "raw" occurrence that doesn't have an assembly context. That way I'll only be dealing with occurrences with an assemblyContext, so I can properly traverse up the tree when needed. Although, I guess I can't use that trick for occurrences contained by the root component. But I can just treat assemblyContext = None as a special case, and know that the container is root in that case.

 

    

parent_occurrence = root().occurrences.addNewComponent(adsk.core.Matrix3D.create())
mybox = box(2, 2, 3, name="mybox")  # creates a new component under root and adds a box body created from TemporaryBrepManager
mybox.moveToComponent(parent_occurrence)
mybox = mybox.createForAssemblyContext(parent_occurrence)

print(mybox.assemblyContext)

----

<adsk.fusion.Occurrence; proxy of <Swig Object of type 'std::vector< adsk::core::Ptr< adsk::fusion::Occurrence > >::value_type *' at 0x0000022E0FA854B0> >

 

I'd still be interested to know if there's a good way to find the containing component of the "native" occurrence, but I think the above workaround should be workable at least.

 

 

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