2 Replies Latest reply on Mar 21, 2014 8:43 AM by George Bon

    Select2 Method (IBody2) working in part but not in assembly

    George Bon

      Hello all,

       

      I noticed that when using the select2 method to select bodies, if the activedocument is a part, selected bodies will highlight, but if the active document is an assembly and I use select2 to select bodies within components, the bodies do not highlight even though select2 returns 'True'.

       

      Any help appreciated

       

      Here is my code for reference:

       

      Private Sub ListBox5_Click()
         
          Dim i As Long, j As Long, k As Long
          Dim swBody As Body2
          Dim swSelData As SldWorks.SelectData
          Dim materialnameStr As String
          Dim swPart As PartDoc
          Dim vBodies As Variant
          Dim swRootComp                  As SldWorks.Component2
          Dim swConf                      As SldWorks.Configuration
          Dim swAssy As SldWorks.AssemblyDoc
          Dim vComponents As Variant
          Dim swComponent As Component2


          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swConf = swModel.GetActiveConfiguration
          Set swRootComp = swConf.GetRootComponent3(True)
         
          swModel.ClearSelection2 True

          i = 0

          Do Until i = UserForm1.ListBox5.ListCount
              i = i + 1
              If UserForm1.ListBox5.Selected(i) Then
             
                  materialnameStr = ListBox5.List(i, 0)
                  Debug.Print materialnameStr
                 
                  If isPart(swRootComp) Then
                      Set swPart = swModel
                      vBodies = swPart.GetBodies2(0, False)
                      If isArrayEmpty(vBodies) = False Then
                          For j = LBound(vBodies) To UBound(vBodies)
                             
                              Set swBody = vBodies(j)
                              If swBody.GetMaterialPropertyName("", "") = "" And swPart.GetMaterialPropertyName2("", "") = materialnameStr Then
                                  boolstatus = swBody.Select2(True, swSelData)
                              ElseIf swBody.GetMaterialPropertyName("", "") = materialnameStr Then
                                  boolstatus = swBody.Select2(True, swSelData)
                              End If
                          Next
                      End If
                     
                  Else

                      Set swAssy = swModel
                      vComponents = swAssy.GetComponents(False)
                     
                      For k = LBound(vComponents) To UBound(vComponents)
                         
                          Set swModel = vComponents(k).GetModelDoc2

                          If swModel.GetType() = swDocPART Then
                         
                              Set swPart = swModel

                              vBodies = swPart.GetBodies2(0, False)
                         
                              If isArrayEmpty(vBodies) = False Then
                             
                                  For j = LBound(vBodies) To UBound(vBodies)
                                     
                                      Set swBody = vBodies(j)
                                      If swBody.GetMaterialPropertyName("", "") = "" And swPart.GetMaterialPropertyName2("", "") = materialnameStr Then
                                          boolstatus = swBody.Select2(True, swSelData)
                                      ElseIf swBody.GetMaterialPropertyName("", "") = materialnameStr Then
                                          boolstatus = swBody.Select2(True, swSelData)
                                      End If
                                      Debug.Print boolstatus
                                     
                                  Next
                                 
                              End If
                             
                          End If
                         
                       
                      Next

                  End If
                 
              End If
          Loop

             
         
      End Sub