Files
Setting and getting faces by name
Code
'Demonstrates usage of IPartDoc::SetEntityName.
'Preconditions: Part is open and at least one body is present.
'Postconditions: All faces are named.
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim vBodies As Variant
Dim swBody As SldWorks.Body2
Dim vFaces As Variant
Dim swFace As SldWorks.Face2
Dim swEnt As SldWorks.Entity
Dim i As Integer
Dim z As Integer
Dim facecounter As Integer
Dim errors As Long
Dim warnings As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
facecounter = 1
vBodies = swPart.GetBodies2(swAllBodies, False)
For i = 0 To UBound(vBodies)
Set swBody = vBodies(i)
vFaces = swBody.GetFaces
For z = 0 To UBound(vFaces)
Set swFace = vFaces(z)
Set swEnt = swFace
Debug.Print swPart.SetEntityName(swEnt, "Face-" & facecounter)
facecounter = facecounter + 1
Next z
Next i
'swModel.Save3 swSaveAsOptions_Silent, errors, warnings
'swApp.CloseDoc swModel.GetTitle
End Sub
'Notes: IPartDoc::SetEntityName returns true if the entity was not previously named. _
Otherwise it returns false and the previous entity name was kept. Use _
IPartDoc::DeleteEntityName to remove an existing entity name before renaming it.