I am having some inconsistency in the behavior of the GetCoordinates method for a SketchText object. When the text is not left-justified, the coordinate returned by the method is not correct. I was hoping at the very least to get either the left corner or the right corner of the bounding box that is touching the construction line. Has anyone else run into this? Am I missing something?
I’ve made a small macro to find the point and insert a green SketchPoint right back into the sketch at the location given. I’m not sure how to upload a sample file here, however if you create a sketch and add text and exit the sketch then the macro should run fine.
Left Justified - Not flipped / Not mirrored
MiddleJustified - Not flipped / Not mirrored
Right Justified - Not flipped / Not mirrored
Left Justified - flipped / mirrored
Middle Justified - flipped / mirrored
Right Justified - flipped / mirrored
Macro Code for Testing:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swSketchSegment As SketchSegment
Dim swSketch As Sketch
Dim swSketchText As SketchText
Dim swSketchMgr As SketchManager
Dim swSketchPoint As SketchPoint
Dim swExtension As ModelDocExtension
Dim curFeature As feature
Dim featureTypeName As String
Dim bRet As Boolean
Dim vSketchSegments As Variant
Dim vSketchSegment As Variant
Dim vCoords As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSketchMgr = swModel.SketchManager
Set swExtension = swModel.Extension
Set curFeature = swModel.FirstFeature
swExtension.StartRecordingUndoObject
Do While Not curFeature Is Nothing
featureTypeName = curFeature.GetTypeName2()
If featureTypeName = "ProfileFeature" Then
Set swSketch = curFeature.GetSpecificFeature2
vSketchSegments = swSketch.GetSketchSegments
If (Not IsEmpty(vSketchSegments)) Then
For Each vSketchSegment In vSketchSegments
Set swSketchSegment = vSketchSegment
If swSketchSegment.GetType = swSketchSegments_e.swSketchText Then
Set swSketchText = swSketchSegment
Debug.Print "[F] FeatureTypeName: " & curFeature.Name & " " & featureTypeName
Debug.Print " Sketch text = " & swSketchText.Text
vCoords = swSketchText.GetCoordinates
Debug.Print " X:" & toInches(vCoords(0)) & " Y:" & toInches(vCoords(1)) & " Z:" & toInches(vCoords(2))
curFeature.Select2 False, -1
swModel.EditSketch
'swSketchMgr.AddToDB = True
Set swSketchPoint = swSketchMgr.CreatePoint(vCoords(0), vCoords(1), vCoords(2))
swSketchPoint.Color = 65280
'swSketchMgr.AddToDB = False
swModel.InsertSketch2 False
End If
Next vSketchSegment
End If
End If
Set curFeature = curFeature.GetNextFeature()
Loop
bRet = swExtension.FinishRecordingUndoObject2("Add Insert Coords for SketchText", False)
swModel.ForceRebuild3 True
Debug.Print "MACRO COMPLETE"
End Sub
Function toInches(number As Variant) As String
toInches = Format(number / 0.0254, "0.0000") & " in"
End Function