Why do you use solidworks.interop.sldworks.feature instead of just SldWorks.Feature? The same for the other three variables? From what I understand it is required when you want to start SolidWorks from another application. Is that what you're doing?
Can you comment out sections or replace then with hardcoded lines to keep the error from appearing?
From what I read here you need to define a Sketch Manager variable first and use that one to add a sketch with. Like in swSketchManager.Insert3DSketch. You're using the model doc to add a sketch to, that method is now obsolete.
This code is ok
I added loop to your code to insert 100x 3D sketches and nothing crashed.
Check the way you attached to SolidWorks. Is there a chance that the memory could be cleaned and some variables (like model) could be set back to nothing or overwritten by another command in the code?
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Dim swFeat As Feature
Dim swSkPoint1 As SketchPoint
Dim swSkPoint2 As SketchPoint
Dim swSkLine As SketchLine
Dim bRet As Boolean
Dim i As Integer
For i = 0 To 100
Dim P1x As Double: P1x = 0
Dim P1y As Double: P1y = i * 0.1
Dim P1z As Double: P1z = 0
Dim P2x As Double: P2x = 0.1 + i * 0.1
Dim P2y As Double: P2y = i * 0.1
Dim P2z As Double: P2z = 0
Set swSkPoint1 = swModel.CreatePoint2(P1x, P1y, P1z)
Set swSkPoint2 = swModel.CreatePoint2(P2x, P2y, P2z)
Set swSkLine = swModel.CreateLine2(P1x, P1y, P1z, P2x, P2y, P2z)
Set TempSketch = swModel.GetActiveSketch2
Set swFeat = TempSketch
swFeat.Name = "DispMeaSketch_" & i
bRet = swModel.EditRebuild3
Viktor, fantastic job and I really appreciate all of your previous help. In the current version of the project Solidworks is attached "dynamically". For awhile, there were some significant problems but they seem to be straightened out. Given some of the battles, I would agree that the "attachment" is a strong potential candidate. However, in the previous sets (before the dynamic attachment) and the attachment was clean, the crashing was happening within the about 10 manual processes.
I really appreciate your help. From your feedback I tried the following code, which hasn't crashed SW yet (fairly minimal testing):
Dim swSketchMgr As SketchManager = swModel.SketchManager
Dim swSketchSegment As SketchSegment
swSketchMgr.CreatePoint(P1x, P1y, P1z)
swSketchMgr.CreatePoint(P2x, P2y, P2z)
swSketchSegment = swSketchMgr.CreateLine(P1x, P1y, P1z, P2x, P2y, P2z)
TempSketch = swModel.GetActiveSketch2
swFeat = TempSketch
swFeat.Name = "DispMeaSketch"
This codes uses SketchManager and apparently doesn't need a few of the lines that were previously used. Hopefully, this will keep working.