예제 #1
0
        void dimension(double value, string text = "")
        {
            DisplayDimension dispDim = Model.AddDimension2(0, 10 * mm, 10 * mm);

            string name = dispDim.GetNameForSelection();

            dispDim.CenterText = true;

            Dimension Dim = Dimensions[iDimensions++] = Model.Parameter(name);

            if (text != "")
            {
                Dim.Name = text;
            }
            Dim.SystemValue = value * mm;
        }
예제 #2
0
        //позиционирование скетча по середине
        public void SketchToCenter(int indexSketch)
        {
            swDoc.Extension.SelectByID2("Point26", "SKETCHPOINT", 0, 0, 0, false, 0, null, 0);
            swDoc.Extension.SelectByID2("Point1@Исходная точка", "EXTSKETCHPOINT", 0, 0, 0, true, 0, null, 0);
            swDoc.AddDimension2(0, 0, 0);
            var dimension = swDoc.Parameter("D2@Эскиз" + (indexSketch + 2).ToString());

            dimension.SystemValue = 0.01;
        }
예제 #3
0
        public void makeDimensions(ModelDoc2 swModel)
        {
            foreach (string[] list in pack)
            {
                swModel.ClearSelection2(true);

                for (int i = 6; i < list.Length; i++)
                {
                    SmartTools.SelectByID(swModel, list[i]);
                }

                swModel.AddDimension2(Convert.ToDouble(list[3]), Convert.ToDouble(list[4]), Convert.ToDouble(list[5]));
            }
        }
예제 #4
0
        public static void DimensionWith(this SketchLine l1, SketchLine l2, double value, string linkName, SldWorks swApp)
        {
            ModelDoc2 swDoc = (ModelDoc2)swApp.ActiveDoc;
            bool      bl    = false;

            swDoc.ClearSelection2(true);

            bl = ((SketchSegment)l1).Select(false);
            bl = ((SketchSegment)l2).Select(true);

            Point textPoint = new Point((l1.toLine().Start.X + l2.toLine().Start.X) / 2,
                                        (l1.toLine().Start.Y + l2.toLine().Start.Y) / 2,
                                        (l1.toLine().Start.Z + l2.toLine().Start.Z) / 2);

            swDoc.AddDimension2(textPoint.X, textPoint.Y, 0);

            swDoc.ClearSelection2(true);
        }
예제 #5
0
        public static void DimensionWith(this SketchLine l1, SketchLine l2, string linkName, SldWorks swApp)
        {
            ModelDoc2 swDoc = (ModelDoc2)swApp.ActiveDoc;
            bool      bl    = false;

            swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate,
                                          false);
            swDoc.ClearSelection2(true);

            bl = ((SketchSegment)l1).Select(false);
            bl = ((SketchSegment)l2).Select(true);

            Point textPoint = new Point((l1.toLine().Start.X + l2.toLine().Start.X) / 2,
                                        (l1.toLine().Start.Y + l2.toLine().Start.Y) / 2,
                                        (l1.toLine().Start.Z + l2.toLine().Start.Z) / 2);

            DisplayDimension disDim = swDoc.AddDimension2(textPoint.X, textPoint.Y, 0);

            disDim.SetLinkedText("" + linkName + "");

            swDoc.ClearSelection2(true);
            swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swInputDimValOnCreate,
                                          true);
        }
예제 #6
0
        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);
        }
예제 #7
0
        public static void AddConstraintAndDim(ModelDoc2 SketchDoc)
        {
            SketchManager SwSketchMrg = SketchDoc.SketchManager;//获得SketchManager对象

            SketchDoc.Extension.SelectByID2("前视基准面", "PLANE", 0, 0, 0, false, 0, null, 0);
            SwSketchMrg.InsertSketch(true);//进入编辑草图模式
            object[]      ObjRectangle = SwSketchMrg.CreateCenterRectangle(0, 0, 0, 0.075, 0.04, 0);
            SketchSegment SktCircle1   = SwSketchMrg.CreateCircle(-0.0425, 0, 0, -0.03, 0, 0);
            SketchSegment SktCircle2   = SwSketchMrg.CreateCircle(0.0425, 0, 0, 0.03, 0, 0);
            SketchSegment SktCentLine  = SwSketchMrg.CreateCenterLine(0, 0.04, 0, 0, -0.04, 0);

            #region 两个圆心添加水平
            SketchDoc.ClearSelection2(true);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", -0.0425, 0, 0, true, 0, null, 0);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", 0.0425, 0, 0, true, 0, null, 0);
            SketchDoc.SketchAddConstraints("sgHORIZONTALPOINTS2D");
            #endregion

            #region 两个圆心添加对称
            SketchDoc.ClearSelection2(true);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", -0.0425, 0, 0, true, 0, null, 0);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", 0.0425, 0, 0, true, 0, null, 0);
            SktCentLine.Select(true);
            SketchDoc.SketchAddConstraints("sgSYMMETRIC");
            #endregion

            #region 圆心与坐标原点水平
            SketchDoc.ClearSelection2(true);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", -0.0425, 0, 0, true, 0, null, 0);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", 0, 0, 0, true, 0, null, 0);
            SketchDoc.SketchAddConstraints("sgHORIZONTALPOINTS2D");
            #endregion

            #region 添加孔间距尺寸
            SketchDoc.ClearSelection2(true);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", -0.0425, 0, 0, true, 0, null, 0);
            SketchDoc.Extension.SelectByID2("", "SKETCHPOINT", 0.0425, 0, 0, true, 0, null, 0);
            SketchDoc.AddDimension2(0, 0.05, 0);
            #endregion

            #region 两个圆添加相同大小
            SktCircle1.Select(false);
            SktCircle2.Select(true);
            SketchDoc.SketchAddConstraints("sgSAMELENGTH");
            #endregion

            #region 添加圆尺寸
            SktCircle1.Select(false);
            SketchDoc.AddDimension2(-0.02, 0.02, 0);
            #endregion

            #region 添加矩形长
            SketchDoc.Extension.SelectByID2("", "SKETCHSEGMENT", -0.02, 0.04, 0, false, 0, null, 0);
            SketchDoc.AddDimension2(0, 0.07, 0);
            #endregion

            #region 添加矩形高
            SketchDoc.Extension.SelectByID2("", "SKETCHSEGMENT", 0.075, 0, 0, false, 0, null, 0);
            SketchDoc.AddDimension2(0.09, 0, 0);
            #endregion

            SwSketchMrg.InsertSketch(true);//退出编辑草图模式
        }