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
API Create Closed Spline
-
- Posts: 26
- Joined: Wed Jul 21, 2021 3:20 pm
- x 6
- x 2
API Create Closed Spline
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
Go to full postCan 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
- Eddy Alleman
- Posts: 44
- Joined: Thu Apr 01, 2021 10:32 am
- Location: Belgium
- x 79
- x 86
- Contact:
Re: API Create Closed Spline
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
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
-
- Posts: 26
- Joined: Wed Jul 21, 2021 3:20 pm
- x 6
- x 2
Re: API Create Closed Spline
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
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
- Eddy Alleman
- Posts: 44
- Joined: Thu Apr 01, 2021 10:32 am
- Location: Belgium
- x 79
- x 86
- Contact: