I have an assembly with parts below it that I need to get their sketches. I tried to combine two bits of code I've found the one mentioned and to recursively navigate the assembly to find the sketches. It seems to run without errors, and through a message box I can verify I have the correct view & correct sketch I want to make visible I am unsure why it is not showing up. Any help would be appreciated, it seems in the video above by Curtis he was managing to make sketches show from an assembly.
Thanks!
Sub Main()
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisDoc.Document
Dim oView As DrawingView
Dim oViews As DrawingViews
Dim oAssm As AssemblyDocument
Dim Occurrences As ComponentOccurrences
Dim oSheets As Sheets
oSheets = oDrawingDoc.Sheets
For Each oSheet In oSheets
oViews = oSheet.DrawingViews
For Each oView In oViews
If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = kAssemblyDocumentObject Then
Dim RefDoc As AssemblyDocument
RefDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
'recurse all components in assembly referenced by view
Call recurseOccurrences(RefDoc.ComponentDefinition.Occurrences,oView)
End If
Next
Next
End Sub
Sub recurseOccurrences(Occurrences As ComponentOccurrences,oView As DrawingView)'oView As DrawingView
Dim Occurrence As ComponentOccurrence
For Each Occurrence In Occurrences
If Occurrence.DefinitionDocumentType = kAssemblyDocumentObject Then
'found assembly, find subparts
Call recurseOccurrences(Occurrence.SubOccurrences,oView)
ElseIf Occurrence.DefinitionDocumentType = kPartDocumentObject And InStr(LCase(Occurrence.Name), "tf_sk") Then
If oView.ParentView Is Nothing Then
Exit Sub
End If
Dim oGenericComponentDefinition As PartComponentDefinition
oGenericComponentDefinition = Occurrence.definition
Dim oSketch As Sketch
For Each oSketch In oGenericComponentDefinition.Sketches
oView.SetVisibility(oSketch, True)
MsgBox( oSketch.Name )
Next
End If
Next
End Sub