Inconsistent Point Import from UTF-8 Text File (SolidWorks 2026)

Dear all,

I am trying to import a list of points from a UTF-8 encoded text file using a macro I wrote. However, I am experiencing inconsistent results:

  • Some points are imported correctly.
  • Others have incorrect coordinates.
  • When I run the macro multiple times, the point locations change each time.

The text file format is as follows:

2.3500080    27.4249896
4.8600000    10.3500000
4.8600000    13.3500000
4.8600000    16.3500000
4.8600000    19.3500000
5.0250090    25.8700016

System information:

  • Operating System: Windows 11
  • Regional Settings: Germany (possible issue due to decimal separator preferences)
  • Software: SolidWorks Designer 2026 SP 0.0

Has anyone experienced similar behavior or knows what might be causing this issue?

Thank you in advance.


 

Macro:
Option Explicit

Sub main()

   ' ===== EINSTELLUNGEN (mm) =====
   Const OFFSET_X_MM As Double = 0# '45# + 7.75
   Const OFFSET_Y_MM As Double = 0# '-17.5 - 10.35
   Const MIRROR_X As Boolean = True
   ' =============================

   Dim swApp As Object
   Dim part As Object
   Dim skManager As Object
   Dim fs As Object
   Dim textStream As Object

   Dim line As String
   Dim coords() As String
   Dim x_mm As Double
   Dim y_mm As Double
   Dim sketchWasOpen As Boolean
   Dim idx As Long: idx = 1

   Set swApp = Application.SldWorks
   Set part = swApp.ActiveDoc
   If part Is Nothing Then Exit Sub

   Set skManager = part.SketchManager
   Set fs = CreateObject("Scripting.FileSystemObject")

   Set textStream = fs.OpenTextFile( _
       "xy_testpads3.txt")

   part.ClearSelection2 True
   part.Extension.SelectByID2 "Ebene oben", "PLANE", 0, 0, 0, False, 0, Nothing, 0
   skManager.InsertSketch True

   Do While Not textStream.AtEndOfStream

       line = Trim(textStream.ReadLine)
       If line <> "" Then

           line = Replace(line, vbTab, " ")
           Do While InStr(line, "  ") > 0
               line = Replace(line, "  ", " ")
           Loop

           coords = Split(line, " ")

           If UBound(coords) >= 1 Then

               ' --- Rohdaten aus Datei (mm)
               x_mm = CDbl(Replace(coords(0), ".", ","))
               y_mm = CDbl(Replace(coords(1), ".", ","))

               Debug.Print "Punkt " & idx & " RAW     : X=" & Format(x_mm, "0.0000000") _
                                     & "  Y=" & Format(y_mm, "0.0000000") & " [mm]"

               ' --- Transformation (mm!)
               If MIRROR_X Then x_mm = -x_mm

               x_mm = x_mm + OFFSET_X_MM
               y_mm = y_mm + OFFSET_Y_MM

               Debug.Print "Punkt " & idx & " TRANSF.: X=" & Format(x_mm, "0.0000000") _
                                     & "  Y=" & Format(y_mm, "0.0000000") & " [mm]"

               ' --- Übergabe an SolidWorks (einmalig in Meter!)
               skManager.CreatePoint x_mm / 1000#, y_mm / 1000#, 0#

               Debug.Print "Punkt " & idx & " SW      : X=" & Format(x_mm / 1000#, "0.000000000") _
                                     & "  Y=" & Format(y_mm / 1000#, "0.000000000") _
                                     & "  Z=0.000000000 [m]"
               Debug.Print String(70, "-")

               idx = idx + 1
           End If
       End If
   Loop

   textStream.Close

   If Not sketchWasOpen Then
       skManager.InsertSketch False
   End If

   part.ViewZoomtofit2
   MsgBox "Punkte erfolgreich erstellt.", vbInformation

End Sub