Files
Code
Module: mMain
'Gets the fully qualified path name for a selected sketch entity in a part _
or assembly.
'Note:
'-Conics are considered parabolas in the API.
'-ISketchSegment::GetID and ISketchPoint::GetID return two integers. The _
second integer is the one needed by IModelDocExtension::SelectByID2. _
It is also the same integer seen when an entity is selected with the _
Measure tool in the GUI. When the first integer is useful is unclear.
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swObj As Object
Dim swSkSeg As SldWorks.SketchSegment
Dim swSkPt As SldWorks.SketchPoint
Dim swFeat As SldWorks.Feature
Dim vId As Variant
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swObj = swSelMgr.GetSelectedObject6(1, -1)
If TypeOf swObj Is SldWorks.SketchPoint Then
Set swSkPt = swObj
Set swFeat = swSkPt.GetSketch
vId = swSkPt.GetID
Debug.Print "Point" & vId(1) & "@" & swFeat.GetNameForSelection(Empty)
ElseIf TypeOf swObj Is SldWorks.SketchSegment Then
Set swSkSeg = swObj
Set swFeat = swSkSeg.GetSketch
vId = swSkSeg.GetID
Select Case swSkSeg.GetType
Case swSketchARC
Debug.Print "Arc" & vId(1) & "@" & swFeat.GetNameForSelection(Empty)
Case swSketchELLIPSE
Debug.Print "Ellipse" & vId(1) & "@" & swFeat.GetNameForSelection(Empty)
Case swSketchLine
Debug.Print "Line" & vId(1) & "@" & swFeat.GetNameForSelection(Empty)
Case swSketchPARABOLA
Debug.Print "Parabola" & vId(1) & "@" & swFeat.GetNameForSelection(Empty)
Case swSketchSPLINE
Debug.Print "Spline" & vId(1) & "@" & swFeat.GetNameForSelection(Empty)
Case swSketchTEXT
Debug.Print "SketchText" & vId(1) & "@" & swFeat.GetNameForSelection(Empty)
End Select
Else
Debug.Print "Unsupported sketch entity."
End If
End Sub