How to get the component name from Sldworks.Face2?

Dear All,

I am trying to modify the hatch angle and scale of a cross section view in the drawing.

I am able to modify those using following API.
http://help.solidworks.com/2021/english/api/sldworksapi/Get_Hatching_Data_Example_VB.htm?verRedirect=
In this code, I would like to know component name from Sldworks.Face2

Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc    
    Set swSelMgr = swModel.SelectionManager
    Set swView = swSelMgr.GetSelectedObjec6(1, -1)
    Set swSketch = swView.GetSketch
    Debug.Print "View   = " & swView.Name
    Debug.Print "  Type = " & swView.Type
    Debug.Print ""
    vFaceHatch = swView.GetFaceHatches
    If Not IsEmpty(vFaceHatch) Then
        Debug.Print "  Face hatches:"
        Debug.Print ""
        For i = 0 To UBound(vFaceHatch)
            Set swFaceHatch = vFaceHatch(i)
            **Set swFace = swFaceHatch.Face**
            ' Cannot select a face because a face is in model
            bRet = swFace.Select2(True, 0)
            ' Get sketch hatch data
            ' 1 radian = 180º/p = 57.295779513º or approximately 57.3º
            Debug.Print "  Angle          = " & swFaceHatch.Angle * 57.3 & " degrees"
            Debug.Print "  Color          = " & swFaceHatch.Color
            Debug.Print "  Definition     = " + swFaceHatch.Definition
            Debug.Print "  Layer          = " & swFaceHatch.Layer
            Debug.Print "  Pattern        = " + swFaceHatch.Pattern
            Debug.Print "  Scale          = " & swFaceHatch.Scale2
            Debug.Print "  SolidFill      = " & swFaceHatch.SolidFill
            Debug.Print "  -----------------------"
        Next i
    End If

I need to know the model name in which this face is associated with?

Set swFace = swFaceHatch.Face

Any Solidworks API available, kindly share it with me

According to my search, you should be able to cast a face to an entity and then get the component that owns that entity with the code below.

https://r1132100503382-eu1-3dswym.3dexperience.3ds.com/#community:yUw32GbYTEqKdgY7-jbZPg/iquestion:D0Xo8CIKSGSTRx0ji9J65A

From there, just use IComponent2.Name2 to get the name.

Hi,
Thanks for the reply.
This below code will only work only in the assembly file.
swentity.getcomponent
I am looking to get the component name from the cross section face in the drawing file.

http://help.solidworks.com/2017/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.ientity~getcomponent.html

Thanks. But this code retruns “Nothing”

Please read the remarks section.