예제 #1
0
        // 由圆心、两条尺寸界线原点、尺寸文本位置、尺寸文本和标注样式创建弧长标注的函数.
        public static ObjectId AddDimArc(Point3d cenPt, Point3d pt1, Point3d pt2, Point3d arcPt, string text, ObjectId style)
        {
            ArcDimension ent   = new ArcDimension(cenPt, pt1, pt2, arcPt, text, style);
            ObjectId     entId = AppendEntity(ent);

            return(entId);
        }
예제 #2
0
        public static ObjectId AddDimArc(Point3d cenPt, Point3d pt1, Point3d pt2, Point3d arcPt)
        {
            Database     workingDatabase = HostApplicationServices.WorkingDatabase;
            ObjectId     dimstyle        = workingDatabase.Dimstyle;
            Vector3d     vectorTo        = cenPt.GetVectorTo(pt1);
            Vector3d     vectorTo2       = cenPt.GetVectorTo(pt2);
            double       angleTo         = vectorTo.GetAngleTo(vectorTo2);
            double       num             = cenPt.DistanceTo(pt1);
            double       value           = angleTo * num;
            string       text            = Conversions.ToString(Math.Round(value, workingDatabase.Dimdec));
            ArcDimension ent             = new ArcDimension(cenPt, pt1, pt2, arcPt, text, dimstyle);

            return(ModelSpace.AddEnt(ent));
        }
예제 #3
0
        // 由圆心、两条尺寸界线原点和尺寸文本位置创建弧长标注的函数.
        public static ObjectId AddDimArc(Point3d cenPt, Point3d pt1, Point3d pt2, Point3d arcPt)
        {
            Database     db        = HostApplicationServices.WorkingDatabase;
            ObjectId     style     = db.Dimstyle;
            Vector3d     vec1      = cenPt.GetVectorTo(pt1);
            Vector3d     vec2      = cenPt.GetVectorTo(pt2);
            double       ang       = vec1.GetAngleTo(vec2);
            double       radius    = cenPt.DistanceTo(pt1);
            double       arcLength = ang * radius;
            string       text      = (Math.Round(arcLength, db.Dimdec)).ToString();
            ArcDimension ent       = new ArcDimension(cenPt, pt1, pt2, arcPt, text, style);
            ObjectId     entId     = AppendEntity(ent);

            return(entId);
        }
예제 #4
0
    public crawlAcDbArcDimension(ArcDimension dim)
    {
        Entity ent = (Entity)dim;

        this.ObjectId = ent.ObjectId.ToString();

        this.XLine1Point  = new crawlPoint3d(dim.XLine1Point.X, dim.XLine1Point.Y, dim.XLine1Point.Z);
        this.XLine2Point  = new crawlPoint3d(dim.XLine2Point.X, dim.XLine2Point.Y, dim.XLine2Point.Z);
        this.ArcPoint     = new crawlPoint3d(dim.ArcPoint.X, dim.ArcPoint.Y, dim.ArcPoint.Z);
        this.TextPosition = new crawlPoint3d(dim.TextPosition.X, dim.TextPosition.Y, dim.TextPosition.Z);

        this.Layer      = dim.Layer;
        this.Linetype   = dim.Linetype;
        this.LineWeight = dim.LineWeight.ToString();
        this.Color      = dim.Color.ToString();

        this.DimensionText      = dim.DimensionText;
        this.DimensionStyleName = dim.DimensionStyleName;
    }
예제 #5
0
        private string jsonGetObjectData(ObjectId id_platf)
        {
            string result = "";

            try
            {//Всякое может случиться
                //Открываем переданный в функцию объект на чтение, преобразуем его к Entity
                Entity ent = (Entity)id_platf.GetObject(OpenMode.ForRead);

                //Далее последовательно проверяем класс объекта на соответствие классам основных примитивов

                if (id_platf.ObjectClass.Name == "AcDbLine")
                {                                                       //Если объект - отрезок (line)
                    crawlAcDbLine kline = new crawlAcDbLine((Line)ent); //Преобразуем к типу линия
                    result = jsonHelper.To <crawlAcDbLine>(kline);
                }
                else if (id_platf.ObjectClass.Name == "AcDbPolyline")
                {//Если объект - полилиния
                    Polyline          kpLine = (Polyline)ent;
                    crawlAcDbPolyline jpline = new crawlAcDbPolyline(kpLine);
                    result = jsonHelper.To <crawlAcDbPolyline>(jpline);
                }
                else if (id_platf.ObjectClass.Name == "AcDb2dPolyline")
                {//2D полилиния - такие тоже попадаются
                    Polyline2d        kpLine = (Polyline2d)ent;
                    crawlAcDbPolyline jpline = new crawlAcDbPolyline(kpLine);
                    result = jsonHelper.To <crawlAcDbPolyline>(jpline);
                }
                else if (id_platf.ObjectClass.Name == "AcDb3dPolyline")
                {//2D полилиния - такие тоже попадаются
                    Polyline3d kpLine = (Polyline3d)ent;

                    crawlAcDbPolyline jpline = new crawlAcDbPolyline(kpLine);
                    result = jsonHelper.To <crawlAcDbPolyline>(jpline);
                }
                else if (id_platf.ObjectClass.Name == "AcDbText")
                { //Текст
                    DBText        dbtxt = (DBText)ent;
                    crawlAcDbText jtext = new crawlAcDbText(dbtxt);
                    result = jsonHelper.To <crawlAcDbText>(jtext);
                }
                else if (id_platf.ObjectClass.Name == "AcDbMText")
                {//Мтекст
                    MText          mtxt  = (MText)ent;
                    crawlAcDbMText jtext = new crawlAcDbMText(mtxt);
                    result = jsonHelper.To <crawlAcDbMText>(jtext);
                }
                else if (id_platf.ObjectClass.Name == "AcDbArc")
                {//Дуга
                    Arc          arc  = (Arc)ent;
                    crawlAcDbArc cArc = new crawlAcDbArc(arc);
                    result = jsonHelper.To <crawlAcDbArc>(cArc);
                }
                else if (id_platf.ObjectClass.Name == "AcDbCircle")
                {//Окружность
                    Circle          circle  = (Circle)ent;
                    crawlAcDbCircle cCircle = new crawlAcDbCircle(circle);
                    result = jsonHelper.To <crawlAcDbCircle>(cCircle);
                }
                else if (id_platf.ObjectClass.Name == "AcDbEllipse")
                {  //Эллипс
                    Ellipse          el   = (Ellipse)ent;
                    crawlAcDbEllipse cEll = new crawlAcDbEllipse(el);
                    result = jsonHelper.To <crawlAcDbEllipse>(cEll);
                }
                else if (id_platf.ObjectClass.Name == "AcDbAlignedDimension")
                {//Размер повернутый
                    AlignedDimension dim = (AlignedDimension)ent;

                    crawlAcDbAlignedDimension rDim = new crawlAcDbAlignedDimension(dim);
                    result = jsonHelper.To <crawlAcDbAlignedDimension>(rDim);
                }

                else if (id_platf.ObjectClass.Name == "AcDbRotatedDimension")
                {//Размер повернутый
                    RotatedDimension dim = (RotatedDimension)ent;

                    crawlAcDbRotatedDimension rDim = new crawlAcDbRotatedDimension(dim);
                    result = jsonHelper.To <crawlAcDbRotatedDimension>(rDim);
                }

                else if (id_platf.ObjectClass.Name == "AcDbPoint3AngularDimension")
                {//Угловой размер по 3 точкам
                    Point3AngularDimension dim = (Point3AngularDimension)ent;

                    crawlAcDbPoint3AngularDimension rDim = new crawlAcDbPoint3AngularDimension(dim);
                    result = jsonHelper.To <crawlAcDbPoint3AngularDimension>(rDim);
                }

                else if (id_platf.ObjectClass.Name == "AcDbLineAngularDimension2")
                {//Еще угловой размер по точкам
                    LineAngularDimension2 dim = (LineAngularDimension2)ent;

                    crawlAcDbLineAngularDimension2 rDim = new crawlAcDbLineAngularDimension2(dim);
                    result = jsonHelper.To <crawlAcDbLineAngularDimension2>(rDim);
                }
                else if (id_platf.ObjectClass.Name == "AcDbDiametricDimension")
                {  //Размер диаметра окружности
                    DiametricDimension          dim  = (DiametricDimension)ent;
                    crawlAcDbDiametricDimension rDim = new crawlAcDbDiametricDimension(dim);
                    result = jsonHelper.To <crawlAcDbDiametricDimension>(rDim);
                }
                else if (id_platf.ObjectClass.Name == "AcDbArcDimension")
                {  //Дуговой размер
                    ArcDimension          dim  = (ArcDimension)ent;
                    crawlAcDbArcDimension rDim = new crawlAcDbArcDimension(dim);
                    result = jsonHelper.To <crawlAcDbArcDimension>(rDim);
                }
                else if (id_platf.ObjectClass.Name == "AcDbRadialDimension")
                {  //Радиальный размер
                    RadialDimension          dim  = (RadialDimension)ent;
                    crawlAcDbRadialDimension rDim = new crawlAcDbRadialDimension(dim);
                    result = jsonHelper.To <crawlAcDbRadialDimension>(rDim);
                }
                else if (id_platf.ObjectClass.Name == "AcDbAttributeDefinition")
                {  //Атрибут блока
                    AttributeDefinition ad = (AttributeDefinition)ent;

                    crawlAcDbAttributeDefinition atd = new crawlAcDbAttributeDefinition(ad);
                    result = jsonHelper.To <crawlAcDbAttributeDefinition>(atd);
                }
                else if (id_platf.ObjectClass.Name == "AcDbHatch")
                {//Штриховка
                    Teigha.DatabaseServices.Hatch htch = ent as Teigha.DatabaseServices.Hatch;

                    crawlAcDbHatch cHtch = new crawlAcDbHatch(htch);
                    result = jsonHelper.To <crawlAcDbHatch>(cHtch);
                }
                else if (id_platf.ObjectClass.Name == "AcDbSpline")
                {//Сплайн
                    Spline spl = ent as Spline;

                    crawlAcDbSpline cScpline = new crawlAcDbSpline(spl);
                    result = jsonHelper.To <crawlAcDbSpline>(cScpline);
                }
                else if (id_platf.ObjectClass.Name == "AcDbPoint")
                {//Точка
                    DBPoint        Pnt = ent as DBPoint;
                    crawlAcDbPoint pt  = new crawlAcDbPoint(Pnt);
                    result = jsonHelper.To <crawlAcDbPoint>(pt);
                }

                else if (id_platf.ObjectClass.Name == "AcDbBlockReference")
                {//Блок
                    BlockReference          blk  = ent as BlockReference;
                    crawlAcDbBlockReference cBlk = new crawlAcDbBlockReference(blk);

                    result = jsonHelper.To <crawlAcDbBlockReference>(cBlk);

                    //newDocument(id_platf, result);
                }
                else if (id_platf.ObjectClass.Name == "AcDbProxyEntity")
                {//Прокси
                    ProxyEntity pxy = ent as ProxyEntity;


                    crawlAcDbProxyEntity cBlk = new crawlAcDbProxyEntity(pxy);

                    result = jsonHelper.To <crawlAcDbProxyEntity>(cBlk);

                    DocumentFromBlockOrProxy(id_platf, result);
                }
                else if (id_platf.ObjectClass.Name == "AcDbSolid")
                {//Солид 2Д
                    Solid solid = (Solid)ent;


                    crawlAcDbSolid cSld = new crawlAcDbSolid(solid);

                    result = jsonHelper.To <crawlAcDbSolid>(cSld);
                }

                /*
                 *
                 *
                 * else if (id_platf.ObjectClass.Name == "AcDbLeader")
                 * {  //Выноска Autocad
                 * Leader ld = (Leader)ent;
                 *
                 * if (ld.EndPoint.Z != 0 || ld.StartPoint.Z != 0)
                 * {
                 * //ed.WriteMessage("DEBUG: Преобразован объект: Выноска Autocad");
                 *
                 * ld.EndPoint = new Point3d(ld.EndPoint.X, ld.EndPoint.Y, 0);
                 * ld.StartPoint = new Point3d(ld.StartPoint.X, ld.StartPoint.Y, 0);
                 *
                 * result = true;
                 * };
                 *
                 * }
                 * /*
                 * else if (id_platf.ObjectClass.Name == "AcDbPolygonMesh")
                 * {
                 * BUG: В платформе нет API для доступа к вершинам сетей AcDbPolygonMesh и AcDbPolygonMesh и AcDbSurface
                 *
                 * }
                 * else if (id_platf.ObjectClass.Name == "AcDbSolid")
                 * {
                 * BUG: Чтобы плющить Solid-ы нужны API функции 3d
                 * }
                 * else if (id_platf.ObjectClass.Name == "AcDbRegion")
                 * {
                 * Region rgn = ent as Region;
                 * BUG: нет свойств у региона
                 * }
                 *
                 */
                else
                {
                    //Если объект не входит в число перечисленных типов,
                    //то выводим в командную строку класс этого необработанного объекта

                    cDebug.WriteLine("Не могу обработать тип объекта: " + id_platf.ObjectClass.Name);
                }
            }
            catch (System.Exception ex)
            {
                //Если что-то сломалось, то в командную строку выводится ошибка
                cDebug.WriteLine("Не могу преобразовать - ошибка: " + ex.Message);
            };

            //Возвращаем значение функции
            return(result);
        }
예제 #6
0
        private void MyMirror(List <Entity> listEnt, Line line, string xY)
        {
            if (listEnt == null || line == null)
            {
                return;
            }

            Line3d line3d = new Line3d(line.StartPoint, line.EndPoint);

            for (int i = 0; i < listEnt.Count; i++)
            {
                var entity = listEnt[i];

                Entity ent = entity;

                //if((ent as Dimension) != null)
                //{
                //    continue;
                //}


                if (ent is DBText || ent is MText)
                {
                    listOId.Add(ent.ToSpace(blkRef.Database));
                }
                else
                {
                    ent = entity.GetTransformedCopy(Matrix3d.Mirroring(line3d));

                    if ((ent as Dimension) == null)
                    {
                        list.Add(ent);
                    }

                    //continue;
                }

                /* var ptMin = ent.Bounds.Value.MinPoint;
                 *
                 * var ptMax = ent.Bounds.Value.MaxPoint;
                 *
                 * var w = Math.Abs(ptMax.X - ptMin.X);
                 * var h = Math.Abs(ptMax.Y - ptMin.Y);
                 *
                 * var ptCenter = new Point3d((ptMin.X + ptMax.X) / 2, (ptMin.Y + ptMax.Y) / 2, 0);*/
                if (ent is DBText)
                {
                    var a = ent as DBText;
                    MirrorText(a, line3d);
                }
                else if (ent is MText)
                {
                    var a = ent as MText;

                    MirrorText(a, line3d);
                }
                else if ((ent as Dimension) != null)
                {
                    var dim = ent as Dimension;



                    Plane p = null;

                    if (xY == "X")
                    {
                        p   = new Plane(dim.TextPosition, dim.Normal);
                        ent = dim.GetTransformedCopy(Matrix3d.Mirroring(p));
                    }
                    else if (xY == "Y")
                    {
                        p = new Plane(dim.TextPosition, dim.Normal);

                        ent = dim.GetTransformedCopy(Matrix3d.Mirroring(p));
                    }
                    if (ent is RotatedDimension)
                    {
                        var rDim = ent as RotatedDimension;

                        var rDim1 = new RotatedDimension(rDim.Rotation, rDim.XLine1Point, rDim.XLine2Point, rDim.DimLinePoint, rDim.DimensionText, rDim.DimensionStyle);
                        Dim2Dim(rDim1, rDim);
                        list.Add(rDim1);
                    }

                    else if (ent is AlignedDimension)
                    {
                        var rDim = ent as AlignedDimension;

                        var rDim1 = new AlignedDimension(rDim.XLine1Point, rDim.XLine2Point, rDim.DimLinePoint, rDim.DimensionText, rDim.DimensionStyle);
                        Dim2Dim(rDim1, rDim);
                        list.Add(rDim1);
                    }
                    else if (ent is ArcDimension)
                    {
                        var rDim = ent as ArcDimension;

                        var rDim1 = new ArcDimension(rDim.CenterPoint, rDim.XLine1Point, rDim.XLine2Point, rDim.ArcPoint, rDim.DimensionText, rDim.DimensionStyle);

                        Dim2Dim(rDim1, rDim);
                        list.Add(rDim1);
                    }
                    else if (ent is DiametricDimension)
                    {
                        var rDim = ent as DiametricDimension;

                        var rDim1 = new DiametricDimension(rDim.ChordPoint, rDim.FarChordPoint, rDim.LeaderLength, rDim.DimensionText, rDim.DimensionStyle);

                        Dim2Dim(rDim1, rDim);
                        list.Add(rDim1);
                    }
                    else if (ent is LineAngularDimension2)
                    {
                        var rDim = ent as LineAngularDimension2;

                        var rDim1 = new LineAngularDimension2(rDim.XLine1Start, rDim.XLine1End, rDim.XLine2Start, rDim.XLine2End, rDim.ArcPoint, rDim.DimensionText, rDim.DimensionStyle);

                        Dim2Dim(rDim1, rDim);
                        list.Add(rDim1);
                    }
                    else if (ent is Point3AngularDimension)
                    {
                        var rDim = ent as Point3AngularDimension;

                        var rDim1 = new Point3AngularDimension(rDim.CenterPoint, rDim.XLine1Point, rDim.XLine2Point, rDim.ArcPoint, rDim.DimensionText, rDim.DimensionStyle);

                        Dim2Dim(rDim1, rDim);
                        list.Add(rDim1);
                    }
                    else if (ent is RadialDimension)
                    {
                        var rDim = ent as RadialDimension;

                        var rDim1 = new RadialDimension(rDim.Center, rDim.ChordPoint, rDim.LeaderLength, rDim.DimensionText, rDim.DimensionStyle);


                        Dim2Dim(rDim1, rDim);
                        list.Add(rDim1);
                    }
                    else if (ent is RadialDimensionLarge)
                    {
                        var rDim = ent as RadialDimensionLarge;

                        var rDim1 = new RadialDimensionLarge(rDim.Center, rDim.ChordPoint, rDim.OverrideCenter, rDim.JogPoint, rDim.JogAngle, rDim.DimensionText, rDim.DimensionStyle);

                        Dim2Dim(rDim1, rDim);
                        list.Add(rDim1);
                    }
                }
            }



            listEnt.ForEach(ent => ent.Dispose());
        }
예제 #7
0
        public static bool Clear(this Dimension obj)
        {
            bool myFlag = false;

            if (Math.Abs(obj.Elevation) >= TOLERANCE)
            {
                obj.Elevation = 0.0;
                myFlag        = true;
            }
            if (obj is AlignedDimension)
            {
                AlignedDimension myDimension = obj as AlignedDimension;
                if (Math.Abs(myDimension.XLine1Point.Z) >= TOLERANCE)
                {
                    myDimension.XLine1Point = myDimension.XLine1Point.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.XLine2Point.Z) >= TOLERANCE)
                {
                    myDimension.XLine2Point = myDimension.XLine2Point.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.DimLinePoint.Z) >= TOLERANCE)
                {
                    myDimension.DimLinePoint = myDimension.DimLinePoint.ClearZ();
                    myFlag = true;
                }
            }
            else if (obj is ArcDimension)
            {
                ArcDimension myDimension = obj as ArcDimension;
                if (Math.Abs(myDimension.XLine1Point.Z) >= TOLERANCE)
                {
                    myDimension.XLine1Point = myDimension.XLine1Point.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.XLine2Point.Z) >= TOLERANCE)
                {
                    myDimension.XLine2Point = myDimension.XLine2Point.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.Leader1Point.Z) >= TOLERANCE)
                {
                    myDimension.Leader1Point = myDimension.Leader1Point.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.Leader2Point.Z) >= TOLERANCE)
                {
                    myDimension.Leader2Point = myDimension.Leader2Point.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.ArcPoint.Z) >= TOLERANCE)
                {
                    myDimension.ArcPoint = myDimension.ArcPoint.ClearZ();
                    myFlag = true;
                }
            }
            else if (obj is DiametricDimension)
            {
                DiametricDimension myDimension = obj as DiametricDimension;
                if (Math.Abs(myDimension.ChordPoint.Z) >= TOLERANCE)
                {
                    myDimension.ChordPoint = myDimension.ChordPoint.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.FarChordPoint.Z) >= TOLERANCE)
                {
                    myDimension.FarChordPoint = myDimension.FarChordPoint.ClearZ();
                    myFlag = true;
                }
            }
            else if (obj is LineAngularDimension2)
            {
                LineAngularDimension2 myDimension = obj as LineAngularDimension2;
                if (Math.Abs(myDimension.ArcPoint.Z) >= TOLERANCE)
                {
                    myDimension.ArcPoint = myDimension.ArcPoint.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.XLine1End.Z) >= TOLERANCE)
                {
                    myDimension.XLine1End = myDimension.XLine1End.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.XLine1Start.Z) >= TOLERANCE)
                {
                    myDimension.XLine1Start = myDimension.XLine1Start.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.XLine2End.Z) >= TOLERANCE)
                {
                    myDimension.XLine2End = myDimension.XLine2End.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.XLine2Start.Z) >= TOLERANCE)
                {
                    myDimension.XLine2Start = myDimension.XLine2Start.ClearZ();
                    myFlag = true;
                }
            }
            else if (obj is Point3AngularDimension)
            {
                Point3AngularDimension myDimension = obj as Point3AngularDimension;
                if (Math.Abs(myDimension.ArcPoint.Z) >= TOLERANCE)
                {
                    myDimension.ArcPoint = myDimension.ArcPoint.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.CenterPoint.Z) >= TOLERANCE)
                {
                    myDimension.CenterPoint = myDimension.CenterPoint.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.XLine1Point.Z) >= TOLERANCE)
                {
                    myDimension.XLine1Point = myDimension.XLine1Point.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.XLine2Point.Z) >= TOLERANCE)
                {
                    myDimension.XLine2Point = myDimension.XLine2Point.ClearZ();
                    myFlag = true;
                }
            }
            else if (obj is RadialDimension)
            {
                RadialDimension myDimension = obj as RadialDimension;
                if (Math.Abs(myDimension.Center.Z) >= TOLERANCE)
                {
                    myDimension.Center = myDimension.Center.ClearZ();
                    myFlag             = true;
                }
                if (Math.Abs(myDimension.ChordPoint.Z) >= TOLERANCE)
                {
                    myDimension.ChordPoint = myDimension.ChordPoint.ClearZ();
                    myFlag = true;
                }
            }
            else if (obj is RadialDimensionLarge)
            {
                RadialDimensionLarge myDimension = obj as RadialDimensionLarge;
                if (Math.Abs(myDimension.Center.Z) >= TOLERANCE)
                {
                    myDimension.Center = myDimension.Center.ClearZ();
                    myFlag             = true;
                }
                if (Math.Abs(myDimension.ChordPoint.Z) >= TOLERANCE)
                {
                    myDimension.ChordPoint = myDimension.ChordPoint.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.JogPoint.Z) >= TOLERANCE)
                {
                    myDimension.JogPoint = myDimension.JogPoint.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.OverrideCenter.Z) >= TOLERANCE)
                {
                    myDimension.OverrideCenter = myDimension.OverrideCenter.ClearZ();
                    myFlag = true;
                }
            }
            else if (obj is RotatedDimension)
            {
                RotatedDimension myDimension = obj as RotatedDimension;
                if (Math.Abs(myDimension.DimLinePoint.Z) >= TOLERANCE)
                {
                    myDimension.DimLinePoint = myDimension.DimLinePoint.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.XLine1Point.Z) >= TOLERANCE)
                {
                    myDimension.XLine1Point = myDimension.XLine1Point.ClearZ();
                    myFlag = true;
                }
                if (Math.Abs(myDimension.XLine2Point.Z) >= TOLERANCE)
                {
                    myDimension.XLine2Point = myDimension.XLine2Point.ClearZ();
                    myFlag = true;
                }
            }
            return(myFlag);
        }
예제 #8
0
        public void DimTest()
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                // 创建要标注的图形
                Line   line1 = new Line(new Point3d(30, 20, 0), new Point3d(120, 20, 0));
                Line   line2 = new Line(new Point3d(120, 20, 0), new Point3d(120, 40, 0));
                Line   line3 = new Line(new Point3d(120, 40, 0), new Point3d(90, 80, 0));
                Line   line4 = new Line(new Point3d(90, 80, 0), new Point3d(30, 80, 0));
                Arc    arc   = new Arc(new Point3d(30, 50, 0), 30, Math.PI / 2, Math.PI * 3 / 2);
                Circle cir1  = new Circle(new Point3d(30, 50, 0), Vector3d.ZAxis, 15);
                Circle cir2  = new Circle(new Point3d(70, 50, 0), Vector3d.ZAxis, 10);
                //将图形添加到模型空间中
                db.AddToModelSpace(line1, line2, line3, line4, arc, cir1, cir2);
                //创建一个列表,用于存储标注对象
                List <Dimension> dims = new List <Dimension>();
                // 创建转角标注(水平)
                RotatedDimension dimRotated1 = new RotatedDimension
                {
                    //指定第一条尺寸界线的附着位置
                    XLine1Point = line1.StartPoint,
                    //指定第二条尺寸界线的附着位置
                    XLine2Point = line1.EndPoint,
                    //指定尺寸线的位置
                    DimLinePoint  = GeTools.MidPoint(line1.StartPoint, line1.EndPoint).PolarPoint(-Math.PI / 2, 10),
                    DimensionText = "<>mm" //设置标注的文字为标注值+后缀mm
                };
                dims.Add(dimRotated1);     //将水平转角标注添加到列表中
                //创建转角标注(垂直)
                RotatedDimension dimRotated2 = new RotatedDimension
                {
                    Rotation = Math.PI / 2, //转角标注角度为90度,表示垂直方向
                                            //指定两条尺寸界线的附着位置和尺寸线的位置
                    XLine1Point  = line2.StartPoint,
                    XLine2Point  = line2.EndPoint,
                    DimLinePoint = GeTools.MidPoint(line2.StartPoint, line2.EndPoint).PolarPoint(0, 10)
                };
                dims.Add(dimRotated2);//将垂直转角标注添加到列表中
                //创建转角标注(尺寸公差标注)
                RotatedDimension dimRotated3 = new RotatedDimension
                {
                    //指定两条尺寸界线的附着位置和尺寸线的位置
                    XLine1Point  = line4.StartPoint,
                    XLine2Point  = line4.EndPoint,
                    DimLinePoint = GeTools.MidPoint(line4.StartPoint, line4.EndPoint).PolarPoint(Math.PI / 2, 10),
                    //设置标注的文字为标注值+堆叠文字
                    DimensionText = TextTools.StackText("<>", "+0.026", "-0.025", StackType.Tolerance, 0.7)
                };
                dims.Add(dimRotated3);//将尺寸公差标注添加到列表中
                // 创建对齐标注
                AlignedDimension dimAligned = new AlignedDimension
                {
                    //指定两条尺寸界线的附着位置和尺寸线的位置
                    XLine1Point  = line3.StartPoint,
                    XLine2Point  = line3.EndPoint,
                    DimLinePoint = GeTools.MidPoint(line3.StartPoint, line3.EndPoint).PolarPoint(Math.PI / 2, 10),
                    //设置标注的文字为标注值+公差符号
                    DimensionText = "<>" + TextSpecialSymbol.Tolerance + "0.2"
                };
                dims.Add(dimAligned);//将对齐标注添加到列表中
                // 创建半径标注
                RadialDimension dimRadial = new RadialDimension
                {
                    Center = cir1.Center, //圆或圆弧的圆心
                                          //用于附着引线的圆或圆弧上的点
                    ChordPoint   = cir1.Center.PolarPoint(GeTools.DegreeToRadian(30), 15),
                    LeaderLength = 10     //引线长度
                };
                dims.Add(dimRadial);      //将半径标注添加到列表中
                // 创建直径标注
                DiametricDimension dimDiametric = new DiametricDimension
                {
                    //圆或圆弧上第一个直径点的坐标
                    ChordPoint = cir2.Center.PolarPoint(GeTools.DegreeToRadian(45), 10),
                    //圆或圆弧上第二个直径点的坐标
                    FarChordPoint = cir2.Center.PolarPoint(GeTools.DegreeToRadian(-135), 10),
                    LeaderLength  = 0   //从 ChordPoint 到注解文字或折线处的长度
                };
                dims.Add(dimDiametric); //将直径标注添加到列表中
                // 创建角度标注
                Point3AngularDimension dimLineAngular = new Point3AngularDimension
                {
                    //圆或圆弧的圆心、或两尺寸界线间的共有顶点的坐标
                    CenterPoint = line2.StartPoint,
                    //指定两条尺寸界线的附着位置
                    XLine1Point = line1.StartPoint,
                    XLine2Point = line2.EndPoint,
                    //设置角度标志圆弧线上的点
                    ArcPoint = line2.StartPoint.PolarPoint(GeTools.DegreeToRadian(135), 10)
                };
                dims.Add(dimLineAngular);//将角度标注添加到列表中
                // 创建弧长标注,标注文字取为默认值
                ArcDimension dimArc = new ArcDimension(arc.Center, arc.StartPoint, arc.EndPoint, arc.Center.PolarPoint(Math.PI, arc.Radius + 10), "<>", db.Dimstyle);
                dims.Add(dimArc);//将弧长标注添加到列表中
                // 创建显示X轴值的坐标标注
                OrdinateDimension dimX = new OrdinateDimension
                {
                    UsingXAxis    = true,        //显示 X 轴值
                    DefiningPoint = cir2.Center, //标注点
                                                 //指定引线终点,即标注文字显示的位置
                    LeaderEndPoint = cir2.Center.PolarPoint(-Math.PI / 2, 20)
                };
                dims.Add(dimX);//将坐标标注添加到列表中
                // 创建显示Y轴值的坐标标注
                OrdinateDimension dimY = new OrdinateDimension
                {
                    UsingXAxis    = false,       //显示Y轴
                    DefiningPoint = cir2.Center, //标注点
                                                 //指定引线终点,即标注文字显示的位置
                    LeaderEndPoint = cir2.Center.PolarPoint(0, 20)
                };
                dims.Add(dimY);                       //将坐标标注添加到列表中
                foreach (Dimension dim in dims)       //遍历标注列表
                {
                    dim.DimensionStyle = db.Dimstyle; //设置标注样式为当前样式
                    db.AddToModelSpace(dim);          //将标注添加到模型空间中
                }

                trans.Commit();//提交更改
            }
        }
예제 #9
0
        public static ObjectId AddDimArc(Point3d cenPt, Point3d pt1, Point3d pt2, Point3d arcPt, string text, ObjectId style)
        {
            ArcDimension ent = new ArcDimension(cenPt, pt1, pt2, arcPt, text, style);

            return(ModelSpace.AddEnt(ent));
        }