Some background: I would like to crate a macro that generates springs from a text file of data, specifically spring centerline data and wire diameter. This is a text file (though, it might have a different file extension than .txt, despite acting like a .txt), that has three columns separated by tabs, and a number of rows separated by line breaks. Each row represents a point, and each column represents the X, Y, and Z coordinate of those points, respectively. If the text file is not formatted in this way, I don't think SolidWorks will accept it. The wire diameter can be manually input.
If we were to adapt this program to make springs from a single Frontedge folder, the program would need to search for the centerline data within the folder, as well as the wire diameter, and output several files.
After the spring is made, Save the new SolidWorks part. We'd need to choose a name for the spring, and the output folder. We mostly make use of the SolidWorks model of the spring to check for packaging in assemblies, so ideally, after setting everything up, it would only take the press of a button to update (or overwrite) the springs while iterating a design.
I've been using this macro as a foundation, but I don't think it can read from a text file:
API: Create Spring Macro Feature (VBA)
The first step is reading the relevant lines from a text file and generating the curve, so this is the code I have so far:
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
swApp.ActiveDoc.ActiveView.FrameState = 1
Dim skPoint As Object
Dim lines() As String
Dim sBuffer As String
Const FILE_NAME As String = "insert file path here"
Dim fileNmb As Integer
Dim myLine() As String
Part.SketchManager.Insert3DSketch True
fileNmb = FreeFile()
Do While Not EOF(fileNmb)
Part.InsertCurveFileBegin
'Input #1, X, Y, Z
Input #fileNmb, myLine(6)
Set skPoint = Part.SketchManager.CreatePoint(X / 1000, Y / 1000, Z / 1000)
Loop
Close #fileNmb
Set swApp = _Application.SldWorks
Set Part = swApp.ActiveDoc
End Sub
How do I read the file if I want to read it from line 6? I've been using this line: Part.InsertCurveFileBegin but I wonder if there needs to be more.
I also get a 'bad file name or number' error on this line: Do While Not EOF(fileNmb)
You are missing the following line:
To read from 6th line. Just do 5 dummy inputs to temp variable. Something like