Page 1 of 1
API Create Closed Spline
Posted: Wed Jul 21, 2021 3:46 pm
by Jordan Brown
Hello,
Does anyone have a way for creating a closed spline using the API? I have a macro that creates a spline form points but I can't find a way to close it.
I tried repeating the first point but I received an error.
Thanks,
Jordan
Re: API Create Closed Spline
Posted: Thu Jul 22, 2021 8:55 am
by Eddy Alleman
Hi Jordan,
Can you show your code?
What error did you get?
The following recorded code creates a spline with the last point equal to the first one:
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
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.SketchManager.InsertSketch True
Part.ClearSelection2 True
Dim pointArray As Variant
Dim points() As Double
ReDim points(0 To 11) As Double
points(0) = 0
points(1) = 0
points(2) = 0
points(3) = 8.84089926098794E-02
points(4) = 0.041517292882147
points(5) = 0
points(6) = -3.17090003889537E-02
points(7) = 8.90807934655776E-02
points(8) = 0
points(9) = 0
points(10) = 0
points(11) = 0
pointArray = points
Dim skSegment As Object
Set skSegment = Part.SketchManager.CreateSpline((pointArray))
Part.ClearSelection2 True
Part.SketchManager.InsertSketch True
End Sub
So there must be something else going on.
Eddy
Re: API Create Closed Spline
Posted: Fri Jul 23, 2021 7:37 am
by Jordan Brown
Thanks Eddy, I should have guessed, but the error was not really related to the spline. The message was a generic "Your application has encountered a problem...index value does not exist..."
I was sorting a bunch of points using lists. Everything worked fine, until I tried adding my original point to the spline list, without realizing that I had already deleted it.
As generic as the error was, I should have realized that it pointed to something other than the spline command.
Thanks again,
Storm
Re: API Create Closed Spline
Posted: Fri Jul 23, 2021 10:07 am
by Eddy Alleman
You're welcome
thanks for your feedback ;-)
Eddy