So, i've got a bit of code that is placing points in a sketch that is consumed by a hole wizard. The hole wizard is already created and I have programmatically 'gone back into the sketch' to add more points. This all works great.
Now, I'm trying to take advantage of the 'fullyDefinSketch' method. I begin editing the sketch, select all the points in the sketch, clear the selection list, select the origin, try to 'fully define the sketch', watch it crash.
Does anyone have any idea what the problem is? Here's the code snippet
'clearing the selection list
swModel.ClearSelection2(True)
'selecting the sketch I want to edit
bool = swModel.Extension.SelectByID2(sketchname, "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
'editing the sketch
swModel.EditSketch()
'clearing the selection list
swModel.ClearSelection2(True)
'getting all the points in the sketch
vSkSegArr = swSketch.GetSketchPoints2
'looping through the points in the sketch and selecting each one.
'I do this is based on a successful macro I recorded
For Each ob As Object In vSkSegArr
Dim sPoint As SketchPoint = ob
sPoint.Select(True)
Next
'clearing the selection list again. Again, because the recorded macro said to do it
swModel.ClearSelection2(True)
'selecting the origin so I can assign it a marker of 6
bool = swModel.Extension.SelectByID2("Point1@Origin@" & EditedPart.Name & "@" & Path.GetFileNameWithoutExtension(swModel.GetPathName), "EXTSKETCHPOINT", 0, 0, 0, True, 6, Nothing, 0)
Dim result As Long
Dim hDatumObj As Object = Nothing
Dim vDatumObj As Object = Nothing
Try
'______________________________________________
'
'this is where the code crashes. It crashes so hard that my try-catch block can't even catch it!
'
result = swModel.SketchManager.FullyDefineSketch(True, True, 1023, True, 3, hDatumObj, 3, vDatumObj, -1, -1)
'
'result -KABOOM!!!!!
'
Catch ex As Exception
MsgBox(ex.ToString)
End Try
SolidworksApi macros