Issue
I want my WorkPlane from my model to be visible in my drawing, how can I achieve this through API?
Solution
If the model is a Part, it is pretty straightforward: you just have to retrieve the relevant WorkPlane object from the PartComponentDefinition and use the DrawingView.SetVisibility method passing this object.
If the model is an Assembly, then you first have to retrieve the WorkPlane object from the corresponding occurrence Definition and create a WorkPlaneProxy in the top level Assembly. Once it is done use again DrawingView.SetVisibility method passing the proxy object.
Here are the samples that illustrate the two situations:
Public Sub SetWorkPlaneVisibilityFromPart()
' assume we have had Inventor application
' _InvApplication
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = _InvApplication.ActiveDocument
'Get referenced Part document
Dim oPart As PartDocument
oPart = oDrawingDoc.ReferencedDocuments(1)
Dim oPartCompDef As PartComponentDefinition
oPartCompDef = oPart.ComponentDefinition
'Get YZ WorkPlane, suppose it's perpendicular to the view
Dim oWP As WorkPlane
oWP = oPartCompDef.WorkPlanes.Item("YZ Plane")
'Set visibility
Call oDrawingDoc.Sheets(1).DrawingViews(1).
SetVisibility(oWP, True)
End Sub
Public Sub SetWorkPlaneVisibilityFromAsm()
' assume we have had Inventor application
' _InvApplication
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = _InvApplication.ActiveDocument
'Get referenced Assembly document
Dim oAsm As AssemblyDocument
oAsm = oDrawingDoc.ReferencedDocuments(1)
'Get first occurrence, suppose it's a Part
Dim oOcc As ComponentOccurrence
oOcc = oAsm.ComponentDefinition.Occurrences(1)
Dim oPartCompDef As PartComponentDefinition
oPartCompDef = oOcc.Definition
'Get YZ WorkPlane, suppose it's perpendicular to the view
Dim oWP As WorkPlane
oWP = oPartCompDef.WorkPlanes.Item("YZ Plane")
'Create proxy object
Dim oWPpx As WorkPlaneProxy
Call oOcc.CreateGeometryProxy(oWP, oWPpx)
'Set visibility
Call oDrawingDoc.Sheets(1).DrawingViews(1).
SetVisibility(oWPpx, True)
End Sub