//画第二个草图,中点重合即可. private Feature DrawnSketchOnFace(ModelDoc2 swModel, double[] mousePoint, string SketchName, Entity swSelFaceEntity) { swModel.SketchManager.InsertSketch(true); //通过两条相邻边来标注 创建点的位置 //1。 计算鼠标选中点到面的各边的距离。 //Dictionary<Edge, double> pointToEdgeDim = new Dictionary<Edge, double>(); var selMousePt = (double[])TransformPoint(swModel.IGetActiveSketch2(), mousePoint[0], mousePoint[1], mousePoint[2]); swModel.SketchManager.CreateCenterRectangle(selMousePt[0], selMousePt[1], selMousePt[2], selMousePt[0] + 0.03, selMousePt[1] + 0.03, selMousePt[2]); swModel.ClearSelection2(true); swModel.Extension.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, false, 0, null, 0); swModel.Extension.SelectByID2("Point1@" + SketchName, "EXTSKETCHPOINT", 0, 0, 0, true, 0, null, 0); swModel.SketchAddConstraints("sgCOINCIDENT");//增加重合 var skFeature = (Feature)swModel.IGetActiveSketch2(); swModel.SketchManager.InsertSketch(true); var boolstatus = swModel.InsertPlanarRefSurface(); ISelectionMgr swSelMgr = (ISelectionMgr)swModel.SelectionManager; skFeature = (Feature)swSelMgr.GetSelectedObject6(1, 0);// swModel.FeatureByPositionReverse(0); return(skFeature); //skFeature = swModel.FeatureByPositionReverse(0); //return skFeature; }
private Feature DrawnSketchOnFace(ModelDoc2 swModel, double[] mousePoint, List <Edge> thisFaceEdgeList, Entity swSelFaceEntity, out string sketchName) { swModel.SketchManager.InsertSketch(true); //通过两条相邻边来标注 创建点的位置 //1。 计算鼠标选中点到面的各边的距离。 List <FaceEdgeInfos> faceEdgeInfor = new List <FaceEdgeInfos>(); //Dictionary<Edge, double> pointToEdgeDim = new Dictionary<Edge, double>(); var selMousePt = (double[])TransformPoint(swModel.IGetActiveSketch2(), mousePoint[0], mousePoint[1], mousePoint[2]); foreach (var item in thisFaceEdgeList) { var tStart = (Vertex)item.GetStartVertex(); var pstart = (double[])tStart.GetPoint(); var tEnd = (Vertex)item.GetEndVertex(); var pend = (double[])tEnd.GetPoint(); pstart = (double[])TransformPoint(swModel.IGetActiveSketch2(), pstart[0], pstart[1], pstart[2]); pend = (double[])TransformPoint(swModel.IGetActiveSketch2(), pend[0], pend[1], pend[2]); var angleOfLine = Math.Atan2((pend[1] - pstart[1]), (pend[0] - pstart[0])) * 180 / Math.PI; double tempChuizuX = 0; double tempChuizuY = 0; //垂足的坐标位置 var tempchuizu = Geometry2D.GetPerpendicular(selMousePt[0], selMousePt[1], pend[0], pend[1], pstart[0], pstart[1]); tempChuizuX = tempchuizu[0]; tempChuizuY = tempchuizu[1]; faceEdgeInfor.Add(new FaceEdgeInfos(item, Geometry2D.pointToLine(pstart[0], pstart[1], pend[0], pend[1], selMousePt[0], selMousePt[1]), angleOfLine, Geometry2D.lineSpace(pstart[0], pstart[1], pend[0], pend[1]), tempChuizuX, tempChuizuY)); //pointToEdgeDim.Add(item, pointToLine(pstart[0], pstart[1], pend[0], pend[1], mousePoint[0], mousePoint[1])); } //把所有的边按距离排序 var EdgeInfosOrderByDim = faceEdgeInfor.OrderBy(x => x.dim).ToList(); //最近的一条边 var minEdgeObject = EdgeInfosOrderByDim[0]; //下一条相临的边 FaceEdgeInfos nextMinEdga = null; for (int i = 1; i < EdgeInfosOrderByDim.Count; i++) { if (Math.Abs(EdgeInfosOrderByDim[i].Angle) != 180 - Math.Abs(minEdgeObject.Angle) && EdgeInfosOrderByDim[i].Angle != minEdgeObject.Angle) { nextMinEdga = EdgeInfosOrderByDim[i]; break; } } // var eNextEdge = faceEdgeInfoses.Find(x => ((Vertex)x.edge.GetStartVertex()).GetPoint() == ((Vertex)minEdgeObject.GetEndVertex()).GetPoint()); var minEdge = (Entity)minEdgeObject.edge; var nextminEdge = (Entity)nextMinEdga.edge; swModel.ClearSelection(); //MessageBox.Show("done"); swSelFaceEntity.Select(false); // var actSketch = swModel.SketchManager.ActiveSketch; ////把鼠标点坐标转换到草图中 //var selMousePt = (double[])TransformPoint(swModel.IGetActiveSketch2(), mousePoint[0], mousePoint[1], mousePoint[2]); swModel.SketchManager.CreateCenterRectangle(selMousePt[0], selMousePt[1], selMousePt[2], selMousePt[0] + 0.03, selMousePt[1] + 0.03, selMousePt[2]); swModel.ClearSelection2(true); swModel.Extension.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, false, 0, null, 0); minEdge.Select(true); // var thisDim = (DisplayDimension)swModel.AddDimension2(selMousePt[0], selMousePt[1], selMousePt[2]); var thisDim = (DisplayDimension)swModel.AddDimension2(minEdgeObject.chuizuPoint_X, minEdgeObject.chuizuPoint_Y, 0); thisDim.GetDimension2(0).SystemValue = Math.Round(minEdgeObject.dim * 1000, 0) / 1000; //第二个方向尺寸 swModel.ClearSelection2(true); swModel.Extension.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, false, 0, null, 0); nextminEdge.Select(true); //var nextthisDim = (DisplayDimension)swModel.AddDimension2(selMousePt[0], selMousePt[1], selMousePt[2]); var nextthisDim = (DisplayDimension)swModel.AddDimension2(nextMinEdga.chuizuPoint_X, nextMinEdga.chuizuPoint_Y, 0); nextthisDim.GetDimension2(0).SystemValue = Math.Round(nextMinEdga.dim * 1000, 0) / 1000; string featName = null; string featType = null; var skFeature = (Feature)swModel.IGetActiveSketch2(); featName = skFeature.GetNameForSelection(out featType); sketchName = featName; swModel.SketchManager.InsertSketch(true); swModel.Extension.SelectByID2(sketchName, "SKETCH", 0, 0, 0, false, 1, null, 0); var boolstatus = swModel.InsertPlanarRefSurface(); ISelectionMgr swSelMgr = (ISelectionMgr)swModel.SelectionManager; skFeature = (Feature)swSelMgr.GetSelectedObject6(1, 0);// swModel.FeatureByPositionReverse(0); return(skFeature); }