Use GetFeature Method (IFace2)

Hello
Let me explain my problem:
I want to get the name present in the creation tree by selecting a face. Except that I can't do it.
Here's my code:

 

Code:
Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Sun swSelMgr As SldWorks.SelectionMgr
Dim swFace As SldWorks.Face2
Dim swfeat As SldWorks.Feature
Dim swfacefeat As SldWorks.Feature
Dim swent As SldWorks.Entity
Dim swseldata As SldWorks.SelectData
Dim vface As Variant

Sub test()



Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
If swSelMgr.GetSelectedObjectType3(1, -1) = swSelFACES Then
    Set swFace = swSelMgr.GetSelectedObject6(1, -1)
    Set swseldata = swSelMgr.CreateSelectData
    vface = swFace.GetFeature
    Set swfeat = vface
        MsgBox swfeat. Name
Else
    MsgBox "select a piercing"
    End
End If

End Sub


Would there be someone to help me???
Thanks in advance

Gael

1 Like

Hello

 

A "set" was missing to get the feature and it works.

Below is the modified code

 

A+

 

Philippe

 

Option Explicit
 
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Sun swSelMgr As SldWorks.SelectionMgr
Dim swFace As SldWorks.Face2
Dim swfeat As SldWorks.Feature
Dim swfacefeat As SldWorks.Feature
Dim swent As SldWorks.Entity
Dim swseldata As SldWorks.SelectData
Dim vface As Variant
 
Sub test()
 
 
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
If swSelMgr.GetSelectedObjectType3(1, -1) = swSelFACES Then
    Set swFace = swSelMgr.GetSelectedObject6(1, -1)
    Set swseldata = swSelMgr.CreateSelectData
   Set vface = swFace.GetFeature
    Set swfeat = vface
        MsgBox swfeat. Name
Else
    MsgBox "select a piercing"
    End
End If
 
End Sub
9 Likes

I have only one thing to say: THANK YOU