public void AddFeature(SldWorks SwApp, ModelDoc2 SwModel, Point2D P1, Point2D P2) { if (CheckUsing() == false) { return; } SwModel.ClearSelection2(true); object[] seating_types = new[] { "None", "Prismatic A", "Prismatic B", "Segmented" }; object[] operations_types = new[] { "None", "Chamfer", "Fillet" }; // array of operation names Helper helper = new Helper(SwModel, SwApp); FeatureManager featureManager = SwModel.FeatureManager; SketchManager sketchManager = SwModel.SketchManager; SelectionMgr selectionMgr = (SelectionMgr)SwModel.SelectionManager; Entity ent = default(Entity); Array facesArray = default(Array); Array edgesArray = default(Array); Feature swFeature = default(Feature); Face2 face2 = default(Face2); // neds to get edges of selected face double LStage = 0; double x_center = 0; double y_center = 0; double L = 0; double W = 0; bool append = false; LStage = P2.x - P1.x; // length of current stage x_center = P1.x + (LStage / 2) + seatingOffset; // center of current stage y_center = 0; L = x_center + seatingLength / 2; W = seatingWidth / 2; SwModel.ClearSelection2(true); #region // make prismatic A keyseat if (seatingType == seating_types[1]) //Prismatic A { helper.select_feature("RefPlane", 1, false, 0); SwModel.CreatePlaneAtOffset(P1.y, false); sketchManager.InsertSketch(true); sketchManager.CreateCenterRectangle(x_center, y_center, 0, L, W, 0); SwModel.FeatureManager.FeatureCut3(true, false, false, 0, 0, seatingDepth, 0, false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true, false, 0, 0, false); // add cut feature if (seatingOpearationType != operations_types[0]) // add chamfer or fillet, if none or value is 0 - pass { swFeature = (Feature)selectionMgr.GetSelectedObject6(1, -1); facesArray = (Array)swFeature.GetFaces(); ent = facesArray.GetValue(0) as Entity; ent.Select4(false, null); if (seatingOpearationType == operations_types[1]) { featureManager.InsertFeatureChamfer(4, 1, seatingChamferFilletValue, helper.ToRad(45), 0, 0, 0, 0); } if (seatingOpearationType == operations_types[2]) { SwModel.FeatureManager.FeatureFillet(195, seatingChamferFilletValue, 0, 0, null, null, null); } swFeature = selectionMgr.GetSelectedObject6(1, -1); swFeature.Select2(false, 4); //create selection for pattern append = true; } CreatePattern(helper, append, SwModel, swFeature, selectionMgr); } #endregion #region // make prismatic B keyseat if (seatingType == seating_types[2]) //Prismatic B { W = seatingWidth; //Width helper.select_feature("RefPlane", 1, false, 0); SwModel.CreatePlaneAtOffset(P1.y, false); sketchManager.InsertSketch(true); sketchManager.CreateSketchSlot((int)swSketchSlotCreationType_e.swSketchSlotCreationType_line, (int)swSketchSlotLengthType_e.swSketchSlotLengthType_CenterCenter, W, L - seatingLength, 0, 0, L, 0, 0, 0, 0, 0, 1, false); SwModel.FeatureManager.FeatureCut3(true, false, false, 0, 0, seatingDepth, 0, false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true, false, 0, 0, false); if (seatingOpearationType != operations_types[0]) // add chamfer or fillet, if none or value is 0 - pass { swFeature = (Feature)selectionMgr.GetSelectedObject6(1, -1); facesArray = (Array)swFeature.GetFaces(); ent = facesArray.GetValue(0) as Entity; ent.Select4(false, null); if (seatingOpearationType == operations_types[1]) { featureManager.InsertFeatureChamfer(4, 1, seatingChamferFilletValue, helper.ToRad(45), 0, 0, 0, 0); } if (seatingOpearationType == operations_types[2]) { SwModel.FeatureManager.FeatureFillet(195, seatingChamferFilletValue, 0, 0, null, null, null); } swFeature = selectionMgr.GetSelectedObject6(1, -1); swFeature.Select2(false, 4); //create selection for pattern append = true; } CreatePattern(helper, append, SwModel, swFeature, selectionMgr); } #endregion #region // make segmented seatkey if (seatingType == seating_types[3]) //Segmented { helper.select_feature("RefPlane", 0, false, 0); sketchManager.InsertSketch(true); sketchManager.Create3PointArc(L - seatingLength, P1.y, 0, L, P1.y, 0, x_center, (P1.y - seatingDepth), 0); sketchManager.CreateLine(L - seatingLength, P1.y, 0, L, P1.y, 0); //close sketsh SwModel.FeatureManager.FeatureCut3(true, false, false, 6, 0, (seatingWidth), 0, false, false, false, false, 0, 0, false, false, false, false, false, true, true, true, true, false, 0, 0, false); //cut from mide plane if (SeatingOpearationType != operations_types[0]) // add chamfer or fillet, if nono or value is 0 - pass { // select edges for chamfering or filleting swFeature = (Feature)selectionMgr.GetSelectedObject6(1, -1); facesArray = (Array)swFeature.GetFaces(); SelectData selectData = selectionMgr.CreateSelectData(); ent = facesArray.GetValue(2) as Entity; ent.Select4(false, selectData); face2 = selectionMgr.GetSelectedObject6(1, -1); edgesArray = (Array)face2.GetEdges(); ent = edgesArray.GetValue(0) as Entity; ent.Select4(false, null); ent = edgesArray.GetValue(2) as Entity; ent.Select4(true, null); // select edges for chamfering or filleting // MessageBox.Show("" + face2.GetEdgeCount()); if (seatingOpearationType == operations_types[1]) { featureManager.InsertFeatureChamfer(4, 1, seatingChamferFilletValue, helper.ToRad(45), 0, 0, 0, 0); } if (seatingOpearationType == operations_types[2]) { SwModel.FeatureManager.FeatureFillet(195, seatingChamferFilletValue, 0, 0, null, null, null); } swFeature = selectionMgr.GetSelectedObject6(1, -1); swFeature.Select2(false, 4); //create selection for pattern append = true; } CreatePattern(helper, append, SwModel, swFeature, selectionMgr); } #endregion helper.HidePlanes(); }