// 由标注类型(是否是X坐标)、标注箭头的起始位置、标注箭头的终止位置、尺寸文本和标注样式创建坐标标注的函数.
        public static ObjectId AddDimOrdinate(bool useXAxis, Point3d ordPt, Point3d pt, string text, ObjectId style)
        {
            OrdinateDimension ent   = new OrdinateDimension(useXAxis, ordPt, pt, text, style);
            ObjectId          entId = AppendEntity(ent);

            return(entId);
        }
        public OrdinateDimension OrdinateDimensionX(Point3d stratPoint, Point3d ordPt, double lenght, bool bo)
        {
            Database          db    = HostApplicationServices.WorkingDatabase;
            ObjectId          style = db.Dimstyle;
            Point3d           pt1   = new Point3d(ordPt.X + lenght * Math.Cos(bo ? 3 * Math.PI / 2 : Math.PI / 2), ordPt.Y + lenght * Math.Sin(bo ? 3 * Math.PI / 2 : Math.PI / 2), ordPt.Z);
            OrdinateDimension entX  = new OrdinateDimension(true, ordPt, pt1, "<>", style);

            entX.Origin = stratPoint;
            return(entX);
        }
        // 由标注箭头的起始位置、标注箭头的X终止位置和标注箭头的Y终止位置创建坐标标注的函数(X坐标和Y坐标).
        public static ObjectIdCollection AddDimOrdinate(Point3d ordPt, Point3d ptX, Point3d ptY)
        {
            Database           db     = HostApplicationServices.WorkingDatabase;
            ObjectId           style  = db.Dimstyle;
            string             textX  = Math.Round(ordPt.X, db.Dimdec).ToString();
            string             textY  = Math.Round(ordPt.Y, db.Dimdec).ToString();
            OrdinateDimension  entX   = new OrdinateDimension(true, ordPt, ptX, textX, style);
            OrdinateDimension  entY   = new OrdinateDimension(false, ordPt, ptY, textY, style);
            ObjectId           objIdX = AppendEntity(entX);
            ObjectId           objIdY = AppendEntity(entY);
            ObjectIdCollection entIds = new ObjectIdCollection();

            entIds.Add(objIdX);
            entIds.Add(objIdY);
            return(entIds);
        }
        public void AddEntityObject()
        {
            AddToModelSpace(DbText(new Point3d(-10, 20, 0), "fck13", 5));//创建一个基点为(0, 50, 0),文字高度为20的文字,添加到模型空间
            Line L = new Line(new Point3d(40, 0, 0), new Point3d(60, 15, 0));
            //创建直线
            OrdinateDimension ODX = OrdinateDimensionX(L.StartPoint, L.EndPoint, 10, true);

            //创建X增量标注
            AddToModelSpace(L);
            AddToModelSpace(ODX);
            Circle          C  = new Circle(Point3d.Origin, Vector3d.ZAxis, 15); //创建圆
            RadialDimension RD = RadialDimension(C, 3 * Math.PI / 4, 10);        //创建半径标注

            AddToModelSpace(C);
            AddToModelSpace(RD);
        }
Exemple #5
0
        public static ObjectIdCollection AddDimOrdinate(Point3d ordPt, Point3d ptX, Point3d ptY)
        {
            Database           workingDatabase    = HostApplicationServices.WorkingDatabase;
            ObjectId           dimstyle           = workingDatabase.Dimstyle;
            string             text               = Math.Round(ordPt.X, workingDatabase.Dimdec).ToString();
            string             text2              = Math.Round(ordPt.Y, workingDatabase.Dimdec).ToString();
            OrdinateDimension  ent                = new OrdinateDimension(true, ordPt, ptX, text, dimstyle);
            OrdinateDimension  ent2               = new OrdinateDimension(false, ordPt, ptY, text2, dimstyle);
            ObjectId           objectId           = ModelSpace.AddEnt(ent);
            ObjectId           objectId2          = ModelSpace.AddEnt(ent2);
            ObjectIdCollection objectIdCollection = new ObjectIdCollection();

            objectIdCollection.Add(objectId);
            objectIdCollection.Add(objectId2);
            return(objectIdCollection);
        }
Exemple #6
0
        public static ObjectId AddDimOrdinate(bool useXAxis, Point3d ordPt, Point3d pt)
        {
            Database workingDatabase = HostApplicationServices.WorkingDatabase;
            ObjectId dimstyle        = workingDatabase.Dimstyle;
            string   text;

            if (useXAxis)
            {
                text = Math.Round(ordPt.X, workingDatabase.Dimdec).ToString();
            }
            else
            {
                text = Math.Round(ordPt.Y, workingDatabase.Dimdec).ToString();
            }
            OrdinateDimension ent = new OrdinateDimension(useXAxis, ordPt, pt, text, dimstyle);

            return(ModelSpace.AddEnt(ent));
        }
        // 由标注类型(是否是X坐标)、标注箭头的起始位置和标注箭头的终止位置创建坐标标注的函数.
        public static ObjectId AddDimOrdinate(bool useXAxis, Point3d ordPt, Point3d pt)
        {
            Database db    = HostApplicationServices.WorkingDatabase;
            ObjectId style = db.Dimstyle;
            string   text;

            if (useXAxis == true)
            {
                text = Math.Round(ordPt.X, db.Dimdec).ToString();
            }
            else
            {
                text = Math.Round(ordPt.Y, db.Dimdec).ToString();
            }
            OrdinateDimension ent   = new OrdinateDimension(useXAxis, ordPt, pt, text, style);
            ObjectId          entId = AppendEntity(ent);

            return(entId);
        }
 // 由标注箭头的起始位置、标注箭头的X终止位置、标注箭头的Y终止位置、X坐标标注文字、Y坐标标注文字和标注样式创建坐标标注的函数.
 public static ObjectIdCollection AddDimOrdinate(Point3d ordPt, Point3d ptX, Point3d ptY, string textX, string textY, ObjectId style)
 {
     try
     {
         OrdinateDimension  entX   = new OrdinateDimension(true, ordPt, ptX, textX, style);
         OrdinateDimension  entY   = new OrdinateDimension(false, ordPt, ptX, textX, style);
         ObjectId           objIdX = AppendEntity(entX);
         ObjectId           objIdY = AppendEntity(entY);
         ObjectIdCollection entIds = new ObjectIdCollection();
         entIds.Add(objIdX);
         entIds.Add(objIdY);
         return(entIds);
     }
     catch
     {
         ObjectId           nullId  = ObjectId.Null;
         ObjectIdCollection nullIds = new ObjectIdCollection();
         nullIds.Add(nullId);
         return(nullIds);
     }
 }
Exemple #9
0
        public static ObjectIdCollection AddDimOrdinate(Point3d ordPt, Point3d ptX, Point3d ptY, string textX, string textY, ObjectId style)
        {
            ObjectIdCollection result;

            try
            {
                OrdinateDimension  ent                = new OrdinateDimension(true, ordPt, ptX, textX, style);
                OrdinateDimension  ent2               = new OrdinateDimension(false, ordPt, ptY, textY, style);
                ObjectId           objectId           = ModelSpace.AddEnt(ent);
                ObjectId           objectId2          = ModelSpace.AddEnt(ent2);
                ObjectIdCollection objectIdCollection = new ObjectIdCollection();
                objectIdCollection.Add(objectId);
                objectIdCollection.Add(objectId2);
                result = objectIdCollection;
            }
            catch (Exception ex)
            {
                ObjectId           @null = ObjectId.Null;
                ObjectIdCollection objectIdCollection2 = new ObjectIdCollection();
                objectIdCollection2.Add(@null);
                result = objectIdCollection2;
            }
            return(result);
        }
Exemple #10
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();//提交更改
            }
        }
Exemple #11
0
        internal static GeometryBase CreateGeometryHelper(IntPtr pGeometry, object parent, int subobjectIndex)
        {
            if (IntPtr.Zero == pGeometry)
            {
                return(null);
            }

            var type = UnsafeNativeMethods.ON_Geometry_GetGeometryType(pGeometry);

            if (type < 0)
            {
                return(null);
            }
            GeometryBase rc = null;

            switch (type)
            {
            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Curve: //1
                rc = new Curve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsCurve: //2
                rc = new NurbsCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolyCurve: // 3
                rc = new PolyCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolylineCurve: //4
                rc = new PolylineCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ArcCurve: //5
                rc = new ArcCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_LineCurve: //6
                rc = new LineCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Mesh: //7
                rc = new Mesh(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Point: //8
                rc = new Point(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_TextDot: //9
                rc = new TextDot(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Surface: //10
                rc = new Surface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Brep: //11
                rc = new Brep(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsSurface: //12
                rc = new NurbsSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_RevSurface: //13
                rc = new RevSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PlaneSurface: //14
                rc = new PlaneSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ClippingPlaneSurface: //15
                rc = new ClippingPlaneSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Hatch: // 17
                rc = new Hatch(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SumSurface: //19
                rc = new SumSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepFace: //20
            {
                int    faceindex = -1;
                IntPtr ptr_brep  = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref faceindex);
                if (ptr_brep != IntPtr.Zero && faceindex >= 0)
                {
                    Brep b = new Brep(ptr_brep, parent);
                    rc = b.Faces[faceindex];
                }
            }
            break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepEdge: // 21
            {
                int    edgeindex = -1;
                IntPtr ptr_brep  = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref edgeindex);
                if (ptr_brep != IntPtr.Zero && edgeindex >= 0)
                {
                    Brep b = new Brep(ptr_brep, parent);
                    rc = b.Edges[edgeindex];
                }
            }
            break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_InstanceReference: // 23
                rc = new InstanceReferenceGeometry(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Extrusion: //24
                rc = new Extrusion(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointCloud: // 26
                rc = new PointCloud(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DetailView: // 27
                rc = new DetailView(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Light: //32
                rc = new Light(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointGrid: //33
                rc = new Point3dGrid(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_MorphControl: //34
                rc = new MorphControl(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepLoop: //35
            {
                int    loopindex = -1;
                IntPtr ptr_brep  = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref loopindex);
                if (ptr_brep != IntPtr.Zero && loopindex >= 0)
                {
                    Brep b = new Brep(ptr_brep, parent);
                    rc = b.Loops[loopindex];
                }
            }
            break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepTrim: // 36
            {
                int    trimindex = -1;
                IntPtr ptr_brep  = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref trimindex);
                if (ptr_brep != IntPtr.Zero && trimindex >= 0)
                {
                    Brep b = new Brep(ptr_brep, parent);
                    rc = b.Trims[trimindex];
                }
            }
            break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Leader: // 38
                rc = new Leader(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SubD: // 39
                rc = new SubD(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimLinear: //40
                rc = new LinearDimension(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimAngular: //41
                rc = new AngularDimension(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimRadial: //42
                rc = new RadialDimension(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimOrdinate: //43
                rc = new OrdinateDimension(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Centermark: //44
                rc = new Centermark(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Text: //45
                rc = new TextEntity(pGeometry, parent);
                break;

            default:
                rc = new UnknownGeometry(pGeometry, parent, subobjectIndex);
                break;
            }

            return(rc);
        }
Exemple #12
0
        public static ObjectId AddDimOrdinate(bool useXAxis, Point3d ordPt, Point3d pt, string text, ObjectId style)
        {
            OrdinateDimension ent = new OrdinateDimension(useXAxis, ordPt, pt, text, style);

            return(ModelSpace.AddEnt(ent));
        }