I am trying to assign a name to all faces on parts, I found an example which does exactly this:
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim boolstatus As Boolean
Sub setFaceNames()
Dim swFace As SldWorks.Face2
Dim currface As Integer
Dim retval As Variant
Dim i As Integer
Dim obj As Object
Set swApp = Application.SldWorks
If Not swApp Is Nothing Then
Set Part = swApp.ActiveDoc
If Not Part Is Nothing Then
Set swPart = Part
If Not swPart Is Nothing Then
retval = swPart.GetBodies2(SwConst.swSolidBody, True)
For i = 0 To UBound(retval)
Set swFace = retval(i).GetFirstFace
currface = 1
Do While Not swFace Is Nothing
swFace.Select False
Set obj = Part.SelectionManager.GetSelectedObject5(1)
boolstatus = swPart.SetEntityName(swFace, currface)
Debug.Print swPart.GetEntityName(swFace)
Set swFace = swFace.GetNextFace
currface = currface + 1
Loop
Next i
End If
End If
End If
Set swApp = Nothing
End Sub
This has worked fine for most of the parts however, there is one component which is revolved as two separate closed sketches as shown below:
This causes problems as the faces on the left section of the revolved body do not seem to get names applied to them, only the faces on for the section sketched on the right do. I think this may have something to do with the split between two sketches resulting in SW thinking these are two separate bodies?? In which case, how could all faces be named?
SolidworksApi macros