Below is my code where I am getting the solidworks gets crashed.
I have tried different things but for some value of Radius its working fine but for some its not, Or sometime it get crashed for the same value. Here I want this to create multiple circles and extrude cut them.
My program is crashing just after sketch - also sketch looks correct but just after that it crashes the Solidworks.
Log(\\\$"[Dogbone] Starting CreateDogboneCutFeature for {featureName}");
//swApp.SendMsgToUser2("Step 1: Selecting face...",
// (int)swMessageBoxIcon_e.swMbInformation, (int)swMessageBoxBtn_e.swMbOk);
IModelDocExtension mdl_ext = model.Extension;
IEntity entity = (IEntity)face;
bool ok = entity.Select2(false, 0);
if (!ok)
{
double[] pt = GetPointOnFace(face);
ok = mdl_ext.SelectByRay(pt[0], pt[1], pt[2], 0, 0, 1, 0.001,
(int)swSelectType_e.swSelFACES, false, 0, 0);
}
if (!ok)
{
Log("❌ Failed to select face for sketch plane.");
swApp.SendMsgToUser2("Failed to select face. Aborting.",
(int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk);
return null;
}
Log("✅ Face selected successfully.");
//model.GraphicsRedraw2();
SketchManager sketchMgr = model.SketchManager;
FeatureManager featMgr = model.FeatureManager;
IModelView modelView = model.ActiveView;
double[] rect;
rect = null;
sketchMgr.InsertSketch(true);
sketchMgr.AddToDB = true;
sketchMgr.DisplayWhenAdded = false;
foreach (var centerPoint in center_lists)
{
sketchMgr.CreateCircleByRadius(centerPoint[0], centerPoint[1], centerPoint[2], radius);
}
sketchMgr.AddToDB = false;
sketchMgr.InsertSketch(true); // exit sketch
sketchMgr.DisplayWhenAdded = true;
//modelView.GraphicsRedraw(rect);
// --- Create cut ---
//Feature cutFeat = null;
Feature cutFeat = featMgr.FeatureCut4(true, false, false, (int)swEndConditions_e.swEndCondBlind, 0, cutDepth, 0.01, false, false, false, false, 1, 1, false, false, false, false, false, true, true, true, true, false, (int)swStartConditions_e.swStartSketchPlane, 0, false, false);
if (cutFeat == null)
{
Log("❌ FeatureCut4 failed to create cut feature.");
swApp.SendMsgToUser2("FeatureCut4 failed — check Output window and model visually.",
(int)swMessageBoxIcon_e.swMbStop, (int)swMessageBoxBtn_e.swMbOk);
return null;
}
cutFeat.Name = featureName;
//model.EditRebuild3();
//model.GraphicsRedraw2();
model.ClearSelection2(true);
