Example #1
0
        public void Cmd1()
        {
            var line = new Line(Point3d.Origin - Vector3d.XAxis + Vector3d.YAxis * 2, Point3d.Origin + Vector3d.XAxis + Vector3d.YAxis * 2);


            line.ToSpace();

            var db = Application.DocumentManager.MdiActiveDocument.Database;

            ObjectId styleId = DBHelper.GetSymbol(db.DimStyleTableId, "LL");

            AlignedDimension dimAlign = new AlignedDimension(line.StartPoint, line.EndPoint, Point3d.Origin + Vector3d.YAxis * 1.5, null, styleId);

            dimAlign.ToSpace();
        }
Example #2
0
        public void Cmd2()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            Autodesk.AutoCAD.DatabaseServices.Polyline pyLine = new Autodesk.AutoCAD.DatabaseServices.Polyline();


            var bsPointRes = ed.GetPoint(new PromptPointOptions("\n请输入圆心"));

            if (bsPointRes.Status == PromptStatus.OK)
            {
                pyLine.AddVertexAt(pyLine.NumberOfVertices, new Point2d(bsPointRes.Value.X, bsPointRes.Value.Y), 0, 0, 0);
                var jigPtOpts = new JigPromptPointOptions();

                var dimAlign = new AlignedDimension();

                var donut = new JigHelper();

                donut.SetEntities(new Entity[] { pyLine, dimAlign });

                for (int i = 1; i < int.MaxValue; i++)
                {
                    donut.PrapareForNextInput(jigPtOpts, "\n请输入下一个点");


                    donut.SetUpdate(jig =>
                    {
                        if (pyLine.NumberOfVertices == i)
                        {
                            pyLine.AddVertexAt(pyLine.NumberOfVertices, new Point2d(jig.Point.X, jig.Point.Y), 0, 0, 0);
                        }
                        else
                        {
                            pyLine.SetPointAt(i, new Point2d(jig.Point.X, jig.Point.Y));
                        }

                        Point3d pt1 = pyLine.GetPoint3dAt(i - 1);
                        Point3d pt2 = pyLine.GetPoint3dAt(i);

                        var vec3d  = pt1 - pt2;
                        var vec3d2 = vec3d.RotateBy(Math.PI / 2, Vector3d.ZAxis);



                        Point3d cPoint3d = new Point3d((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2, 0);

                        dimAlign.XLine1Point = pt1;
                        dimAlign.XLine2Point = pt2;

                        dimAlign.DimLinePoint = cPoint3d + vec3d2 * 0.5;

                        dimAlign.DimensionText = null;

                        dimAlign.DimensionStyle = ObjectId.Null;
                    });
                    dimAlign.ToSpace();
                    dimAlign = new AlignedDimension();

                    var status = donut.Drag();
                    if (status == PromptStatus.Cancel)
                    {
                        break;
                    }
                    else if (status != PromptStatus.OK)
                    {
                        return;
                    }
                }

                pyLine.ToSpace();
            }
        }
        private void DimToSpace2(List <Point3d> ptArr, List <Dimension> listDim, Point3d pt1, Point3d wrongPt, int indexPt2)
        {
            RotatedDimension dimOld  = null;
            RotatedDimension dimOld2 = null;
            int indexPt = ptArr.IndexOf(pt1);

            Point3d pt3 = Point3d.Origin;

            if (indexPt < indexPt2)
            {
                pt3 = ptArr[Math.Abs((indexPt2 - 1)) % ptArr.Count];
            }
            else
            {
                pt3 = ptArr[(indexPt2 + 1) % ptArr.Count];
            }
            foreach (var d in listDim)
            {
                if ((d as RotatedDimension) != null)
                {
                    dimOld = d as RotatedDimension;


                    if ((PtEqual(dimOld.XLine1Point, pt1) && PtEqual(dimOld.XLine2Point, wrongPt)) ||
                        (PtEqual(dimOld.XLine1Point, wrongPt) && PtEqual(dimOld.XLine2Point, pt1)))
                    {
                        dimOld = d as RotatedDimension;
                        break;
                    }
                    else
                    {
                        dimOld = null;
                    }
                }
            }

            foreach (var d in listDim)
            {
                if ((d as RotatedDimension) != null)
                {
                    dimOld2 = d as RotatedDimension;


                    if ((PtEqual(dimOld2.XLine1Point, pt3) && PtEqual(dimOld2.XLine2Point, wrongPt)) ||
                        (PtEqual(dimOld2.XLine1Point, wrongPt) && PtEqual(dimOld2.XLine2Point, pt3)))
                    {
                        dimOld2 = d as RotatedDimension;

                        if (dimOld2 != dimOld)
                        {
                            break;
                        }
                        else
                        {
                            dimOld2 = null;
                        }
                    }
                    else
                    {
                        dimOld2 = null;
                    }
                }
            }
            double dimLen = 20d;

            if (null != dimOld)
            {
                var line  = new Line(dimOld.XLine1Point, dimOld.XLine2Point);
                var ptDim = dimOld.DimLinePoint;

                var ptDim2 = line.GetClosestPointTo(ptDim, true);

                var v2 = ptDim - ptDim2;

                dimLen = v2.Length;

                var ptGet = pt1 + v2;

                Vector3d v = pt1 - ptArr[indexPt2];

                //var dimNew = new RotatedDimension(0, pt1, ptArr[indexPt2], ptGet, v.Length.ToString(), dimOld.DimensionStyle);
                var dimNew = new AlignedDimension(pt1, ptArr[indexPt2], ptGet, v.Length.ToString("f2"), dimOld.DimensionStyle);
                Dim2Dim(dimNew, dimOld);
                dimNew.ToSpace();

                using (var trans = Db.TransactionManager.StartTransaction())
                {
                    var ent = trans.GetObject(dimOld.ObjectId, OpenMode.ForWrite) as Entity;

                    ent.Erase(true);

                    trans.Commit();
                }
            }
            if (dimOld2 != null)
            {
                var line  = new Line(dimOld2.XLine1Point, dimOld2.XLine2Point);
                var ptDim = dimOld2.DimLinePoint;

                var ptDim2 = line.GetClosestPointTo(ptDim, true);

                var v2 = ptDim - ptDim2;

                dimLen = v2.Length;

                var      ptGet = ptArr[indexPt2] + v2;
                Vector3d v3    = ptArr[indexPt2] - pt3;
                //var dimNew2 = new RotatedDimension(0, ptArr[indexPt2], pt3, pt4, v3.Length.ToString(), dimOld2.DimensionStyle);
                var dimNew2 = new AlignedDimension(ptArr[indexPt2], pt3, ptGet, v3.Length.ToString("f2"), dimOld2.DimensionStyle);

                Dim2Dim(dimNew2, dimOld2);

                dimNew2.ToSpace();

                using (var trans = Db.TransactionManager.StartTransaction())
                {
                    //var ent = trans.GetObject(dimOld.ObjectId, OpenMode.ForWrite) as Entity;

                    // ent.Erase(true);

                    var ent2 = trans.GetObject(dimOld2.ObjectId, OpenMode.ForWrite) as Entity;

                    ent2.Erase(true);

                    trans.Commit();
                }
            }
        }