Select and Rename Objects Example (VBA)
The example shows how to verify the name of
the edge and then change it. You could also select the edge programmatically
using IFace2::GetEdges or ICoEdge::GetEdge. It is assumed that the user
has selected an edge.
Verify that the user
has made a selection
Grab the dispatch handle
to the selected object
Determine the type
of object selected
Determine the name
of the object
Give the entity a name
if one does not already exist
'------------------------------------------------------------
Sub GetAndSetEdgeName()
Dim swApp As
Object
Dim Model, Part
As Object
Dim SelMgr As
Object
Dim selObj As
Object
Dim edgeName,
messageString As String
Const swSelEDGES
= 1
Set swApp =
CreateObject("SldWorks.Application")
Set Model =
swApp.ActiveDoc
Set Part = Model
Set SelMgr =
Model.SelectionManager()
If (SelMgr.GetSelectedObjectCount <> 0) Then
Set selObj = SelMgr.GetSelectedObject5(1)
If (SelMgr.GetSelectedObjectType(1) = swSelEDGES)
Then
edgeName =
Part.GetEntityName(selObj)
If (edgeName
= "") Then
ret = Part.SetEntityName(selObj, "NewEdgeName")
If (ret = True)
Then
swApp.SendMsgToUser ("Successfully gave
the edge a name")
Else
swApp.SendMsgToUser ("Error changing
edge name.")
End If
Else
messageString
= "Edge already has name of " + edgeName
swApp.SendMsgToUser (messageString)
End
If
Else
swApp.SendMsgToUser ("Please Select an
Edge for this operation.")
End If
End If
End Sub