Can you share your code?
You could prevent crashes by adding lines like the following:
On Error GoTo LabelX
code that can cause an error
Label you jump to when an error occurs.
We might be able to prevent the error from happening altogether though
Here is the relevant code:
Dim swApp As Object
Set swApp = Application.SldWorks
Dim swModel As SldWorks.IModelDoc2
Set swModel = swApp.ActiveDoc
Dim swPart As SldWorks.IPartDoc
Set swPart = swModel
Dim body As IBody2
Set body = swPart.ICreateNewBody2
Dim Props(7) As Integer
Dim UKnots(5) As Double
Dim VKnots(5) As Double
Dim CtrlPtCoords(26) As Double
Props(0) = 3
Props(7) = 0
UKnots(0) = 0#
UKnots(5) = 1#
VKnots(0) = 0#
VKnots(5) = 1#
CtrlPtCoords(0) = 0#
CtrlPtCoords(26) = 0#
Dim surface As ISurface
Set surface = body.ICreateBsplineSurface(Props, UKnots, VKnots, CtrlPtCoords) LINE CAUSING ERROR
The error is happening on pretty much the most important line in the program, and always gives an Access Violation Error.
Crash occurs on SW16 and 17 when there is a part open, without a part open there is a different error relating to the activeDoc line, which makes sense.
You could start by changing IPart to Part etc for all objects, otherwise you are apparently defining interfaces instead of objects.
You might also need some checks to make sure that "body" is not nothing. If it is, you shouldn't perform any actions on it. The same holds for parts, you can check the type before setting swPart equal to swModel.
Regarding the parameters, they can be messy sometimes. Certainly when the help says something like "These are integers packed into a double array", while it is supposed to be an object. An example would really help there, because I also don't know exactly what to feed this function. I might try creating an array and copying it to an object before passing it as a parameter.
After changing the interfaces to objects and doing some checks, it looks like the issue is in how I am passing the data to the function. Will look at more next week. :/
Side note: I only really need to get raw nurb data into solidworks, I don't care how I do it. Saving to IGES and 3DM didn't work as well as I would have hoped, but if anyone has suggestions in general for this, that would be greatly appreciated.
I tried the same. It just crashes on the troubled line, even my error handling doesn't catch it. It would have been nice if they would make a function a little more robust when it is so hard to create a set of proper parameters.
I have no idea how to create a set of parameters that should work. There are a few forum questions about this function, but no real answers. I haven't worked with either splines or surfaces, so that makes it harder I also couldn't find a button to create such a surface in the GUI, so it's unclear to me what it should do exactly. If there is a button available, maybe we can record an example.