Create Line From User Selection Example (VBA)
This example shows how to create geometry in
a sketch or drawing, including how to retrieve the coordinates of a user's
selection point into a SafeArray. This information can then be used to
create a line.
'------------------------------------------------------------
Sub LineFromPickPoints()
Dim Model, swApp, SelMgr
As Object
Dim PickPt As Variant
Dim x1, y1, x2, y2 As Double
Set swApp = CreateObject("SldWorks.Application")
Set Model = swApp.ActiveDoc
Set SelMgr = Model.SelectionManager
PickPt = SelMgr.GetSelectionPointInSketchSpace(1)
If (SelMgr.GetSelectedObjectCount
= 0) Or (IsEmpty(PickPt)) Then
swApp.SendMsgToUser
("Select a Location first...")
Else
x1 = PickPt(0)
y1 = PickPt(1)
x2 = PickPt(0) + 0.5
y2 = PickPt(1) + 0.5
Model.CreateLineVB
x1, y1, 0#, x2, y2, 0#
End If
End Sub