Hey all,
I'm trying to write a macro that will collect information about all points in the selected sketch, will find the points' XYZ and finally will determine their IDs.
Once the data is collected, I'm expecting the macro to create a note at each sketch point, anchored at each point's XYZ. The notes' text field contains the points' ID.
So here's the macro :
(SW2003 / VBA 6)
===========================================================
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.feature
Dim swSketch As SldWorks.sketch
Dim vSketchPt As Variant
Dim vSketchSeg As Variant
Dim swSketchPt As SldWorks.SketchPoint
Dim swSketchSeg As SldWorks.SketchSegment
Dim vID As Variant
Dim i As Long
Dim bRet As Boolean
Dim Note As Object
Dim Part As Object
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject3(1)
Set swSketch = swFeat.GetSpecificFeature
Set Part = swApp.ActiveDoc
Debug.Print "Feature = " + swFeat.Name
vSketchPt = swSketch.GetSketchPoints
If Not IsEmpty(vSketchPt) Then
Debug.Print " Sketch Points:"
For i = 0 To UBound(vSketchPt)
Set swSketchPt = vSketchPt(i)
vID = swSketchPt.GetId
Debug.Print (Trim(" Pt(" + Str(i) + ") = [" + Str(vID(0)) + "," + Str(vID(1)) + "]"))
boolstatus = _
Part.Extension.SelectByID(RTrim("Point") & LTrim(Str(i)), _
"SKETCHPOINT", vSketchPt(i).x, vSketchPt(i).y, 0, _
False, 0, Nothing)
'MsgBox (RTrim("Point") & LTrim(Str(i)))
Set Note = Part.InsertNote(Trim("Pt(" + Str(i) + ")=[" + Str(vID(0)) + "," + Str(vID(1)) + "]"))
If Not Note Is Nothing Then
Note.angle = 0
boolstatus = Note.SetBalloon(0, 0)
Set Annotation = Note.GetAnnotation()
If Not Annotation Is Nothing Then
longstatus = Annotation.SetLeader2(True, 0, True, False, False, False)
boolstatus = Annotation.SetPosition(0.15, 0.15 - i * 0.005, 0)
End If
End If
Next i
End If
Debug.Print ""
vSketchSeg = swSketch.GetSketchSegments
If Not IsEmpty(vSketchSeg) Then
Debug.Print " Sketch Segments:"
For i = 0 To UBound(vSketchSeg)
Set swSketchSeg = vSketchSeg(i)
vID = swSketchSeg.GetId
Debug.Print (Trim(" Seg(" + Str(i) + ") = [" + Str(vID(0)) + "," + Str(vID(1)) + "]"))
Next i
End If
End Sub
===========================================================
The result is : All notes are anchored at the origin point, but are displaying correct point IDs. I've been trying to find a solution to this for 4 days now, can anyone tell me - what in the Sweet Chocolate Christ, have I done wrong ?
I'm trying to write a macro that will collect information about all points in the selected sketch, will find the points' XYZ and finally will determine their IDs.
Once the data is collected, I'm expecting the macro to create a note at each sketch point, anchored at each point's XYZ. The notes' text field contains the points' ID.
So here's the macro :
(SW2003 / VBA 6)
===========================================================
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.feature
Dim swSketch As SldWorks.sketch
Dim vSketchPt As Variant
Dim vSketchSeg As Variant
Dim swSketchPt As SldWorks.SketchPoint
Dim swSketchSeg As SldWorks.SketchSegment
Dim vID As Variant
Dim i As Long
Dim bRet As Boolean
Dim Note As Object
Dim Part As Object
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject3(1)
Set swSketch = swFeat.GetSpecificFeature
Set Part = swApp.ActiveDoc
Debug.Print "Feature = " + swFeat.Name
vSketchPt = swSketch.GetSketchPoints
If Not IsEmpty(vSketchPt) Then
Debug.Print " Sketch Points:"
For i = 0 To UBound(vSketchPt)
Set swSketchPt = vSketchPt(i)
vID = swSketchPt.GetId
Debug.Print (Trim(" Pt(" + Str(i) + ") = [" + Str(vID(0)) + "," + Str(vID(1)) + "]"))
boolstatus = _
Part.Extension.SelectByID(RTrim("Point") & LTrim(Str(i)), _
"SKETCHPOINT", vSketchPt(i).x, vSketchPt(i).y, 0, _
False, 0, Nothing)
'MsgBox (RTrim("Point") & LTrim(Str(i)))
Set Note = Part.InsertNote(Trim("Pt(" + Str(i) + ")=[" + Str(vID(0)) + "," + Str(vID(1)) + "]"))
If Not Note Is Nothing Then
Note.angle = 0
boolstatus = Note.SetBalloon(0, 0)
Set Annotation = Note.GetAnnotation()
If Not Annotation Is Nothing Then
longstatus = Annotation.SetLeader2(True, 0, True, False, False, False)
boolstatus = Annotation.SetPosition(0.15, 0.15 - i * 0.005, 0)
End If
End If
Next i
End If
Debug.Print ""
vSketchSeg = swSketch.GetSketchSegments
If Not IsEmpty(vSketchSeg) Then
Debug.Print " Sketch Segments:"
For i = 0 To UBound(vSketchSeg)
Set swSketchSeg = vSketchSeg(i)
vID = swSketchSeg.GetId
Debug.Print (Trim(" Seg(" + Str(i) + ") = [" + Str(vID(0)) + "," + Str(vID(1)) + "]"))
Next i
End If
End Sub
===========================================================
The result is : All notes are anchored at the origin point, but are displaying correct point IDs. I've been trying to find a solution to this for 4 days now, can anyone tell me - what in the Sweet Chocolate Christ, have I done wrong ?