AnsweredAssumed Answered

How to get the text of the tree node associated with the material?

Question asked by Boris Sorin on Jun 25, 2020
Latest reply on Jun 29, 2020 by Boris Sorin

Hello! For all nodes of the construction tree, I developed an algorithm for obtaining the text of the selected node. This algorithm works for all nodes except the nodes associated with the material. The problem is that I do not know which object is associated with the selected node in this case. Here is my algorithm:

 

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeature As SldWorks.Feature
Dim swSelectionMgr As SldWorks.SelectionMgr
Dim swComponent As SldWorks.Component2
Dim typeObj As Integer

 

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelectionMgr = swModel.SelectionManager

typeObj = swSelectionMgr.GetSelectedObjectType3(1, -1)
Debug.Print "type: " & typeObj
If typeObj = swSelCOMPONENTS Then
   Set swComponent = swSelectionMgr.GetSelectedObjectsComponent4(1, -1)
   If Not swComponent Is Nothing Then
      Debug.Print "Component Name: " & swComponent.Name2
   End If
Else
   Set swFeature = swSelectionMgr.GetSelectedObject6(1, -1)
   If Not swFeature Is Nothing Then
      Debug.Print "Feature Name: " & swFeature.Name
   End If
End If

 

For the selected tree node associated with the material, the type of the object is typeObj = swSelBROWSERITEM
I do not get to the statement Debug.Print "Component Name:" & swComponent.Name2
since the selected object is not a Component. I do not get to the statement Debug.Print "Feature Name:" & swFeature.Name as well since swComponent Is Nothing.

 

This means that the selected object is neither a Component2, nor Feature. What is it then?
I would be grateful for any help.

Outcomes