Get level of active edit document occurrence in parent assembly

Get level of active edit document occurrence in parent assembly

matt_jlt
Collaborator Collaborator
385 Views
2 Replies
Message 1 of 3

Get level of active edit document occurrence in parent assembly

matt_jlt
Collaborator
Collaborator

I am  to determine how deep into the assembly occurrence structure that an "active edit document" is which means i need to get its occurrence in the parent assembly.

 

When i get the "active edit document", it is a document and not an occurrence of the parent occurrence. I don't know how i can get its relevant occurrence.

 

I would try using the "active edit object" but the user could also be editing an assembly level sketch or some other feature and it would be problematic.

 

Does anyone have a solution for this?

 

Thanks, Matt.

 

Example

 

Assembly A (Parent)

      Assembly B:1 (Child assembly occurrence) - i could be editing this assembly

      Assembly C:1 (Child assembly occurrence)

             Assembly D:1 (Child assembly occurrence) - i could also be editing this assembly

0 Likes
Accepted solutions (1)
386 Views
2 Replies
Replies (2)
Message 2 of 3

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @matt_jlt . I hope I understood you correctly. This is an example of iLogic code that can retrieve the level of an actively edited document in an assembly:

Dim oInvApp As Inventor.Application = ThisApplication
Dim oADoc As AssemblyDocument = TryCast(oInvApp.ActiveDocument, AssemblyDocument)
If oADoc Is Nothing Then Exit Sub
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oEditOcc As ComponentOccurrence = oADef.ActiveOccurrence
If oEditOcc Is Nothing Then Exit Sub
Dim oParentOcc As ComponentOccurrence
MessageBox.Show(oEditOcc.Name, "Avtive Edit Occurrence:")
Dim iLevel As Integer = 1
Do
	oParentOcc = oEditOcc.ParentOccurrence
	MessageBox.Show(oParentOcc.Name, "Parent Occurrence - Level " & iLevel & ":")
	iLevel += 1
	oEditOcc = oParentOcc
Loop While oEditOcc.ParentOccurrence Isnot Nothing
MessageBox.Show(oADoc.DisplayName, "Top Level Document - Level " & iLevel & ":")

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 3

matt_jlt
Collaborator
Collaborator

That's exactly what i was after, thankyou. I didnt know there was an "ActiveOccurrence" object.

 

Thanks again, Matt.

0 Likes