include with API a work plane from model inside the drawing

By Xiaodong Liang

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%">&#160;&#160;&#160; </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%">&#160;&#160;&#160; oDrawingDoc = _InvApplication.ActiveDocument</span></p>    <p style="margin: 0px"><span style="line-height: 140%">&#160;&#160;&#160; </span><span style="line-height: 140%;color: green">'Get referenced Part document</span></p>    <p style="margin: 0px"><span style="line-height: 140%">&#160;&#160;&#160; </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%">&#160;&#160;&#160; oPart = oDrawingDoc.ReferencedDocuments(1)</span></p>    <p style="margin: 0px"><span style="line-height: 140%">&#160;&#160;&#160; </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%">&#160;&#160;&#160; oPartCompDef = oPart.ComponentDefinition</span></p>    <p style="margin: 0px"><span style="line-height: 140%">&#160;&#160;&#160; </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%">&#160;&#160;&#160; </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%">&#160;&#160;&#160; oWP = oPartCompDef.WorkPlanes.Item(</span><span style="line-height: 140%;color: #a31515">&quot;YZ Plane&quot;</span><span style="line-height: 140%">)</span></p>    <p style="margin: 0px"><span style="line-height: 140%">&#160;&#160;&#160; </span><span style="line-height: 140%;color: green">'Set visibility</span></p>    <p style="margin: 0px"><span style="line-height: 140%">&#160;&#160;&#160; </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%">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 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()             &apos; assume we have had Inventor application        &apos;  _InvApplication             Dim oDrawingDoc As DrawingDocument        oDrawingDoc = _InvApplication.ActiveDocument        &apos;Get referenced Assembly document        Dim oAsm As AssemblyDocument        oAsm = oDrawingDoc.ReferencedDocuments(1)        &apos;Get first occurrence, suppose it&apos;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


Comments

One response to “include with API a work plane from model inside the drawing”

  1. I’ve got a syntax error if I use this rule for my assembly drawing

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading