Hi @Anonymous
Try this code. Define the name of the sketch at the first line, then when the code is running - pick the drawing view in which you want to set the sketch to visible.
The code has edits since first posted
Sub Main
Dim sketchName As String = "Sketch1" 'Name of sketch
Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select Drawing view")
If oView Is Nothing Then Exit Sub
Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
For Each oSketch As PlanarSketch In oDoc.ComponentDefinition.Sketches
If oSketch.Name = sketchName
oView.SetVisibility(oSketch, True)
End If
Next
For Each orefDoc As Document In oDoc.AllReferencedDocuments
If orefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject _
Or orefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
Try
Dim oSketch As PlanarSketch = orefDoc.ComponentDefinition.Sketches.Item(sketchName)
For Each oOcc As ComponentOccurrence In oDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(orefDoc)
Dim sketchToInclude = CreateSketchProxy(oOcc.OccurrencePath, oSketch.Name)
oView.SetVisibility(sketchToInclude, True)
Next
Catch
End Try
End If
Next
ElseIf oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
For Each oSketch As PlanarSketch In oDoc.ComponentDefinition.Sketches
If oSketch.Name = sketchName
oView.SetVisibility(oSketch, True)
End If
Next
End If
End Sub
Function CreateSketchProxy(oOccList As ComponentOccurrencesEnumerator, oSketchName As String) As Object
Dim oProx As Object
For i = oOccList.Count To 1 Step -1
If i = oOccList.Count
Call oOccList(i).CreateGeometryProxy(oOccList(i).Definition.Sketches.Item(oSketchName), oProx)
Else
Call oOccList(i).CreateGeometryProxy(oProx, oProx)
End If
Next
Return oProx
End Function