solid body visibility from objectcollection

solid body visibility from objectcollection

Neil-Star
Participant Participant
228 Views
2 Replies
Message 1 of 3

solid body visibility from objectcollection

Neil-Star
Participant
Participant

The scenario I have is within an assembly I need to go through a preselected object collection and find certain occurrences of content centre parts within and change the visibility of solid bodies within. My code works fine when looping through all leaf occurrences of assembly but when I loop through only the object collection it does not update the parts, despite finding them fine. 

TIA.

       Public Sub SB2()

           Dim oDoc As AssemblyDocument
           Dim oInsul As String
           Dim oOccurrence As ComponentOccurrence
           Dim oPartDef As PartComponentDefinition
           Dim oPartDoc As PartDocument
           Dim oRunQty As Integer
           Dim oSelectedEnts As ObjectCollection
           Dim oSrfBod As SurfaceBody
           Dim oSrfBods As SurfaceBodies
           Dim oSrfBodProxy As SurfaceBodyProxy
           Dim oVis As String

           oDoc = g_inventorApplication.ActiveDocument
           oVis = "FULL"
           oInsul = "025"
           oRunQty = 2

           If oSelectedEnts Is Nothing Then
               oSelectedEnts = g_inventorApplication.TransientObjects.CreateObjectCollection()
           End If

           For Each oItem In g_inventorApplication.ActiveDocument.SelectSet
               oSelectedEnts.Add(oItem)
           Next

           For i = 1 To oRunQty
               oOccurrence = oSelectedEnts.Item(i)
               'loop through the sub occurences within each occurence in the object collection
               'oDoc = g_inventorApplication.ActiveDocument
               ' For Each occ As ComponentOccurrence In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences - works fine for this scenario

               For Each occ In oOccurrence.Definition.Occurrences.AllLeafOccurrences
                   If occ.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then

                       If occ.Definition.Iscontentmember Then
                           oPartDef = occ.Definition
                           oPartDoc = oPartDef.Document
                           oSrfBods = oPartDef.SurfaceBodies

                           'show/hide solid bodies in the content center part occurences
                           For Each oSrfBod In oSrfBods
                               If oSrfBod.Name.Contains("FIT") Then
                               Else

                                   If oSrfBod.Name = "INS_" & oInsul Or oSrfBod.Name = "SHL_" & oInsul Then
                                       Call occ.CreateGeometryProxy(oSrfBod, oSrfBodProxy)
                                       oSrfBodProxy.Visible = True
                                   End If
                               End If
                           Next
                       End If
                   End If
               Next
           Next
       End Sub

T

 

0 Likes
Accepted solutions (1)
229 Views
2 Replies
Replies (2)
Message 2 of 3

marcin_otręba
Advisor
Advisor
Accepted solution

hi,

 

if you want to inspect only selected occurrences then go with this code,

       Public Sub SB2()

           Dim oDoc As AssemblyDocument
           Dim oInsul As String
           Dim occ As ComponentOccurrence
           Dim oPartDef As PartComponentDefinition
           Dim oPartDoc As PartDocument
           Dim oRunQty As Integer
           Dim oSelectedEnts As ObjectCollection
           Dim oSrfBod As SurfaceBody
           Dim oSrfBods As SurfaceBodies
           Dim oSrfBodProxy As SurfaceBodyProxy
           Dim oVis As String

           oDoc = g_inventorApplication.ActiveDocument
           oVis = "FULL"
           oInsul = "025"
           oRunQty = 2

           If oSelectedEnts Is Nothing Then
               oSelectedEnts = g_inventorApplication.TransientObjects.CreateObjectCollection()
           End If

           For Each oItem In g_inventorApplication.ActiveDocument.SelectSet
               oSelectedEnts.Add(oItem)
           Next

           For i = 1 To oRunQty
               oOccurrence = oSelectedEnts.Item(i)
               'loop through the sub occurences within each occurence in the object collection
               'oDoc = g_inventorApplication.ActiveDocument
               ' For Each occ As ComponentOccurrence In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences - works fine for this scenario

             
                   If occ.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then

                       If occ.Definition.Iscontentmember Then
                           oPartDef = occ.Definition
                           oPartDoc = oPartDef.Document
                           oSrfBods = oPartDef.SurfaceBodies

                           'show/hide solid bodies in the content center part occurences
                           For Each oSrfBod In oSrfBods
                               If oSrfBod.Name.Contains("FIT") Then
                               Else

                                   If oSrfBod.Name = "INS_" & oInsul Or oSrfBod.Name = "SHL_" & oInsul Then
                                       Call occ.CreateGeometryProxy(oSrfBod, oSrfBodProxy)
                                       oSrfBodProxy.Visible = True
                                   End If
                               End If
                           Next
                       End If
                   End If
               Next

       End Sub

 

if you want to check suboccurrences in selected occurrences then change line 34 from

For Each occ In oOccurrence.Definition.Occurrences.AllLeafOccurrences

to :

 For Each occ In oOccurrence.SubOccurrences

 

also keep in mind that it will check only 2 selected occurrences because of line 18.

it shpuld be changed to something like:

 

 oRunQty =  g_inventorapplication.ActiveDocument.SelectSet.Count

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 3

Neil-Star
Participant
Participant

Thanks a lot!