2 Replies Latest reply on Jan 27, 2017 4:38 AM by roberto gennari

    Help! Get subassembly object of a select component

    roberto gennari

      Hallo,

      I want found the subassembly object which contain the select component:

       

      Preconditions:

      - A document assembly with some subassembly and components

      - A component in a subassembly is select

       

      Dim swApp As SldWorks.SldWorks
      Dim activeDocument As SldWorks.ModelDoc2
      Dim refmodel As SldWorks.ModelDoc2
      Dim selEntity As Entity
      Dim selType As Long
      Dim selType2 As Long
      Dim selmgr As Object
      Dim owningComponent As Object
      Public componentNames, componentName
      Public levels As Double
      Const swDocPART = 1
      Const swSelEDGES = 1
      Const swSelFACES = 2
      Const swSelVERTICES = 3

       

       

      Sub main()
      Set swApp = Application.SldWorks  
      Set activeDocument = swApp.ActiveDoc

      If (activeDocument.GetType = 1) Then 
        Exit Sub
      End If

      Set selmgr = activeDocument.SelectionManager      

      selType2 = selmgr.GetSelectedObjectType2(2)    
      selType = selmgr.GetSelectedObjectType2(1)    

      'swSelFACES=2
      'swSelEDGES=1
      'swSelVERTICES=3
      If ((selType = 2) Or _
          (selType = 1) Or _
          (selType2 = 1) Or _
          (selType2 = 2) Or _
          (selType2 = 3) Or _
          (selType = 3)) Then    
          If (activeDocument.GetType = 3) Then
              Set selEntity = selmgr.GetSelectedObject3(2)
              If (selType2 = 0) Then      
                  Set selEntity = selmgr.GetSelectedObject3(1)
              End If
          Else
              Set selEntity = selmgr.GetSelectedObject3(1)  
          End If
          Set owningComponent = selEntity.GetComponent 
          componentName = owningComponent.Name

       

      'HERE HOW   GET THE SUBASSEMBLY OBJECT?


          Debug.Print componentName
          componentNames = Split(componentName, "/")
          levels = UBound(componentNames)
         
      Else
          swApp.SendMsgToUser "Please select a Face, Edge or Vertex"
          End
      End If

      End Sub