<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SetIncludeStatus in DrawingView with SubAssembly in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/setincludestatus-in-drawingview-with-subassembly/m-p/9855109#M117855</link>
    <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2181124"&gt;@martin_winkler&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to include the plane from partfiles named "testfile.ipt" you could just traverse all LeafOccurrences in the assembly. I think this should be enough to get the result you want &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@B4D44A73814D7FC0D950DEDFACB97081/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Sub SetIncludeStatusFromAsm()
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet
    Dim oView As DrawingView
    Set oView = oSheet.DrawingViews(1)
    Dim oAsm As AssemblyDocument
    Set oAsm = oView.ReferencedDocumentDescriptor.ReferencedDocument
    Dim intWorkplane As Integer
    intWorkplane = 1
    Dim strFileName As String
    strFileName = "testfile.ipt"
    Dim oOcc As ComponentOccurrence
    Dim oDoc As Document
    For Each oOcc In oAsm.ComponentDefinition.Occurrences.AllLeafOccurrences
        Set oDoc = oOcc.ReferencedDocumentDescriptor.ReferencedDocument
        If Right(oDoc.FullFileName, Len(oDoc.FullFileName) - InStrRev(oDoc.FullFileName, "\")) = strFileName Then
            Dim oWP As WorkPlane
            Set oWP = oDoc.ComponentDefinition.WorkPlanes(intWorkplane)
            Dim oWPprox As WorkPlaneProxy
            Call oOcc.CreateGeometryProxy(oWP, oWPprox)
            Call oView.SetIncludeStatus(oWPprox, True)
        End If
    Next
End Sub&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Nov 2020 07:17:40 GMT</pubDate>
    <dc:creator>JhoelForshav</dc:creator>
    <dc:date>2020-11-09T07:17:40Z</dc:date>
    <item>
      <title>SetIncludeStatus in DrawingView with SubAssembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/setincludestatus-in-drawingview-with-subassembly/m-p/9852970#M117843</link>
      <description>&lt;P&gt;I want to set the IncludeStatus of Workplanes with the API for some parts or assemblies.&lt;/P&gt;
&lt;P&gt;In the first level of the referenced assembly this works fine.&lt;/P&gt;
&lt;P&gt;Then i use TraverseAssembly to do the same in second or deeper levels of the assembly.&lt;/P&gt;
&lt;P&gt;In this case i get an error in the TraverseAssembly in line:&lt;/P&gt;
&lt;P&gt;Call oSheet.DrawingViews(1).SetIncludeStatus(oWPpx, True)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="3DCS-GmbH_Samstag, 7. November 2020_21h00m02s_001_.jpg" style="width: 366px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/841602iFD8A7D1316F6B8B2/image-size/large?v=v2&amp;amp;px=999" role="button" title="3DCS-GmbH_Samstag, 7. November 2020_21h00m02s_001_.jpg" alt="3DCS-GmbH_Samstag, 7. November 2020_21h00m02s_001_.jpg" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code i wrote in VBA:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Public Sub SetIncludeStatusFromAsm()
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet
    Dim intWorkplane As Integer
    intWorkplane = 1 'YZ-Plane

    'Get referenced Assembly document
    Dim strFileName As String
    'File in which the workplane is to be included
    strFileName = "testfile.ipt" 'testfile.iam" 
    Dim oAsm As AssemblyDocument
    Set oAsm = oDrawDoc.ReferencedDocuments(1)
    Dim oCompDef As ComponentDefinition
    Dim oDoc As Document
    Dim oOcc As ComponentOccurrence
    Dim oOccs As ComponentOccurrences
    Set oOccs = oAsm.ComponentDefinition.Occurrences
    'Search for the strFileName occurence    
    For Each oOcc In oOccs
     Debug.Print (oOcc.Name)
      If FileNameFromPath(oOcc.ReferencedDocumentDescriptor.FullDocumentName) = strFileName Then
       Set oCompDef = oOcc.Definition
       Dim oWP As WorkPlane
       'Get YZ WorkPlane, suppose it's perpendicular to the view
       Set oWP = oCompDef.WorkPlanes.item(intWorkplane)
       'Create proxy object
       Dim oWPpx As WorkPlaneProxy
       Call oOcc.CreateGeometryProxy(oWP, oWPpx)
       'SetIncludeStatus
       Call oSheet.DrawingViews(1).SetIncludeStatus(oWPpx, True)
      Else
       If oOcc.Definition.Type = kAssemblyComponentDefinitionObject Then
         Call TraverseAssembly(oOcc.Definition.Occurrences, strFileName, intWorkplane, oSheet)
       End If
      End If
    Next
End Sub

Sub TraverseAssembly(Occurrences As ComponentOccurrences, strFileName As String, intWorkplane As Integer, oSheet As Sheet)
    ' Iterate through all of the occurrence in this collection.  This
    ' represents the occurrences at the top level of an assembly.
    Dim oOcc As ComponentOccurrence
    For Each oOcc In Occurrences
        Debug.Print (oOcc.Name) &amp;amp; " - " &amp;amp; FileNameFromPath(oOcc.ReferencedDocumentDescriptor.FullDocumentName)
        If FileNameFromPath(oOcc.ReferencedDocumentDescriptor.FullDocumentName) = strFileName Then
         Dim oCompDef As ComponentDefinition
         Set oCompDef = oOcc.Definition
         Dim oWP As WorkPlane
         'Get WorkPlane 1 (YZ), suppose it's perpendicular to the view
         Set oWP = oCompDef.WorkPlanes.item(intWorkplane)
            'Create proxy object
            Dim oWPpx As WorkPlaneProxy
            Call oOcc.CreateGeometryProxy(oWP, oWPpx)
            Call oSheet.DrawingViews(1).SetIncludeStatus(oWPpx, True)
        End If
        
        If oOcc.Definition.Type = kAssemblyComponentDefinitionObject Then
            Call TraverseAssembly(oOcc.SubOccurrences, strFileName, intWorkplane, oSheet)
        End If
    Next
End Sub

Public Function FileNameFromPathExt(strFullPath As String) As String
    FileNameFromPathExt = Right(strFullPath, Len(strFullPath) - InStrRev(strFullPath, "\"))
    FileNameFromPathExt = Left(FileNameFromPathExt, InStrRev(FileNameFromPathExt, ".") - 1)
End Function&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did anyone have an idea?&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 20:17:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/setincludestatus-in-drawingview-with-subassembly/m-p/9852970#M117843</guid>
      <dc:creator>martin_winkler</dc:creator>
      <dc:date>2020-11-07T20:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: SetIncludeStatus in DrawingView with SubAssembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/setincludestatus-in-drawingview-with-subassembly/m-p/9855109#M117855</link>
      <description>&lt;P&gt;Hi &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2181124"&gt;@martin_winkler&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to include the plane from partfiles named "testfile.ipt" you could just traverse all LeafOccurrences in the assembly. I think this should be enough to get the result you want &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@B4D44A73814D7FC0D950DEDFACB97081/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Sub SetIncludeStatusFromAsm()
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet
    Dim oView As DrawingView
    Set oView = oSheet.DrawingViews(1)
    Dim oAsm As AssemblyDocument
    Set oAsm = oView.ReferencedDocumentDescriptor.ReferencedDocument
    Dim intWorkplane As Integer
    intWorkplane = 1
    Dim strFileName As String
    strFileName = "testfile.ipt"
    Dim oOcc As ComponentOccurrence
    Dim oDoc As Document
    For Each oOcc In oAsm.ComponentDefinition.Occurrences.AllLeafOccurrences
        Set oDoc = oOcc.ReferencedDocumentDescriptor.ReferencedDocument
        If Right(oDoc.FullFileName, Len(oDoc.FullFileName) - InStrRev(oDoc.FullFileName, "\")) = strFileName Then
            Dim oWP As WorkPlane
            Set oWP = oDoc.ComponentDefinition.WorkPlanes(intWorkplane)
            Dim oWPprox As WorkPlaneProxy
            Call oOcc.CreateGeometryProxy(oWP, oWPprox)
            Call oView.SetIncludeStatus(oWPprox, True)
        End If
    Next
End Sub&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 07:17:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/setincludestatus-in-drawingview-with-subassembly/m-p/9855109#M117855</guid>
      <dc:creator>JhoelForshav</dc:creator>
      <dc:date>2020-11-09T07:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: SetIncludeStatus in DrawingView with SubAssembly</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/setincludestatus-in-drawingview-with-subassembly/m-p/9855467#M117861</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5330176"&gt;@JhoelForshav&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi Jhoel, thank you for the good advice. I have now done that with AllReferencedOccurrences&lt;BR /&gt;and that seems to work for ipt and iam now.&lt;/P&gt;
&lt;P&gt;Here is the complete code to use it from other context:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sub SetIncludeStatusWorkplane()
 Call SetIncludeStatusFromAsm("test.ipt", 1, True)
 'Call SetIncludeStatusFromAsm("test.iam", 1, True)
End Sub

Public Sub SetIncludeStatusFromAsm(strFileName As String, intWorkplane As Integer, boolSetWorkplane As Boolean)
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet
    Dim oAsm As AssemblyDocument
    Set oAsm = oDrawDoc.ReferencedDocuments(1)
    Dim oCompDefAsm As ComponentDefinition
    Set oCompDefAsm = oAsm.ComponentDefinition
    Dim oDoc As Document
    Dim oOcc As ComponentOccurrence
    Dim oOccs As ComponentOccurrences
    Set oOccs = oAsm.ComponentDefinition.Occurrences
    Dim oOccRefs As ComponentOccurrencesEnumerator
    Set oOccRefs = oOccs.AllReferencedOccurrences(oCompDefAsm)
        
    For Each oOcc In oOccRefs
      'Debug.Print (oOcc.Name)
      If FileNameFromPath(oOcc.ReferencedDocumentDescriptor.FullDocumentName) = strFileName Then
        Set oCompDef = oOcc.Definition
        Dim oWP As WorkPlane
        'Get YZ WorkPlane, suppose it's perpendicular to the view
        Set oWP = oCompDef.WorkPlanes.item(intWorkplane)
        'Create proxy object
        Dim oWPpx As WorkPlaneProxy
        Call oOcc.CreateGeometryProxy(oWP, oWPpx)
        'SetIncludeStatus
        Call oSheet.DrawingViews(1).SetIncludeStatus(oWPpx, boolSetWorkplane)
       End If
      Next
End Sub

Public Function FileNameFromPath(strFullPath As String) As String
    Dim i As Integer
    For i = Len(strFullPath) To 1 Step -1
        If Mid(strFullPath, i, 1) = "\" Then
            FileNameFromPath = Right(strFullPath, Len(strFullPath) - i)
            Exit For
        End If
    Next
End Function
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 10:32:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/setincludestatus-in-drawingview-with-subassembly/m-p/9855467#M117861</guid>
      <dc:creator>martin_winkler</dc:creator>
      <dc:date>2020-11-09T10:32:52Z</dc:date>
    </item>
  </channel>
</rss>

