I'm using the code below for part models to assign a name to every face in the model. Essentially, I m right-cliking on a face in SWs and selecting Face Properties and giving it a Name in Entity Information box - all via API.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim retval As Variant
Dim i As Integer
Dim swFace As SldWorks.Face2
Dim matProps(8) As Double
Dim currface As Integer
Dim boolstatus As Boolean
Dim obj As Object
Set swApp = Application.SldWorks
If Not swApp Is Nothing Then
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
Set swPart = swModel
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
Set obj = swModel.SelectionManager.GetSelectedObject5(1)
boolstatus = swPart.SetEntityName(swFace, "Side # " & currface)
Set swFace = swFace.GetNextFace
currface = currface + 1
Set swApp = Nothing
I'd like to do the same to the faces of components in an assembly. I've traversed the assembly and tried to do it that way, but to no avail. I can select the faces in different components in an assembly via the API, but I can't assign the entity name to the faces in the components in the assembly model like I can for the parts models.
I can't think of a way to correctly do the operation in the assembly. The code always breaks at: boolstatus = swPart.SetEntityName(swFace, "Side # " & currface) as I'm working in an assembly.
Any help or advise will be much appreciated.