Can you attach the part as well?
Please see attached file, macro has been ran on this and can be seen only one half of the model has names applied to the faces.
test_case.SLDPRT.zip 52.5 KB
Ok I found the issue. Found this in the help file.
"If the entity already has a name, then this method does not change the name and returns false.
This behavior is intended to prevent a program from accidentally renaming an entity that is referenced in some other location. For example, if an assembly contains a mate to a face on a part, then a name is automatically assigned to that face. If you were to change that name, then there is no guarantee that the mate is still valid. Therefore, when using entity names, you should first check to see if the entity is already named, and, if so, use the existing name. If no name exists for the entity, then you can name the entity.
You can explicitly delete an entity name using the IPartDoc::DeleteEntityName or IPartDoc::IDeleteEntityName method. You then have the option of renaming the item or using that name elsewhere. The method was provided because the action is already available in the core SolidWorks product. However, you should recognize the possibility of reference failures as described."
The reason it wasn't working on your two body part was that your currface = 1 was in the body loop thus resetting it to 1 after it looped through the first body. So the entity name was already taken. I added a line to delete the name. See the comments below.
Here is the updated macro.
Dim swApp As SldWorks.SldWorks
Dim Part As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim boolstatus As Boolean
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
currface = 1
If Not swPart Is Nothing Then
retval = swPart.GetBodies2(SwConst.swSolidBody, True)
For i = 0 To UBound(retval)
Dim swBody As Body2
Set swBody = retval(i)
Set swFace = swBody.GetFirstFace
Do While Not swFace Is Nothing
Set obj = Part.SelectionManager.GetSelectedObject5(1)
boolstatus = swPart.DeleteEntityName(swFace) '************************ remove or comment out if you don't want to accidentally rename your faces in the future.
boolstatus = swPart.SetEntityName(swFace, currface)
Debug.Print boolstatus & " " & swPart.GetEntityName(swFace)
Set swFace = swFace.GetNextFace
currface = currface + 1
Set swApp = Nothing