Message 1 of 9
Getting "Document" from "Occurrence"

Not applicable
11-14-2005
08:49 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have a typical problem: I know that there is enough code in the SDK and on this forum for traversing an Assembly using "Occurrences" and "SubOccurrences" , but I would like to know if it can be done differently. I would like to know if after getting a particular "Occurrence" I can convert it into an "Document" - If so how? To explain my point, I am putting some comments ('''' DIFFERENT WAY ) in the usual sample code below:
Public Sub AssemblyTraversal()
' Get the active document, assuming it's an assembly.
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
' Begin the assembly traversal.
Call TraverseAsm(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub
' The Level argument is used to control the amount of indent for the output.
Private Sub TraverseAsm(oOccurrences As ComponentOccurrences, Level As Integer)
' Iterate through the current list of occurrences.
Dim oOcc As ComponentOccurrence
For Each oOcc In oOccurrences
' Print the name of the current occurence.
Debug.Print Space(Level * 3) & oOcc.Name
'''' DIFFERENT WAY
' HOW Can one get Document Object out of the "oOcc " object here
' If the current occurrence is a subassembly then call this sub
' again passing in the collection for the current occurrence.
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call TraverseAsm(oOcc.SubOccurrences, Level + 1)
End If
Next
End Sub
I have a typical problem: I know that there is enough code in the SDK and on this forum for traversing an Assembly using "Occurrences" and "SubOccurrences" , but I would like to know if it can be done differently. I would like to know if after getting a particular "Occurrence" I can convert it into an "Document" - If so how? To explain my point, I am putting some comments ('''' DIFFERENT WAY ) in the usual sample code below:
Public Sub AssemblyTraversal()
' Get the active document, assuming it's an assembly.
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument
' Begin the assembly traversal.
Call TraverseAsm(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub
' The Level argument is used to control the amount of indent for the output.
Private Sub TraverseAsm(oOccurrences As ComponentOccurrences, Level As Integer)
' Iterate through the current list of occurrences.
Dim oOcc As ComponentOccurrence
For Each oOcc In oOccurrences
' Print the name of the current occurence.
Debug.Print Space(Level * 3) & oOcc.Name
'''' DIFFERENT WAY
' HOW Can one get Document Object out of the "oOcc " object here
' If the current occurrence is a subassembly then call this sub
' again passing in the collection for the current occurrence.
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call TraverseAsm(oOcc.SubOccurrences, Level + 1)
End If
Next
End Sub