Hi all,
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.
Option Explicit
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
Sub main()
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
swFace.Select False
Set obj = swModel.SelectionManager.GetSelectedObject5(1)
boolstatus = swPart.SetEntityName(swFace, "Side # " & 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
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.
Thanks.
Mo
SolidworksApi macros