<?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: Visibility control - drawing environment in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386739#M1255</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;thanks for your code, but unfortunately appears that error&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kreshbell_0-1742809271652.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1480877i08942B76F82A3FE0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kreshbell_0-1742809271652.png" alt="kreshbell_0-1742809271652.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Mar 2025 09:41:43 GMT</pubDate>
    <dc:creator>kresh.bell</dc:creator>
    <dc:date>2025-03-24T09:41:43Z</dc:date>
    <item>
      <title>Visibility control - drawing environment</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386644#M1253</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;is it possible to create an iLogic that would have visibility control (on/off) in the drawing environment for all parts that have the prefix "-" in the body name. Like this one for example&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kreshbell_0-1742805554844.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1480854iB0FB25E165BB95A1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kreshbell_0-1742805554844.png" alt="kreshbell_0-1742805554844.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2025 08:39:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386644#M1253</guid>
      <dc:creator>kresh.bell</dc:creator>
      <dc:date>2025-03-24T08:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Visibility control - drawing environment</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386728#M1254</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4988405"&gt;@kresh.bell&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Try this&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Sub Main()
    ' Check that the active document is a drawing
    If ThisApplication.ActiveDocument.DocumentType &amp;lt;&amp;gt; kDrawingDocumentObject Then
        MessageBox.Show("This code must be executed in a drawing environment.", "Error")
        Exit Sub
    End If
    
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    
    ' Iterate through all sheets in the drawing
    For Each oSheet As Sheet In oDrawDoc.Sheets
        ' Iterate through all views on the sheet
        For Each oView As DrawingView In oSheet.DrawingViews
            ' Get the model document associated with the view
            Dim oRefDoc As Document
            oRefDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
            
            ' Check document type and call processing
            If oRefDoc.DocumentType = kPartDocumentObject Then
                ProcessPartInView(oView, oRefDoc)
            ElseIf oRefDoc.DocumentType = kAssemblyDocumentObject Then
                ProcessAssemblyInView(oView, oRefDoc)
            End If
        Next
    Next
    
    ' Update the drawing
    oDrawDoc.Update
End Sub

Sub ProcessPartInView(oView As DrawingView, oDoc As PartDocument)
    ' Get the component definition of the part
    Dim oCompDef As PartComponentDefinition
    oCompDef = oDoc.ComponentDefinition
    
    ' Iterate through all solid bodies in the part
    For Each oBody As SurfaceBody In oCompDef.SurfaceBodies
        ' Check if the body name starts with "-"
        If Left(oBody.Name, 1) = "-" Then
            ' Turn off visibility of the body in the drawing view
            oView.SetVisibility(oBody, False)
        End If
    Next
End Sub

Sub ProcessAssemblyInView(oView As DrawingView, oDoc As AssemblyDocument)
    ' Get the component definition of the assembly
    Dim oCompDef As AssemblyComponentDefinition
    oCompDef = oDoc.ComponentDefinition
    
    ' Iterate through all component occurrences in the assembly
    For Each oOcc As ComponentOccurrence In oCompDef.Occurrences
        ' Get the document associated with the occurrence
        Dim oSubDoc As Document
        oSubDoc = oOcc.Definition.Document
        
        ' Process only nested parts
        If oSubDoc.DocumentType = kPartDocumentObject Then
            ProcessPartInView(oView, oSubDoc)
        ElseIf oSubDoc.DocumentType = kAssemblyDocumentObject Then
            ' Recursively process nested assemblies
            ProcessAssemblyInView(oView, oSubDoc)
        End If
    Next
End Sub&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 24 Mar 2025 09:35:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386728#M1254</guid>
      <dc:creator>Ivan_Sinicyn</dc:creator>
      <dc:date>2025-03-24T09:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: Visibility control - drawing environment</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386739#M1255</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;thanks for your code, but unfortunately appears that error&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kreshbell_0-1742809271652.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1480877i08942B76F82A3FE0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kreshbell_0-1742809271652.png" alt="kreshbell_0-1742809271652.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2025 09:41:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386739#M1255</guid>
      <dc:creator>kresh.bell</dc:creator>
      <dc:date>2025-03-24T09:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: Visibility control - drawing environment</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386804#M1256</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4988405"&gt;@kresh.bell&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;One more attempt&lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;Sub Main()
    ' Check that the active document is a drawing
    If ThisApplication.ActiveDocument.DocumentType &amp;lt;&amp;gt; kDrawingDocumentObject Then
        MessageBox.Show("This code must be executed in a drawing environment.", "Error")
        Exit Sub
    End If
    
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    
    ' Iterate through all sheets in the drawing
    For Each oSheet As Sheet In oDrawDoc.Sheets
        ' Iterate through all views on the sheet
        For Each oView As DrawingView In oSheet.DrawingViews
            ' Get the model document associated with the view
            Dim oRefDoc As Document
            oRefDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
            
            ' Check if referenced document is valid
            If oRefDoc Is Nothing Then Continue For
            
            ' Check document type and call processing
            If oRefDoc.DocumentType = kPartDocumentObject Then
                ProcessPartInView(oView, oRefDoc)
            ElseIf oRefDoc.DocumentType = kAssemblyDocumentObject Then
                ProcessAssemblyInView(oView, oRefDoc, New Collection)
            End If
        Next
    Next
    
    ' Update the drawing
    oDrawDoc.Update
End Sub

Sub ProcessPartInView(oView As DrawingView, oDoc As PartDocument)
    ' Check if inputs are valid
    If oView Is Nothing Or oDoc Is Nothing Then Exit Sub
    
    ' Get the component definition of the part
    Dim oCompDef As PartComponentDefinition
    oCompDef = oDoc.ComponentDefinition
    
    ' Check if component definition is valid
    If oCompDef Is Nothing Then Exit Sub
    
    ' Iterate through all solid bodies in the part
    For Each oBody As SurfaceBody In oCompDef.SurfaceBodies
        ' Check if body is valid and its name starts with "-"
        If oBody IsNot Nothing AndAlso Left(oBody.Name, 1) = "-" Then
            Try
                ' Turn off visibility of the body in the drawing view
                oView.SetVisibility(oBody, False)
            Catch ex As Exception
                ' Log error silently or handle as needed
            End Try
        End If
    Next
End Sub

Sub ProcessAssemblyInView(oView As DrawingView, oDoc As AssemblyDocument, oParentOccurrences As Collection)
    ' Check if inputs are valid
    If oView Is Nothing Or oDoc Is Nothing Then Exit Sub
    
    ' Get the component definition of the assembly
    Dim oCompDef As AssemblyComponentDefinition
    oCompDef = oDoc.ComponentDefinition
    
    ' Check if component definition is valid
    If oCompDef Is Nothing Then Exit Sub
    
    ' Iterate through all component occurrences in the assembly
    For Each oOcc As ComponentOccurrence In oCompDef.Occurrences
        ' Check if occurrence is valid
        If oOcc Is Nothing Then Continue For
        
        ' Get the document associated with the occurrence
        Dim oSubDoc As Document
        Try
            oSubDoc = oOcc.Definition.Document
        Catch ex As Exception
            Continue For ' Skip if document cannot be accessed
        End Try
        
        ' Check if sub-document is valid
        If oSubDoc Is Nothing Then Continue For
        
        ' Clone the parent occurrences collection and add the current occurrence
        Dim oNewParentOccurrences As New Collection
        For Each item In oParentOccurrences
            oNewParentOccurrences.Add (item)
        Next
        oNewParentOccurrences.Add (oOcc)
        
        ' Process nested parts
        If oSubDoc.DocumentType = kPartDocumentObject Then
            ProcessNestedPartInView(oView, oSubDoc, oNewParentOccurrences)
        ElseIf oSubDoc.DocumentType = kAssemblyDocumentObject Then
            ' Recursively process nested assemblies
            ProcessAssemblyInView(oView, oSubDoc, oNewParentOccurrences)
        End If
    Next
End Sub

Sub ProcessNestedPartInView(oView As DrawingView, oDoc As PartDocument, oParentOccurrences As Collection)
    ' Check if inputs are valid
    If oView Is Nothing Or oDoc Is Nothing Or oParentOccurrences Is Nothing Then Exit Sub
    
    ' Get the component definition of the part
    Dim oCompDef As PartComponentDefinition
    oCompDef = oDoc.ComponentDefinition
    
    ' Check if component definition is valid
    If oCompDef Is Nothing Then Exit Sub
    
    ' Iterate through all solid bodies in the part
    For Each oBody As SurfaceBody In oCompDef.SurfaceBodies
        ' Check if body is valid and its name starts with "-"
        If oBody IsNot Nothing AndAlso Left(oBody.Name, 1) = "-" Then
            Try
                ' Create a proxy for the surface body in the context of the full occurrence path
                Dim oBodyProxy As Object = oBody
                If oParentOccurrences.Count &amp;gt; 0 Then
                    Dim oCurrentOcc As ComponentOccurrence
                    ' Apply proxy creation for each level of nesting in reverse order
                    For i = oParentOccurrences.Count To 1 Step -1
                        oCurrentOcc = oParentOccurrences(i)
                        Dim oTempProxy As Object
                        oCurrentOcc.CreateGeometryProxy(oBodyProxy, oTempProxy)
                        If oTempProxy IsNot Nothing Then
                            oBodyProxy = oTempProxy
                        End If
                    Next
                End If
                
                ' Turn off visibility of the body proxy in the drawing view
                If oBodyProxy IsNot Nothing Then
                    oView.SetVisibility(oBodyProxy, False)
                End If
            Catch ex As Exception
                ' Log error silently or handle as needed
            End Try
        End If
    Next
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Edited: UPD.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2025 10:31:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386804#M1256</guid>
      <dc:creator>Ivan_Sinicyn</dc:creator>
      <dc:date>2025-03-24T10:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Visibility control - drawing environment</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386861#M1257</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1777941"&gt;@Ivan_Sinicyn&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;much better, but it seems like it doesn't work if it's in a subassembly&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kreshbell_0-1742812923651.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1480917iAE27F9E73DD5DF6A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kreshbell_0-1742812923651.png" alt="kreshbell_0-1742812923651.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but it works if it's a part placed assembly&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kreshbell_1-1742812991596.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1480918i5660F77429939702/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kreshbell_1-1742812991596.png" alt="kreshbell_1-1742812991596.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2025 10:43:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386861#M1257</guid>
      <dc:creator>kresh.bell</dc:creator>
      <dc:date>2025-03-24T10:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: Visibility control - drawing environment</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386862#M1258</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4988405"&gt;@kresh.bell&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I updated the second post with the code 5 minutes ago. Check it again. It's working for me.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2025 10:44:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386862#M1258</guid>
      <dc:creator>Ivan_Sinicyn</dc:creator>
      <dc:date>2025-03-24T10:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: Visibility control - drawing environment</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386921#M1259</link>
      <description>&lt;P&gt;unfortunately, dont't works for me for sub sub sub assembly here&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kreshbell_1-1742815737022.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1480935i606CA603372968D2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kreshbell_1-1742815737022.png" alt="kreshbell_1-1742815737022.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2025 11:29:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13386921#M1259</guid>
      <dc:creator>kresh.bell</dc:creator>
      <dc:date>2025-03-24T11:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: Visibility control - drawing environment</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13387035#M1260</link>
      <description>&lt;P&gt;Okay, two problems.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. I misunderstood the task at hand.&lt;span class="lia-unicode-emoji" title=":grimacing_face:"&gt;😬&lt;/span&gt;&lt;/P&gt;&lt;P&gt;2. I made visibility to be disabled for solids, but not for components containing them. But, I have it turned off at any nested levels and I don't understand why it is not turned off for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will later change to disable visibility for parts that contain such solids.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you make a small assembly with a drawing file where the code doesn't work?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Mar 2025 12:46:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/visibility-control-drawing-environment/m-p/13387035#M1260</guid>
      <dc:creator>Ivan_Sinicyn</dc:creator>
      <dc:date>2025-03-24T12:46:14Z</dc:date>
    </item>
  </channel>
</rss>

