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
<p style="margin: 0px"><span style="line-height: 140%">    </span><span style="line-height: 140%;color: blue">Dim</span><span style="line-height: 140%"> oDrawingDoc </span><span style="line-height: 140%;color: blue">As</span><span style="line-height: 140%"> </span><span style="line-height: 140%;color: #2b91af">DrawingDocument</span></p> <p style="margin: 0px"><span style="line-height: 140%">    oDrawingDoc = _InvApplication.ActiveDocument</span></p> <p style="margin: 0px"><span style="line-height: 140%">    </span><span style="line-height: 140%;color: green">'Get referenced Part document</span></p> <p style="margin: 0px"><span style="line-height: 140%">    </span><span style="line-height: 140%;color: blue">Dim</span><span style="line-height: 140%"> oPart </span><span style="line-height: 140%;color: blue">As</span><span style="line-height: 140%"> </span><span style="line-height: 140%;color: #2b91af">PartDocument</span></p> <p style="margin: 0px"><span style="line-height: 140%">    oPart = oDrawingDoc.ReferencedDocuments(1)</span></p> <p style="margin: 0px"><span style="line-height: 140%">    </span><span style="line-height: 140%;color: blue">Dim</span><span style="line-height: 140%"> oPartCompDef </span><span style="line-height: 140%;color: blue">As</span><span style="line-height: 140%"> </span><span style="line-height: 140%;color: #2b91af">PartComponentDefinition</span></p> <p style="margin: 0px"><span style="line-height: 140%">    oPartCompDef = oPart.ComponentDefinition</span></p> <p style="margin: 0px"><span style="line-height: 140%">    </span><span style="line-height: 140%;color: green">'Get YZ WorkPlane, suppose it's perpendicular to the view</span></p> <p style="margin: 0px"><span style="line-height: 140%">    </span><span style="line-height: 140%;color: blue">Dim</span><span style="line-height: 140%"> oWP </span><span style="line-height: 140%;color: blue">As</span><span style="line-height: 140%"> </span><span style="line-height: 140%;color: #2b91af">WorkPlane</span></p> <p style="margin: 0px"><span style="line-height: 140%">    oWP = oPartCompDef.WorkPlanes.Item(</span><span style="line-height: 140%;color: #a31515">"YZ Plane"</span><span style="line-height: 140%">)</span></p> <p style="margin: 0px"><span style="line-height: 140%">    </span><span style="line-height: 140%;color: green">'Set visibility</span></p> <p style="margin: 0px"><span style="line-height: 140%">    </span><span style="line-height: 140%;color: blue">Call</span><span style="line-height: 140%"> oDrawingDoc.Sheets(1).DrawingViews(1).</span></p> <p style="margin: 0px"><span style="line-height: 140%">                       SetVisibility</span><span style="line-height: 140%">(oWP, </span><span style="line-height: 140%;color: blue">True</span><span style="line-height: 140%">)</span></p> <p style="margin: 0px"><span style="line-height: 140%;color: blue">End</span><span style="line-height: 140%"> </span><span style="line-height: 140%;color: blue">Sub</span></p> <p style="margin: 0px"><span style="line-height: 140%;color: blue"></span></p> </div> <p></p> <p></p> <pre class="line-numbers"><code class="language-vbnet">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

Leave a Reply