// 由两个引线附着点、引线长度、尺寸文本和标注样式创建直径标注的函数. public static ObjectId AddDimDiametric(Point3d ptChord1, Point3d ptChord2, double leaderLength, string text, ObjectId style) { DiametricDimension ent = new DiametricDimension(ptChord1, ptChord2, leaderLength, text, style); ObjectId entId = AppendEntity(ent); return(entId); }
public static ObjectId AddDimDiametric(Point3d ptChord1, Point3d ptChord2, double leaderLength) { Database workingDatabase = HostApplicationServices.WorkingDatabase; ObjectId dimstyle = workingDatabase.Dimstyle; string text = "%%c" + Math.Round(ptChord1.DistanceTo(ptChord2), workingDatabase.Dimdec).ToString(); DiametricDimension ent = new DiametricDimension(ptChord1, ptChord2, leaderLength, text, dimstyle); return(ModelSpace.AddEnt(ent)); }
// 由两个引线附着点和引线长度创建直径标注的函数. public static ObjectId AddDimDiametric(Point3d ptChord1, Point3d ptChord2, double leaderLength) { Database db = HostApplicationServices.WorkingDatabase; ObjectId style = db.Dimstyle; string text = "%%c" + Math.Round(ptChord1.DistanceTo(ptChord2), db.Dimdec).ToString(); DiametricDimension ent = new DiametricDimension(ptChord1, ptChord2, leaderLength, text, style); ObjectId entId = AppendEntity(ent); return(entId); }
public crawlAcDbDiametricDimension(DiametricDimension dim) { Entity ent = (Entity)dim; this.ObjectId = ent.ObjectId.ToString(); this.FarChordPoint = new crawlPoint3d(dim.FarChordPoint.X, dim.FarChordPoint.Y, dim.FarChordPoint.Z); this.ChordPoint = new crawlPoint3d(dim.ChordPoint.X, dim.ChordPoint.Y, dim.ChordPoint.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; }
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); }
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()); }
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); }
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();//提交更改 } }
public void MyHook() { Database db = HostApplicationServices.WorkingDatabase; List <Entity> entityList = new List <Entity>(); List <Entity> centerMarkList = new List <Entity>(); List <Entity> MarkList = new List <Entity>(); Point3d pt1 = new Point3d(0, 0, 0); Point3d pt2 = new Point3d(5, -3, 0); Point3d pt3 = new Point3d(0, 70, 0); Point3d pt4 = new Point3d(-18, 46, 0); //已知圆心的圆 Circle c1 = new Circle(pt1, Vector3d.ZAxis, 20); Circle c2 = new Circle(pt2, Vector3d.ZAxis, 45); Circle c3 = new Circle(pt3, Vector3d.ZAxis, 10); Circle c4 = new Circle(pt3, Vector3d.ZAxis, 20); Circle c5 = new Circle(pt4, Vector3d.ZAxis, 8); //已知两条辅助线 Line l1 = new Line(new Point3d(5, -3 - 45, 0), new Point3d(-60, -3 - 45, 0)); l1.ColorIndex = 2; Line l2 = new Line(new Point3d(5, -3 - 45 + 64, 0), new Point3d(-60, -3 - 45 + 64, 0)); l2.ColorIndex = 2; //圆心线 Line lc1x = new Line(new Point3d(-30, 0, 0), new Point3d(30, 0, 0)); Line lc1y = new Line(new Point3d(0, -30, 0), new Point3d(0, 30, 0)); Line lc2x = new Line(new Point3d(-30 + 5, 0 - 3, 0), new Point3d(30 + 5, 0 - 3, 0)); Line lc2y = new Line(new Point3d(-30 + 5, 0 - 3, 0), new Point3d(30 + 5, 0 - 3, 0)); Line lc3x = new Line(new Point3d(-30, 0 + 70, 0), new Point3d(30, 0 + 70, 0)); Line lc3y = new Line(new Point3d(-30, 0 + 70, 0), new Point3d(30, 0 + 70, 0)); //需要求解的圆-->弧 //第一个切圆-->裁剪弧 Circle fc1 = new Circle(pt4, Vector3d.ZAxis, 8 + 18); Circle fc2 = new Circle(pt3, Vector3d.ZAxis, 20 + 18); Point3dCollection pc = new Point3dCollection(); fc1.IntersectWith(fc2, Intersect.OnBothOperands, pc, new IntPtr(0), new IntPtr(0)); fc1.Dispose(); fc2.Dispose(); foreach (Point3d p in pc) { if (p.X < c4.Center.X) { double sa = new Line(p, pt4).Angle; double sb = new Line(p, pt3).Angle; Arc a = new Arc(p, 18, sa, sb); entityList.Add(a); //第一条弧 break; } } //第二个切圆-->裁剪弧 Circle fc3 = new Circle(pt2, Vector3d.ZAxis, 45 + 86); Circle fc4 = new Circle(pt3, Vector3d.ZAxis, 20 + 86); pc.Clear(); fc3.IntersectWith(fc4, Intersect.OnBothOperands, pc, new IntPtr(0), new IntPtr(0)); fc3.Dispose(); fc4.Dispose(); foreach (Point3d p in pc) { if (p.X > c2.Center.X) { double sa = new Line(p, pt3).Angle; double sb = new Line(p, pt2).Angle; Arc a = new Arc(p, 86, sa, sb); entityList.Add(a); //第二条弧 break; } } //第三个切圆-->裁剪弧 Circle fc5 = new Circle(pt1, Vector3d.ZAxis, 20 + 9.7144); Circle fc6 = new Circle(pt2, Vector3d.ZAxis, 45 - 9.7144); pc.Clear(); fc5.IntersectWith(fc6, Intersect.OnBothOperands, pc, new IntPtr(0), new IntPtr(0)); fc5.Dispose(); fc6.Dispose(); foreach (Point3d p in pc) { if (p.X < c1.Center.X && p.Y < (-3 - 45 + 64)) { double sa = new Line(p, pt1).Angle; double sb = new Line(pt2, p).Angle; Arc a = new Arc(p, 9.7144, sa, sb); entityList.Add(a); //第三条弧 break; } } //线 Line fl3 = new Line(new Point3d(0, -30, 0), new Point3d(0, 100, 0)); fl3.TransformBy(Matrix3d.Rotation((Math.PI * 15 / 180), doc.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis, fl3.EndPoint)); Point3d fp1 = fl3.GetClosestPointTo(c1.Center, true); Line l3 = new Line(c1.Center, fp1); pc.Clear(); l3.IntersectWith(c1, Intersect.ExtendThis, pc, new IntPtr(0), new IntPtr(0)); Point3d fp2 = l3.StartPoint; foreach (Point3d p in pc) { if (p.X > c1.Center.X) { fp2 = p; break; } } l3.Extend(50); l3.TransformBy(Matrix3d.Rotation((Math.PI * 90 / 180), doc.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d.Zaxis, fp2)); //l3.GetOffsetCurvesGivenPlaneNormal(Vector3d.XAxis, 18); Vector3d ve = new Vector3d(fp2.X, fp2.Y, fp2.Z); ve = ve.GetNormal(); //DBObjectCollection lc= l3.GetOffsetCurvesGivenPlaneNormal(ve, 14); DBObjectCollection lc = l3.GetOffsetCurves(14); //第四个切圆-->弧 Circle fc7 = new Circle(pt4, Vector3d.ZAxis, 22); Point3d sc1 = new Point3d(); foreach (Entity l in lc) { Point3dCollection fc = new Point3dCollection(); fc7.IntersectWith(l, Intersect.ExtendBoth, fc, new IntPtr(0), new IntPtr(0)); foreach (Point3d p in fc) { if (p.Y < pt4.Y) { //Circle tmpc = new Circle(p, Vector3d.ZAxis, 14); Arc a = new Arc(p, 14, new Line(pt1, fp1).Angle, new Line(p, pt4).Angle); entityList.Add(a); //第四条弧 break; } } } //公切线修剪 l3.StartPoint = fp2; l3.EndPoint = ((Arc)(entityList[entityList.Count - 1])).StartPoint; //修剪c5圆-->弧 Arc a1 = new Arc(c5.Center, c5.Radius, new Line(c5.Center, ((Arc)(entityList[0])).StartPoint).Angle, new Line(c5.Center, ((Arc)(entityList[3])).EndPoint).Angle); entityList.Add(a1);//第五条弧 //修剪C2号圆-->弧 Arc a2 = new Arc(c2.Center, c2.Radius, new Line(c2.Center, ((Arc)(entityList[2])).EndPoint).Angle, new Line(c2.Center, ((Arc)(entityList[1])).EndPoint).Angle); entityList.Add(a2);//第6条弧 //修剪C4号圆-->弧 Arc a3 = new Arc(c4.Center, c4.Radius, new Line(c4.Center, ((Arc)(entityList[1])).StartPoint).Angle, new Line(c4.Center, ((Arc)(entityList[0])).EndPoint).Angle); entityList.Add(a3);//第7条弧 //修剪c1号圆-->弧 Arc a4 = new Arc(c1.Center, c1.Radius, new Line(c1.Center, ((Arc)(entityList[2])).StartPoint).Angle, new Line(c1.Center, l3.StartPoint).Angle); entityList.Add(a4);//第8条弧 //画十字线 Point3d[] points = { pt1, pt2, pt3, pt4 }; foreach (Point3d p in points) { Line tmpl1 = new Line(new Point3d(p.X - 20, p.Y, 0), new Point3d(p.X + 20, p.Y, 0)); Line tmpl2 = new Line(new Point3d(p.X, p.Y - 20, 0), new Point3d(p.X, p.Y + 20, 0)); //tmpl1.Linetype = "CENTER2"; //tmpl2.Linetype = "CENTER2"; tmpl1.ColorIndex = 4; tmpl2.ColorIndex = 4; centerMarkList.Add(tmpl1); centerMarkList.Add(tmpl2); } //标注 //c3直径 DiametricDimension d1 = new DiametricDimension(); Line tmpl = new Line(c3.Center, new Point3d(c3.Center.X - 1, c3.Center.Y + 1, 0)); pc.Clear(); c3.IntersectWith(tmpl, Intersect.ExtendBoth, pc, new IntPtr(0), new IntPtr(0)); d1.ChordPoint = pc[0]; d1.FarChordPoint = pc[1]; d1.LeaderLength = 20; d1.ColorIndex = 2; MarkList.Add(d1); //半径 RadialDimension r1 = new RadialDimension(); Arc tmparc = entityList[0] as Arc; tmpl = new Line(tmparc.Center, new Point3d(tmparc.Center.X + 1, tmparc.Center.Y - 0.5, 0)); pc.Clear(); tmparc.IntersectWith(tmpl, Intersect.ExtendBoth, pc, new IntPtr(0), new IntPtr(0)); r1.Center = tmparc.Center; r1.ChordPoint = pc[1].X > pc[0].X?pc[1]:pc[0]; r1.ColorIndex = 2; r1.LeaderLength = -5; MarkList.Add(r1); RadialDimension r2 = new RadialDimension(); tmparc = entityList[1] as Arc; tmpl = new Line(tmparc.Center, new Point3d(tmparc.Center.X - 1, tmparc.Center.Y - 0.5, 0)); pc.Clear(); tmparc.IntersectWith(tmpl, Intersect.ExtendBoth, pc, new IntPtr(0), new IntPtr(0)); r2.Center = tmparc.Center; r2.ChordPoint = pc[1].X > pc[0].X ? pc[0] : pc[1]; r2.ColorIndex = 2; r2.LeaderLength = -30; MarkList.Add(r2); RadialDimension r3 = new RadialDimension(); tmparc = entityList[2] as Arc; tmpl = new Line(tmparc.Center, new Point3d(tmparc.Center.X + 1, tmparc.Center.Y - 0.2, 0)); pc.Clear(); tmparc.IntersectWith(tmpl, Intersect.ExtendBoth, pc, new IntPtr(0), new IntPtr(0)); r3.Center = tmparc.Center; r3.ChordPoint = pc[1].X > pc[0].X ? pc[0] : pc[1]; r3.ColorIndex = 2; MarkList.Add(r3); RadialDimension r4 = new RadialDimension(); tmparc = entityList[3] as Arc; tmpl = new Line(tmparc.Center, new Point3d(tmparc.Center.X + 0.35, tmparc.Center.Y + 1, 0)); pc.Clear(); tmparc.IntersectWith(tmpl, Intersect.ExtendBoth, pc, new IntPtr(0), new IntPtr(0)); r4.Center = tmparc.Center; r4.ChordPoint = pc[1].X < pc[0].X ? pc[0] : pc[1]; r4.ColorIndex = 2; MarkList.Add(r4); RadialDimension r5 = new RadialDimension(); tmparc = entityList[4] as Arc; tmpl = new Line(tmparc.Center, new Point3d(tmparc.Center.X + 0.35, tmparc.Center.Y + 1, 0)); pc.Clear(); tmparc.IntersectWith(tmpl, Intersect.ExtendBoth, pc, new IntPtr(0), new IntPtr(0)); r5.Center = tmparc.Center; r5.ChordPoint = pc[1].X > pc[0].X ? pc[0] : pc[1]; r5.ColorIndex = 2; MarkList.Add(r5); RadialDimension r6 = new RadialDimension(); tmparc = entityList[5] as Arc; tmpl = new Line(tmparc.Center, new Point3d(tmparc.Center.X + 1, tmparc.Center.Y - 1, 0)); pc.Clear(); tmparc.IntersectWith(tmpl, Intersect.ExtendBoth, pc, new IntPtr(0), new IntPtr(0)); r6.Center = tmparc.Center; r6.ChordPoint = pc[1].X < pc[0].X ? pc[0] : pc[1]; r6.ColorIndex = 2; r6.LeaderLength = 20; MarkList.Add(r6); RadialDimension r7 = new RadialDimension(); tmparc = entityList[6] as Arc; tmpl = new Line(tmparc.Center, new Point3d(tmparc.Center.X + 1, tmparc.Center.Y + 1, 0)); pc.Clear(); tmparc.IntersectWith(tmpl, Intersect.ExtendBoth, pc, new IntPtr(0), new IntPtr(0)); r7.Center = tmparc.Center; r7.ChordPoint = pc[1].X < pc[0].X ? pc[0] : pc[1]; r7.ColorIndex = 2; r7.LeaderLength = 20; MarkList.Add(r7); RadialDimension r8 = new RadialDimension(); tmparc = entityList[7] as Arc; tmpl = new Line(tmparc.Center, new Point3d(tmparc.Center.X - 1, tmparc.Center.Y - 1, 0)); pc.Clear(); tmparc.IntersectWith(tmpl, Intersect.ExtendBoth, pc, new IntPtr(0), new IntPtr(0)); r8.Center = tmparc.Center; r8.ChordPoint = pc[1].X > pc[0].X ? pc[0] : pc[1]; r8.ColorIndex = 2; r8.LeaderLength = 13; MarkList.Add(r8); //对齐标注1 AlignedDimension am1 = new AlignedDimension(); am1.XLine1Point = pt1; am1.XLine2Point = new Point3d(5, 0, 0); am1.DimLinePoint = new Point3d(0, -40, 0); am1.ColorIndex = 2; MarkList.Add(am1); //对齐标注2 AlignedDimension am2 = new AlignedDimension(); am2.XLine1Point = pt1; am2.XLine2Point = new Point3d(0, -3, 0); am2.DimLinePoint = new Point3d(40, 0, 0); am2.ColorIndex = 2; MarkList.Add(am2); //对齐标注3 AlignedDimension am3 = new AlignedDimension(); am3.XLine1Point = pt1; am3.XLine2Point = new Point3d(0, 70, 0); am3.DimLinePoint = new Point3d(70, 30, 0); am3.ColorIndex = 2; MarkList.Add(am3); //对齐标注4 AlignedDimension am4 = new AlignedDimension(); am4.XLine1Point = l1.EndPoint; am4.XLine2Point = l2.EndPoint; am4.DimLinePoint = new Point3d(-60, 0, 0); am4.ColorIndex = 2; MarkList.Add(am4); //对齐标注5 AlignedDimension am5 = new AlignedDimension(); am5.XLine1Point = new Point3d(0, 34, 0); am5.XLine2Point = new Point3d(-18, 34, 0); am5.DimLinePoint = new Point3d(0, 8, 0); am5.ColorIndex = 2; MarkList.Add(am5); //对齐标注6 AlignedDimension am6 = new AlignedDimension(); am6.XLine1Point = new Point3d(-18, 70, 0); am6.XLine2Point = new Point3d(-18, 46, 0); am6.DimLinePoint = new Point3d(-50, 0, 0); am6.ColorIndex = 2; MarkList.Add(am6); //角度标注1 LineAngularDimension2 lad1 = new LineAngularDimension2(); tmpl = new Line(new Point3d(0, 0, 0), new Point3d(0, 1, 0)); pc.Clear(); tmpl.IntersectWith(l3, Intersect.ExtendBoth, pc, new IntPtr(0), new IntPtr(0)); lad1.XLine2Start = pc[0]; lad1.XLine2End = pt1; lad1.XLine1Start = l3.EndPoint; lad1.XLine1End = l3.StartPoint; lad1.ArcPoint = new Point3d(10, 2, 0); lad1.ColorIndex = 2; MarkList.Add(lad1); AddEntities(MarkList.ToArray()); Entity[] es = { c3, l3 }; ////AddEntities(es); entityList.AddRange(es); //组成面域 DBObjectCollection dbc1 = new DBObjectCollection(); foreach (Entity e in entityList) { dbc1.Add(e); } dbc1.Add(c3); DBObjectCollection regions = new DBObjectCollection(); regions = Region.CreateFromCurves(dbc1); //doc.Editor.WriteMessage("r1{0}", dbc1regions.Count); Region re1 = regions[0] as Region; Region re2 = regions[1] as Region; doc.Editor.WriteMessage("r1:{0},r2:{1}", re1.Area, re2.Area); double area = re1.Area > re2.Area ?re1.Area - re2.Area:re2.Area - re1.Area; Area = area; doc.Editor.WriteMessage("面积{0}", area); //entityList.Clear(); //entityList.Add(r1); //entityList.Add(r2); foreach (Entity e in entityList) { e.ColorIndex = 1; } entityList.Add(l1); entityList.Add(l2); AddEntities(entityList.ToArray()); AddEntities(centerMarkList.ToArray()); }
public static ObjectId AddDimDiametric(Point3d ptChord1, Point3d ptChord2, double leaderLength, string text, ObjectId style) { DiametricDimension ent = new DiametricDimension(ptChord1, ptChord2, leaderLength, text, style); return(ModelSpace.AddEnt(ent)); }