public List <Entity> CreateVisual(byte transparence) { var draws = new List <Entity>(); // Штриховка var color = InsPoint?.InsValue?.Requirement?.Color ?? System.Drawing.Color.Gray; var visOpt = new VisualOption(color, Point3d.Origin, transparence); var points = new List <Point2d> { PtOrig, PtStart, PtEnd }; var h = VisualHelper.CreateHatch(points, visOpt); draws.Add(h); // Угловой размер var ptCenter = GetCenterTriangle(PtOrig, PtStart, PtEnd); var ptDim1 = PtOrig + (PtStart - PtOrig) / 2; var ptDim2 = PtOrig + (PtEnd - PtOrig) / 2; var dim = new LineAngularDimension2(PtOrig.Convert3d(), ptDim1.Convert3d(), PtOrig.Convert3d(), ptDim2.Convert3d(), ptCenter.Convert3d(), Time.ToHours(), ObjectId.Null); dim.DimensionStyle = HostApplicationServices.WorkingDatabase.GetDimAngularStylePIK(); dim.Color = Color.FromColor(System.Drawing.Color.Red); dim.Dimtxt = 1.5; dim.Dimscale = 0.5; dim.LineWeight = LineWeight.ByLineWeightDefault; dim.Dimclrd = dim.Color; dim.Dimclre = dim.Color; dim.Dimclrt = dim.Color; draws.Add(dim); return(draws); }
// 由两条直线的起点和终点以及尺寸文本位置、尺寸文本、标注样式创建角度标注的函数. public static ObjectId AddDimLineAngular(Point3d line1StartPt, Point3d line1EndPt, Point3d line2StartPt, Point3d line2EndPt, Point3d arcPt, string text, ObjectId style) { LineAngularDimension2 ent = new LineAngularDimension2(line1StartPt, line1EndPt, line2StartPt, line2EndPt, arcPt, text, style); ObjectId entId = AppendEntity(ent); return(entId); }
public static void CreateAngularDimension() { // 获取当前数据库 Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; // 启动事务 using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // 以读模式打开块表 BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; // 以写模式打开块表记录 ModelSpace BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; // 建立角度标注 LineAngularDimension2 acLinAngDim = new LineAngularDimension2(); acLinAngDim.XLine1Start = new Point3d(0, 5, 0); acLinAngDim.XLine1End = new Point3d(1, 7, 0); acLinAngDim.XLine2Start = new Point3d(0, 5, 0); acLinAngDim.XLine2End = new Point3d(1, 3, 0); acLinAngDim.ArcPoint = new Point3d(3, 5, 0); acLinAngDim.DimensionStyle = acCurDb.Dimstyle; // 添加新对象到模型空间和事务中 acBlkTblRec.AppendEntity(acLinAngDim); acTrans.AddNewlyCreatedDBObject(acLinAngDim, true); // 提交修改,关闭事务 acTrans.Commit(); } }
public static ObjectId AddDimLineAngular(Point3d line1StartPt, Point3d point3d_0, Point3d line2StartPt, Point3d point3d_1, Point3d arcPt) { Database workingDatabase = HostApplicationServices.WorkingDatabase; ObjectId dimstyle = workingDatabase.Dimstyle; Vector3d vector3d = point3d_0 - line1StartPt; Vector3d vector3d2 = point3d_1 - line2StartPt; double value = vector3d.GetAngleTo(vector3d2) * 180.0 / 3.1415926535897931; string text = Math.Round(value, workingDatabase.Dimadec).ToString() + "%%d"; LineAngularDimension2 ent = new LineAngularDimension2(line1StartPt, point3d_0, line2StartPt, point3d_1, arcPt, text, dimstyle); return(ModelSpace.AddEnt(ent)); }
// 由两条直线的起点和终点以及尺寸文本位置创建角度标注的函数. public static ObjectId AddDimLineAngular(Point3d line1StartPt, Point3d line1EndPt, Point3d line2StartPt, Point3d line2EndPt, Point3d arcPt) { Database db = HostApplicationServices.WorkingDatabase; ObjectId style = db.Dimstyle; Vector3d vec1 = line1EndPt - line1StartPt; Vector3d vec2 = line2EndPt - line2StartPt; double ang = vec1.GetAngleTo(vec2) * 180 / Math.PI; string text = Math.Round(ang, db.Dimadec).ToString() + "%%d"; LineAngularDimension2 ent = new LineAngularDimension2(line1StartPt, line1EndPt, line2StartPt, line2EndPt, arcPt, text, style); ObjectId entId = AppendEntity(ent); return(entId); }
public static LineAngularDimension2 DimAng(Database db, Line L1, Line L2, Point3d Pref, ObjectId dimID) { LineAngularDimension2 AD1; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; AD1 = new LineAngularDimension2(L1.StartPoint, L1.EndPoint, L2.StartPoint, L2.EndPoint, Pref, "", dimID); AD1.Layer = "标注"; modelSpace.AppendEntity(AD1); tr.AddNewlyCreatedDBObject(AD1, true); tr.Commit(); } return(AD1); }
public crawlAcDbLineAngularDimension2(LineAngularDimension2 dim) { Entity ent = (Entity)dim; this.ObjectId = ent.ObjectId.ToString(); this.XLine1Start = new crawlPoint3d(dim.XLine1Start.X, dim.XLine1Start.Y, dim.XLine1Start.Z); this.XLine1End = new crawlPoint3d(dim.XLine1End.X, dim.XLine1End.Y, dim.XLine1End.Z); this.XLine2Start = new crawlPoint3d(dim.XLine2Start.X, dim.XLine2Start.Y, dim.XLine2Start.Z); this.XLine2End = new crawlPoint3d(dim.XLine2End.X, dim.XLine2End.Y, dim.XLine2End.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; }
public static void addDiametricDimension(Database db, Point3d start1, Point3d start2, Point3d end1, Point3d end2, double distance, ObjectId dimid) { using (Transaction trans = db.TransactionManager.StartOpenCloseTransaction()) { BlockTable blockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord space = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; LineAngularDimension2 dimLineAngular = new LineAngularDimension2(); //圓或圓弧的圓心、或兩個尺寸界線間的共有頂點的座標 dimLineAngular.XLine1Start = start1; dimLineAngular.XLine2Start = start2; dimLineAngular.XLine1End = end1; dimLineAngular.XLine2End = end2; Vector3d vector3D1 = start1.GetVectorTo(end1); Vector3d vector3D2 = start2.GetVectorTo(end2); Vector3d vector3D = vector3D1 + vector3D2; dimLineAngular.TextPosition = new Point3d((end1.X + end2.X) / 2, (end1.Y + end2.Y) / 2, (end1.Z + end2.Z) / 2).TransformBy(Matrix3d.Displacement(vector3D * distance));; dimLineAngular.DimensionStyle = dimid; dimLineAngular.Layer = "Dim_Layer"; space.AppendEntity(dimLineAngular); trans.AddNewlyCreatedDBObject(dimLineAngular, true); trans.Commit(); } }
static public void OpenJoint() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction tx = db.TransactionManager.StartTransaction()) { // Asking for user inputs and var casting PromptDoubleOptions pdopt = new PromptDoubleOptions("Enter open joint size : \n"); pdopt.AllowZero = false; pdopt.AllowNegative = false; pdopt.DefaultValue = 0.5; pdopt.AllowNone = false; PromptDoubleResult pdres = ed.GetDouble(pdopt); if (pdres.Status != PromptStatus.OK) { return; } double size = pdres.Value; PromptEntityOptions peopt_1 = new PromptEntityOptions("\nSelect first line : \n"); peopt_1.SetRejectMessage("\nSelect only lines"); peopt_1.AddAllowedClass(typeof(Line), false); peopt_1.AllowNone = false; PromptEntityResult peres_1 = ed.GetEntity(peopt_1); if (peres_1.Status != PromptStatus.OK) { return; } ObjectId line1_id = peres_1.ObjectId; ed.WriteMessage(line1_id.ToString()); PromptEntityOptions peopt_2 = new PromptEntityOptions("\nSelect second line : \n"); peopt_2.SetRejectMessage("\nSelect only lines"); peopt_2.AddAllowedClass(typeof(Line), false); peopt_2.AllowNone = false; PromptEntityResult peres_2 = ed.GetEntity(peopt_2); if (peres_2.Status != PromptStatus.OK) { return; } ObjectId line2_id = peres_2.ObjectId; ed.WriteMessage(line2_id.ToString()); // Oid > Entity > Line Entity line1_ent = tx.GetObject(line1_id, OpenMode.ForWrite) as Entity; Entity line2_ent = tx.GetObject(line2_id, OpenMode.ForWrite) as Entity; Line line1 = line1_ent as Line; Line line2 = line2_ent as Line; // Get intersection point > Check parallelity > re-orient lines Point3dCollection intptcoll = new Point3dCollection(); line1.IntersectWith(line2, Intersect.OnBothOperands, intptcoll, 0, 0); if (intptcoll.Count != 1) { Application.ShowAlertDialog("Lines are parallel or not intersecting"); ed.WriteMessage(intptcoll.Count.ToString()); return; } Point3d intpt = intptcoll[0]; //---APEX if (line1.StartPoint.Equals(intpt) != true) { line1.EndPoint = line1.StartPoint; line1.StartPoint = intpt; } if (line2.StartPoint.Equals(intpt) != true) { line2.EndPoint = line2.StartPoint; line2.StartPoint = intpt; } double anglin = AngleBetweenLines(line1.StartPoint, line2.StartPoint, line1.EndPoint, line2.EndPoint); ed.WriteMessage("\nAngle between lines : " + anglin); // Calculate line angles LineAngularDimension2 angdim12 = new LineAngularDimension2(); angdim12.XLine1Start = line1.StartPoint; angdim12.XLine2Start = line2.StartPoint; angdim12.XLine1End = line1.EndPoint; angdim12.XLine2End = line2.EndPoint; // Derive bisector geometry Point3d midpt1 = line1.GetPointAtDist(size); Point3d midpt2 = line2.GetPointAtDist(size); Point3d ovpt1 = line1.GetPointAtDist(2 * size); Point3d ovpt2 = line2.GetPointAtDist(2 * size); Point3d midptbis = new Point3d((midpt1.X + midpt2.X) / 2.0, (midpt1.Y + midpt2.Y) / 2.0, (midpt1.Z + midpt2.Z) / 2.0); Point3d ovptbis = new Point3d((ovpt1.X + ovpt2.X) / 2.0, (ovpt1.Y + ovpt2.Y) / 2.0, (ovpt1.Z + ovpt2.Z) / 2.0); Line linebis = new Line(intpt, ovptbis); double hypothenusedistance = (size / Math.Cos(anglin / 2)); if (hypothenusedistance < 0) { hypothenusedistance = hypothenusedistance * (-1); } ed.WriteMessage("\nhypothenusedistance : " + hypothenusedistance); Point3d endptbis = linebis.GetPointAtDist(hypothenusedistance); //<------ BlockTableRecord btrec = tx.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; line1.StartPoint = midpt1; line2.StartPoint = midpt2; using (Line line3 = new Line(endptbis, midpt1)) { btrec.AppendEntity(line3); tx.AddNewlyCreatedDBObject(line3, true); } using (Line line4 = new Line(endptbis, midpt2)) { btrec.AppendEntity(line4); tx.AddNewlyCreatedDBObject(line4, true); } tx.Commit(); } }
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); }
Entity[] MakeGouJian(Param param) { Point2d[] p2ds = new Point2d[] { Point2d.Origin, Point2d.Origin + Vector2d.YAxis * param.A, Point2d.Origin + Vector2d.YAxis * param.A - Vector2d.XAxis * param.D, Point2d.Origin + Vector2d.YAxis * param.B - Vector2d.XAxis * (param.C - param.E), Point2d.Origin + Vector2d.YAxis * param.B - Vector2d.XAxis * param.C, Point2d.Origin - Vector2d.XAxis * param.C }; Vector2d vec1 = p2ds[1] - p2ds[2]; Vector2d vec2 = p2ds[3] - p2ds[2]; //倒角 Point2d[] AnglePoint = GetAnglePoint(p2ds[2], vec1, vec2, 0.1); Vector2d vec3 = p2ds[0] - p2ds[1]; Vector2d vec4 = p2ds[2] - p2ds[1]; Point2d[] AnglePoint0 = GetAnglePoint(p2ds[1], vec3, vec4, 0.1); Polyline pline0 = EntityHelper.CreatePolygon( new double[] { p2ds[0].X, p2ds[0].Y, AnglePoint0[1].X, AnglePoint0[1].Y, AnglePoint0[0].X, AnglePoint0[0].Y, p2ds[1].X - param.D * 0.5, p2ds[1].Y, AnglePoint[1].X, AnglePoint[1].Y, AnglePoint[0].X, AnglePoint[0].Y, p2ds[3].X, p2ds[3].Y, p2ds[4].X, p2ds[4].Y, p2ds[5].X, p2ds[5].Y, }, new Tuple <int, double>[] { Tuple.Create(4, Math.Tan((Math.PI - vec2.GetAngleTo(vec1)) / 4)), Tuple.Create(1, Math.Tan((Math.PI - vec4.GetAngleTo(vec3)) / 4)) }, null, null ); AlignedDimension alignDim1 = new AlignedDimension(Point3d.Origin, Point3d.Origin + Vector3d.YAxis * param.A, Point3d.Origin + Vector3d.XAxis * 0.5, null, ObjectId.Null); AlignedDimension alignDim2 = new AlignedDimension(Point3d.Origin + Vector3d.YAxis * param.A, Point3d.Origin + Vector3d.YAxis * param.A - Vector3d.XAxis * param.D, Point3d.Origin + Vector3d.YAxis * 3.5, null, ObjectId.Null); AlignedDimension alignDim3 = new AlignedDimension(Point3d.Origin + Vector3d.YAxis * param.B - Vector3d.XAxis * (param.C - param.E), Point3d.Origin + Vector3d.YAxis * param.B - Vector3d.XAxis * param.C, Point3d.Origin + Vector3d.YAxis * (param.B + 0.5), null, ObjectId.Null); AlignedDimension alignDim4 = new AlignedDimension(Point3d.Origin + Vector3d.YAxis * param.B - Vector3d.XAxis * param.C, Point3d.Origin - Vector3d.XAxis * param.C, Point3d.Origin - Vector3d.XAxis * (param.C + 0.5), null, ObjectId.Null); AlignedDimension alignDim5 = new AlignedDimension(Point3d.Origin - Vector3d.XAxis * param.C, Point3d.Origin, Point3d.Origin - Vector3d.YAxis * 0.5, null, ObjectId.Null); LineAngularDimension2 langularDim = new LineAngularDimension2(new Point3d(p2ds[3].X, p2ds[3].Y, 0), new Point3d(p2ds[2].X, p2ds[2].Y, 0), new Point3d(p2ds[3].X, p2ds[3].Y, 0), new Point3d(p2ds[4].X, p2ds[4].Y, 0), new Point3d(p2ds[3].X - 0.8, p2ds[3].Y + 0.8, 0), null, ObjectId.Null ); Xline xline = new Xline() { BasePoint = new Point3d(0, param.A * 0.5, 0), UnitDir = Vector3d.XAxis }; DBText d1 = new DBText() { TextString = "A", Position = new Point3d(-0.15, param.A * 0.5, 0) }; HatchLoop hLoop = new HatchLoop(HatchLoopTypes.Polyline); foreach (var i in Enumerable.Range(0, pline0.NumberOfVertices)) { hLoop.Polyline.Add(new BulgeVertex(pline0.GetPoint2dAt(i), pline0.GetBulgeAt(i))); } Hatch hatch = new Hatch(); hatch.SetHatchPattern(HatchPatternType.PreDefined, "BOX"); hatch.AppendLoop(hLoop); return(new Entity[] { pline0, alignDim1, alignDim2, alignDim3, alignDim4, alignDim5, d1, hatch, langularDim, xline }); }
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()); }
private void button1_Click(object sender, EventArgs e) { // Declare the input variables double intDia = double.Parse(textBox_intDia.Text); double extDia = double.Parse(textBox_extDia.Text); double height = double.Parse(textBox_height.Text); double crossSection = (extDia - intDia) * 0.5; // Boolean : Endless/Split Boolean endless = true; Boolean split = false; // Input validation Boolean isDataValidated = true; // Get the document object Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; ///// Transferred to the class Global.cs //// Prompt for the insertion point //PromptPointResult insertPointResult; //PromptPointOptions insertPointOption = new PromptPointOptions(""); //insertPointOption.Message = "\nClick the point where you want to insert the profile UN : "; //insertPointResult = doc.Editor.GetPoint(insertPointOption); //Point3d insertPoint = insertPointResult.Value; //// Exit if the user presses ESC or cancels the command //if (insertPointResult.Status == PromptStatus.Cancel) return; ////// DATA VALIDATION /////////////////////////////////////////// // int Dia. > ext Dia. if (intDia >= extDia) { labelWarning.Text = "int.Diameter must be smaller than ext.Diameter!"; isDataValidated = false; } // too low height if (height <= 3) { labelWarning.Text = "Height is too small!"; isDataValidated = false; } // too high height if (height > 45) { labelWarning.Text = "Height is too big!"; isDataValidated = false; } // Feasible range if (crossSection < 5 || crossSection > 35) { labelWarning.Text = "Cross-section is out of range!\n(5 <= F <= 35)"; isDataValidated = false; } // Null input // Internal diameter (Null) if (string.IsNullOrEmpty(this.textBox_intDia.Text)) { labelWarning.Text = "Please insert the value of int.Diameter!"; isDataValidated = false; } // External diameter (Null) if (string.IsNullOrEmpty(this.textBox_extDia.Text)) { labelWarning.Text = "Please insert the value of ext.Diameter!"; isDataValidated = false; } // Height (Null) if (string.IsNullOrEmpty(this.textBox_height.Text)) { labelWarning.Text = "Please insert the value of the height!"; isDataValidated = false; } // Process futher only if all the condition has been met // Prompt for the insertion point if (isDataValidated == true) { this.Hide(); Global.Point.getInsertionPoint("\nClick the point where you want to insert the profile : ", doc); } // Locking the document using (DocumentLock docLock = doc.LockDocument()) { // Transaction using (Transaction trans = db.TransactionManager.StartTransaction()) { try { BlockTable bt; bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr; btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; double insertPointX = Global.Point.insertPoint.X; double insertPointY = Global.Point.insertPoint.Y; Point3d insertPoint = new Point3d(insertPointX, insertPointY, 0); // Define the dimensions of tacche // Dimensions are according to TAB_27 double dimB = 1; double dimD = 1; if (crossSection >= 5 && crossSection <= 7.5) { dimB = 1.5; dimD = 1.5; } else if (crossSection > 7.5 && crossSection < 12.5) { dimB = 2; dimD = 1.5; } else if (crossSection >= 12.5 && crossSection < 15) { dimB = 2.5; dimD = 1.5; } else if (crossSection >= 15 && crossSection < 17.5) { dimB = 3; dimD = 1.5; } else if (crossSection >= 17.5 && crossSection < 22) { dimB = 3.5; dimD = 2; } else if (crossSection >= 22 && crossSection < 27.6) { dimB = 3.5; dimD = 2.5; } else if (crossSection >= 27.6) { dimB = 3.5; dimD = 3; } else { dimB = 4; dimD = 3.5; } // Number of tacche double numTacche = 2; if (extDia <= 300) { numTacche = 2; } else if (extDia > 300 && extDia <= 500) { numTacche = 4; } else if (extDia > 500 && extDia <= 700) { numTacche = 6; } else if (extDia > 700 && extDia <= 1100) { numTacche = 8; } else if (extDia > 1100 && extDia <= 1500) { numTacche = 12; } else if (extDia > 1500) { numTacche = 16; } else { numTacche = 20; } // Define the dimension of the bottom height // dimE = total height - height imp (altezzaColl) double dimE = 1; if (crossSection <= 7.5) { dimE = 2; } else if (crossSection > 7.5 && crossSection < 10) { dimE = 2.5; } else if (crossSection >= 10 && crossSection < 12.5) { dimE = 3; } else if (crossSection >= 12.5 && crossSection < 15) { dimE = 3.5; } else if (crossSection >= 15 && crossSection < 17.5) { dimE = 4; } else if (crossSection >= 17.5 && crossSection < 20) { dimE = 4.5; } else if (crossSection >= 20 && crossSection < 22.5) { dimE = 5; } else if (crossSection >= 22.5 && crossSection < 25) { dimE = 5.5; } else if (crossSection >= 25 && crossSection < 27.5) { dimE = 6; } else if (crossSection >= 27.5 && crossSection < 30) { dimE = 6.5; } else if (crossSection >= 30 && crossSection < 32.5) { dimE = 7; } else if (crossSection >= 32.5 && crossSection < 35) { dimE = 7.5; } else { dimE = 8; } // Fascia gap /////////////////////// To be defined x = Fnom-Fcoll. double fasciaGap = 1; if (crossSection <= 8) { fasciaGap = 0.4; } else if (crossSection > 8 && crossSection < 10) { fasciaGap = 0.5; } else if (crossSection >= 10 && crossSection < 10.6) { fasciaGap = 0.6; } else if (crossSection >= 10.6 && crossSection < 14) { fasciaGap = 0.8; } else if (crossSection >= 14 && crossSection < 20.1) { fasciaGap = 1; } else if (crossSection >= 20.1 && crossSection < 23.9) { fasciaGap = 1.2; } else if (crossSection >= 23.9 && crossSection < 26.1) { fasciaGap = 1.3; } else if (crossSection >= 26.1 && crossSection < 27.6) { fasciaGap = 1.4; } else if (crossSection >= 27.6 && crossSection < 30.1) { fasciaGap = 1.5; } else if (crossSection >= 30.1 && crossSection < 35.1) { fasciaGap = 1.6; } else { fasciaGap = 1.8; } // Calculate each point of the profile double point2X = insertPointX; double point2Y = insertPointY - dimB; double point3X = insertPointX - dimD; double point3Y = point2Y; double point4X = point3X; double point4Y = point3Y - (height - dimB); double point5X = point4X; double point5Y = point4Y - (dimE / Math.Sin((45 * (Math.PI / 180)))); double point10X = insertPointX + (crossSection - fasciaGap - (2 * dimD)); double point10Y = insertPointY; double point9X = point10X; double point9Y = point10Y - dimB; double point8X = point9X + dimD; double point8Y = point9Y; double point7X = point8X; double point7Y = point4Y; double point6X = point7X; double point6Y = point7Y - (dimE / Math.Sin((45 * (Math.PI / 180)))); // Create the points with the X,Y point values above Point3d point2 = new Point3d(point2X, point2Y, 0); Point3d point3 = new Point3d(point3X, point3Y, 0); Point3d point4 = new Point3d(point4X, point4Y, 0); Point3d point5 = new Point3d(point5X, point5Y, 0); Point3d point6 = new Point3d(point6X, point6Y, 0); Point3d point7 = new Point3d(point7X, point7Y, 0); Point3d point8 = new Point3d(point8X, point8Y, 0); Point3d point9 = new Point3d(point9X, point9Y, 0); Point3d point10 = new Point3d(point10X, point10Y, 0); //// point5 & point 6 shall be rotated 45°/-45° //Matrix3d currentMatrix = doc.Editor.CurrentUserCoordinateSystem; //CoordinateSystem3d crdSystem = currentMatrix.CoordinateSystem3d; //point5.TransformBy(Matrix3d.Rotation(45 * (Math.PI / 180), crdSystem.Zaxis, point4)); //point6.TransformBy(Matrix3d.Rotation(-45 * (Math.PI / 180), crdSystem.Zaxis, point7)); //// Draw the profile as polyline //using (Polyline pl = new Polyline()) //{ // pl.AddVertexAt(0, new Point2d(point7X, point7Y), 0, 0, 0); // pl.AddVertexAt(1, new Point2d(point8X, point8Y), 0, 0, 0); // pl.AddVertexAt(2, new Point2d(point9X, point9Y), 0, 0, 0); // pl.AddVertexAt(3, new Point2d(point10X, point10Y), 0, 0, 0); // pl.AddVertexAt(4, new Point2d(insertPointX, insertPointY), 0, 0, 0); // pl.AddVertexAt(5, new Point2d(point2X, point2Y), 0, 0, 0); // pl.AddVertexAt(6, new Point2d(point3X, point3Y), 0, 0, 0); // pl.AddVertexAt(7, new Point2d(point4X, point4Y), 0, 0, 0); // pl.AddVertexAt(8, new Point2d(point5X, point5Y), 0, 0, 0); // pl.AddVertexAt(9, new Point2d(point6X, point6Y), 0, 0, 0); // pl.Closed = true; // //pl.ColorIndex = 1; // pl.SetDatabaseDefaults(); // btr.AppendEntity(pl); // trans.AddNewlyCreatedDBObject(pl, true); //} // Draw the profile section Line ln12 = new Line(insertPoint, point2); Line ln23 = new Line(point2, point3); Line ln34 = new Line(point3, point4); Line ln45 = new Line(point4, point5); //Line ln56 = new Line(point5, point6); Line ln67 = new Line(point6, point7); Line ln78 = new Line(point7, point8); Line ln89 = new Line(point8, point9); Line ln910 = new Line(point9, point10); Line ln101 = new Line(point10, insertPoint); // Point 5 & 6 shall be roated 45° / -45° double pointRotated5X = point5X + dimE; double pointRotated5Y = point5Y + (dimE / Math.Sin((45 * (Math.PI / 180)))) - dimE; double pointRotated6X = point6X - dimE; double pointRotated6Y = point6Y + (dimE / Math.Sin((45 * (Math.PI / 180)))) - dimE; Point3d pointRotated5 = new Point3d(pointRotated5X, pointRotated5Y, 0); Point3d pointRotated6 = new Point3d(pointRotated6X, pointRotated6Y, 0); Line ln56 = new Line(pointRotated5, pointRotated6); // Plot Line[] profileLineArray1 = new Line[] { ln12, ln23, ln34, ln56, ln78, ln89, ln910, ln101 }; for (int i = 0; i < 8; i++) { btr.AppendEntity(profileLineArray1[i]); trans.AddNewlyCreatedDBObject(profileLineArray1[i], true); } // ln45 & ln67 shall be rotated 45°/-45° Matrix3d currentMatrix = doc.Editor.CurrentUserCoordinateSystem; CoordinateSystem3d crdSystem = currentMatrix.CoordinateSystem3d; ln45.TransformBy(Matrix3d.Rotation(45 * (Math.PI / 180), crdSystem.Zaxis, point4)); ln67.TransformBy(Matrix3d.Rotation(-45 * (Math.PI / 180), crdSystem.Zaxis, point7)); // Plot rotated 2 lines : ln45 & ln67 ln45.SetDatabaseDefaults(); btr.AppendEntity(ln45); trans.AddNewlyCreatedDBObject(ln45, true); ln67.SetDatabaseDefaults(); btr.AppendEntity(ln67); trans.AddNewlyCreatedDBObject(ln67, true); // Profile line layer (Disegno) Line[] profileLineArray2 = new Line[] { ln12, ln23, ln34, ln45, ln56, ln67, ln78, ln89, ln910, ln101 }; for (int i = 0; i < 10; i++) { profileLineArray2[i].Layer = "DISEGNO"; } // Center line (Axis) double axisPoint1X = point8X + 10 + (crossSection * 0.75); // 10 = length of tacche double axisPoint2X = point8X + 10 + (crossSection * 0.75); // 10 = length of tacche double axisPoint3X = point8X + 10 + (crossSection * 0.75); // 10 = length of tacche double axisPoint4X = point8X + 10 + (crossSection * 0.75); // 10 = length of tacche double axisPoint1Y = point10Y; double axisPoint2Y = point8Y; double axisPoint3Y = point7Y; double axisPoint4Y = point7Y - dimE; Point3d pointCnt1 = new Point3d(axisPoint1X, axisPoint1Y, 0); Point3d pointCnt2 = new Point3d(axisPoint2X, axisPoint2Y, 0); Point3d pointCnt3 = new Point3d(axisPoint3X, axisPoint3Y, 0); Point3d pointCnt4 = new Point3d(axisPoint4X, axisPoint4Y, 0); // Tacche // Calculate each point of tacche // X value double pointTacche1X = point10X + (crossSection * 0.5); double pointTacche2X = pointTacche1X; double pointTacche3X = point10X + (crossSection * 0.5) + 10; double pointTacche4X = pointTacche3X; // Y value double pointTacche1Y = point10Y; double pointTacche2Y = pointTacche1Y - dimB; double pointTacche3Y = pointTacche2Y; double pointTacche4Y = pointTacche1Y; // Tacche points Point3d pointTacche1 = new Point3d(pointTacche1X, pointTacche1Y, 0); Point3d pointTacche2 = new Point3d(pointTacche2X, pointTacche2Y, 0); Point3d pointTacche3 = new Point3d(pointTacche3X, pointTacche3Y, 0); Point3d pointTacche4 = new Point3d(pointTacche4X, pointTacche4Y, 0); // Center lines // Profile lines to the center line Line lnCnt11 = new Line(point10, pointTacche1); Line lnCnt12 = new Line(pointTacche4, pointCnt1); Line lnCnt21 = new Line(point8, pointTacche2); Line lnCnt22 = new Line(pointTacche3, pointCnt2); Line lnCnt3 = new Line(point7, pointCnt3); Line lnCnt4 = new Line(pointRotated6, pointCnt4); // Plot + Layer Line[] centerLineArray = new Line[] { lnCnt11, lnCnt12, lnCnt21, lnCnt22, lnCnt3, lnCnt4 }; for (int i = 0; i < 6; i++) { btr.AppendEntity(centerLineArray[i]); trans.AddNewlyCreatedDBObject(centerLineArray[i], true); centerLineArray[i].Layer = "DISEGNO"; } // Tacche // Tacche lines Line lnTacche2 = new Line(pointTacche1, pointTacche2); Line lnTacche3 = new Line(pointTacche2, pointTacche3); Line lnTacche4 = new Line(pointTacche3, pointTacche4); // Plot + Layer Line[] taccheLineArray = new Line[] { lnTacche2, lnTacche3, lnTacche4 }; for (int i = 0; i < 3; i++) { btr.AppendEntity(taccheLineArray[i]); trans.AddNewlyCreatedDBObject(taccheLineArray[i], true); taccheLineArray[i].Layer = "DISEGNO"; } // Axis line in drawing // Calculate 2 points double pointAxisDwg1X = axisPoint1X; double pointAxisDwg2X = axisPoint1X; double pointAxisDwg1Y = axisPoint1Y + dimB; double pointAxisDwg2Y = axisPoint4Y - dimB; // Axis line in drawing point3d Point3d pointAxisDwg1 = new Point3d(pointAxisDwg1X, pointAxisDwg1Y, 0); Point3d pointAxisDwg2 = new Point3d(pointAxisDwg2X, pointAxisDwg2Y, 0); // Draw the line Line axisLineDwg = new Line(pointAxisDwg1, pointAxisDwg2); btr.AppendEntity(axisLineDwg); trans.AddNewlyCreatedDBObject(axisLineDwg, true); // Line layer (Assi) axisLineDwg.Layer = "ASSI"; // Actual axis line // ENDLESS/SPLIT selection double endlessSplit = 0; string endlessText = ""; string splitText = ""; if (radioButton_endless.Checked == true) { endlessSplit = 0; endless = true; endlessText = "Endless (Intera)"; } else if (radioButton_split.Checked == true) { endlessSplit = 0.5; split = true; splitText = "Double splits"; } // Calculate 2 points double pointAxisReal1X = ((point3X + point8X) * 0.5) + ((intDia + extDia) * 0.25) + endlessSplit; double pointAxisReal1Y = pointAxisDwg1Y; double pointAxisReal2X = pointAxisReal1X; double pointAxisReal2Y = pointAxisDwg2Y; // point Point3d pointAxisReal1 = new Point3d(pointAxisReal1X, pointAxisReal1Y, 0); Point3d pointAxisReal2 = new Point3d(pointAxisReal2X, pointAxisReal2Y, 0); Line lnAxisReal = new Line(pointAxisReal1, pointAxisReal2); btr.AppendEntity(lnAxisReal); trans.AddNewlyCreatedDBObject(lnAxisReal, true); // Line layer (Assi) lnAxisReal.Layer = "DEFPOINTS"; // Create the aligned dimension ////////////////////////////////////////////////////// // Tolerance variables double tollFascia = 0.1; double tollAltezzaColl = 0.1; double tollAltezzaTotal = 0.1; // Cross-section tolerance range (F = 15) if ((point8X - point3X) < 15) { tollFascia = 0.1; } else if ((point8X - point3X) >= 15) { tollFascia = 0.15; } // Altezza Coll. (Height imp) if ((insertPointY - point4Y) < 15) { tollAltezzaColl = 0.1; } else if ((insertPointY - point4Y) >= 15) { tollAltezzaColl = 0.15; } // Altezza total (Total height) if ((insertPointY - pointRotated5Y) < 15) { tollAltezzaTotal = 0.1; } else if ((insertPointY - pointRotated5Y) >= 15) { tollAltezzaTotal = 0.15; } // Open the dimension style and set it to "P" DimStyleTableRecord dstr = new DimStyleTableRecord(); DimStyleTable dst = trans.GetObject(db.DimStyleTableId, OpenMode.ForRead) as DimStyleTable; ObjectId dimStyleP = dst["P"]; doc.Database.Dimstyle = dimStyleP; // Fascia Coll RotatedDimension fasciaColl = new RotatedDimension(); fasciaColl.SetDatabaseDefaults(); fasciaColl.XLine1Point = point8; fasciaColl.XLine2Point = point3; fasciaColl.DimLinePoint = new Point3d(0, insertPointY + (dimB * 2.8), 0); fasciaColl.Layer = "QUOTE"; fasciaColl.DimensionStyle = doc.Database.Dimstyle; // Tolerance fasciaColl.Dimtol = true; fasciaColl.Dimtp = tollFascia; fasciaColl.Dimtm = tollFascia; // Add the new object to Model space and the transaction btr.AppendEntity(fasciaColl); trans.AddNewlyCreatedDBObject(fasciaColl, true); // Dimension D (TAB_27) RotatedDimension dimensionD = new RotatedDimension(); dimensionD.SetDatabaseDefaults(); dimensionD.XLine1Point = point3; dimensionD.XLine2Point = insertPoint; dimensionD.DimLinePoint = new Point3d(0, insertPointY + (dimB * 1.25), 0); dimensionD.Layer = "QUOTE"; dimensionD.DimensionStyle = doc.Database.Dimstyle; // Add the new object to Model space and the transaction btr.AppendEntity(dimensionD); trans.AddNewlyCreatedDBObject(dimensionD, true); // Dimension B (TAB_27) RotatedDimension dimensionB = new RotatedDimension(); dimensionB.SetDatabaseDefaults(); dimensionB.XLine1Point = insertPoint; dimensionB.XLine2Point = point3; dimensionB.Rotation = Math.PI / 2; dimensionB.DimLinePoint = new Point3d(point3X - (dimD * 1.5), 0, 0); dimensionB.Layer = "QUOTE"; dimensionB.DimensionStyle = doc.Database.Dimstyle; // Add the new object to Model space and the transaction btr.AppendEntity(dimensionB); trans.AddNewlyCreatedDBObject(dimensionB, true); // Altezza coll (height) RotatedDimension altezzaColl = new RotatedDimension(); altezzaColl.SetDatabaseDefaults(); altezzaColl.XLine1Point = insertPoint; altezzaColl.XLine2Point = point4; altezzaColl.Rotation = Math.PI / 2; altezzaColl.DimLinePoint = new Point3d(point3X - (dimD * 2.8), (point3Y + point4Y) * 0.5, 0); altezzaColl.Layer = "QUOTE"; altezzaColl.DimensionStyle = doc.Database.Dimstyle; // Tolerance altezzaColl.Dimtol = true; altezzaColl.Dimtp = tollAltezzaColl; altezzaColl.Dimtm = tollAltezzaColl; // Add the new object to Model space and the transaction btr.AppendEntity(altezzaColl); trans.AddNewlyCreatedDBObject(altezzaColl, true); // Altezza total (total height) RotatedDimension altezzaTotal = new RotatedDimension(); altezzaTotal.SetDatabaseDefaults(); altezzaTotal.XLine1Point = insertPoint; altezzaTotal.XLine2Point = pointRotated5; altezzaTotal.Rotation = Math.PI / 2; altezzaTotal.DimLinePoint = new Point3d(point3X - (dimD * 4.15), (insertPointY + pointRotated5Y) * 0.5, 0); altezzaTotal.Layer = "QUOTE"; altezzaTotal.DimensionStyle = doc.Database.Dimstyle; // Tolerance altezzaTotal.Dimtol = true; altezzaTotal.Dimtp = tollAltezzaTotal; altezzaTotal.Dimtm = tollAltezzaTotal; // Add the new object to Model space and the transaction btr.AppendEntity(altezzaTotal); trans.AddNewlyCreatedDBObject(altezzaTotal, true); // Tacche (Dimension A = 10, TAB_27) RotatedDimension dimensionA = new RotatedDimension(); dimensionA.SetDatabaseDefaults(); dimensionA.XLine1Point = pointTacche1; dimensionA.XLine2Point = pointTacche4; dimensionA.DimLinePoint = new Point3d(0, insertPointY + (dimB * 1.25), 0); dimensionA.Layer = "QUOTE"; dimensionA.DimensionStyle = doc.Database.Dimstyle; // Add the new object to Model space and the transaction btr.AppendEntity(dimensionA); trans.AddNewlyCreatedDBObject(dimensionA, true); // Create an angular dimension (90°) LineAngularDimension2 acLinAngDim = new LineAngularDimension2(); acLinAngDim.SetDatabaseDefaults(); acLinAngDim.XLine1Start = point4; acLinAngDim.XLine1End = pointRotated5; acLinAngDim.XLine2Start = pointRotated6; acLinAngDim.XLine2End = point7; acLinAngDim.ArcPoint = new Point3d((point4X + point7X) * 0.5, point4Y + 2, 0); acLinAngDim.Layer = "QUOTE"; acLinAngDim.DimensionStyle = doc.Database.Dimstyle; // Add the new object to Model space and the transaction btr.AppendEntity(acLinAngDim); trans.AddNewlyCreatedDBObject(acLinAngDim, true); // External diameter coll. // Diameter dimensions (P-D2) ObjectId dimStylePD2 = dst["P-D2"]; RotatedDimension extDiaColl = new RotatedDimension(); extDiaColl.SetDatabaseDefaults(); extDiaColl.XLine1Point = new Point3d(pointAxisReal1X, point8Y, 0); extDiaColl.XLine2Point = point3; extDiaColl.DimLinePoint = new Point3d(point8X, insertPointY + (dimB * 4.05), 0); extDiaColl.Layer = "QUOTE"; doc.Database.Dimstyle = dimStylePD2; extDiaColl.DimensionStyle = doc.Database.Dimstyle; // Tolerance // External diameter extDiaColl.Dimtol = true; double tollExtDia = 1; if (split == true) { if (((pointAxisReal1X - point3X) * 2) <= 1000) { extDiaColl.Dimtp = 1; extDiaColl.Dimtm = 0; } else if (((pointAxisReal1X - point3X) * 2) > 1000) { tollExtDia = Math.Round(extDia * 0.001, 2); extDiaColl.Dimtp = tollExtDia; extDiaColl.Dimtm = 0; } } else if (endless == true) { if (((pointAxisReal1X - point3X) * 2) > 600) { tollExtDia = extDia * 0.001; extDiaColl.Dimtp = tollExtDia; extDiaColl.Dimtm = 0; } else if (((pointAxisReal1X - point3X) * 2) <= 200) { tollExtDia = 0.15; extDiaColl.Dimtp = tollExtDia; extDiaColl.Dimtm = tollExtDia; } else if (((pointAxisReal1X - point3X) * 2) > 200 && ((pointAxisReal1X - point3X) * 2) <= 400) { tollExtDia = 0.2; extDiaColl.Dimtp = tollExtDia; extDiaColl.Dimtm = tollExtDia; } else if (((pointAxisReal1X - point3X) * 2) > 400 && ((pointAxisReal1X - point3X) * 2) <= 600) { tollExtDia = 0.25; extDiaColl.Dimtp = tollExtDia; extDiaColl.Dimtm = tollExtDia; } } // Add the new object to Model space and the transaction btr.AppendEntity(extDiaColl); trans.AddNewlyCreatedDBObject(extDiaColl, true); // Diameter at point5 RotatedDimension diaPoint5 = new RotatedDimension(); diaPoint5.SetDatabaseDefaults(); diaPoint5.XLine1Point = new Point3d(pointAxisReal1X, pointRotated5Y, 0); diaPoint5.XLine2Point = pointRotated5; diaPoint5.DimLinePoint = new Point3d(pointRotated5X, pointRotated5Y - (dimB * 2.2), 0); diaPoint5.Layer = "QUOTE"; doc.Database.Dimstyle = dimStylePD2; diaPoint5.DimensionStyle = doc.Database.Dimstyle; // Add the new object to Model space and the transaction btr.AppendEntity(diaPoint5); trans.AddNewlyCreatedDBObject(diaPoint5, true); // Diameter at point6 RotatedDimension diaPoint6 = new RotatedDimension(); diaPoint6.SetDatabaseDefaults(); diaPoint6.XLine1Point = new Point3d(pointAxisReal1X, pointRotated6Y, 0); diaPoint6.XLine2Point = pointRotated6; diaPoint6.DimLinePoint = new Point3d(pointRotated6X, pointRotated6Y - (dimB * 1.2), 0); diaPoint6.Layer = "QUOTE"; doc.Database.Dimstyle = dimStylePD2; diaPoint6.DimensionStyle = doc.Database.Dimstyle; // Add the new object to Model space and the transaction btr.AppendEntity(diaPoint6); trans.AddNewlyCreatedDBObject(diaPoint6, true); // Internal diameter coll. RotatedDimension intDiaColl = new RotatedDimension(); intDiaColl.SetDatabaseDefaults(); intDiaColl.XLine1Point = new Point3d(pointAxisReal1X, point8Y, 0); intDiaColl.XLine2Point = point8; intDiaColl.DimLinePoint = new Point3d(point8X, insertPointY + (dimB * 2.8), 0); // Override the dimension (ref.) intDiaColl.DimensionText = "(<>)"; //acRotDim.DimensionStyle = acCurDb.Dimstyle; intDiaColl.Layer = "QUOTE"; doc.Database.Dimstyle = dimStylePD2; intDiaColl.DimensionStyle = doc.Database.Dimstyle; // Add the new object to Model space and the transaction btr.AppendEntity(intDiaColl); trans.AddNewlyCreatedDBObject(intDiaColl, true); // Get the dimension style from P-D2 to P doc.Database.Dimstyle = dimStyleP; ///// Create the leader /////////////////////////////////////////////////////// Leader leader = new Leader(); leader.SetDatabaseDefaults(); leader.AppendVertex(new Point3d(pointTacche2X + 2, pointTacche2Y, 0)); // Verify the space for leader text if ((point8Y - point7Y) >= 6.5) { leader.AppendVertex(new Point3d(pointTacche2X + 2, pointTacche2Y - dimB, 0)); leader.AppendVertex(new Point3d(pointTacche2X + 3, pointTacche2Y - dimB, 0)); } else if ((point8Y - point7Y) < 6.5) { leader.AppendVertex(new Point3d(pointTacche2X + 2, pointRotated6Y - dimB, 0)); leader.AppendVertex(new Point3d(pointTacche2X + 3, pointRotated6Y - dimB, 0)); } leader.HasArrowHead = true; leader.Layer = "QUOTE"; // Add the new object to Model space and the transaction btr.AppendEntity(leader); trans.AddNewlyCreatedDBObject(leader, true); // Create the leader text (TACCHE COME DA ...) MText leaderText = new MText(); leaderText.SetDatabaseDefaults(); // Verify the space for leader text if ((point8Y - point7Y) >= 6.5) { leaderText.Location = new Point3d(pointTacche2X + 3, pointTacche2Y - dimB + 0.5, 0); // Connected to the third point of the leader } else if ((point8Y - point7Y) < 6.5) { leaderText.Location = new Point3d(pointTacche2X + 3, pointRotated6Y - dimB + 0.5, 0); // Connected to the third point of the leader } leaderText.Width = 15; // Adjust text height double textHeight = 1; if (crossSection < 11) { textHeight = 0.8; } leaderText.TextHeight = textHeight; leaderText.Layer = "0"; leaderText.Contents = "TACCHE COME DA\nTAB_27\nN°" + numTacche + "x" + dimB + "x10"; // Add the new object to Model space and the transaction btr.AppendEntity(leaderText); trans.AddNewlyCreatedDBObject(leaderText, true); ////// HATCH ////////////////////////////////////////////////////////////////////// // Create the hatches // Adds the circle to an object id array ObjectIdCollection acObjIdColl = new ObjectIdCollection(); for (int i = 0; i < 10; i++) { acObjIdColl.Add(profileLineArray2[i].ObjectId); } // Create the hatch object and append it to the block table record Hatch acHatch = new Hatch(); // Add the new object to Model space and the transaction btr.AppendEntity(acHatch); trans.AddNewlyCreatedDBObject(acHatch, true); // Set the properties of the hatch object // Associative must be set after the hatch object is appended to the // block table record and before AppendLoop acHatch.SetDatabaseDefaults(); acHatch.Layer = "FINE"; // Adjust the pattern scale double patternScale = 1; if (crossSection < 10) { patternScale = 0.15; } else if (crossSection >= 10 && crossSection < 19) { patternScale = 0.25; } else if (crossSection >= 19 && crossSection < 34) { patternScale = 0.5; } acHatch.PatternScale = patternScale; // Pattern scale to be defined according to the size of crossSection // Material type (Nylon / PTFE) string matNylon = ""; string matPTFE = ""; if (radioButton_nylon.Checked == true) { acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI32"); matNylon = "Nylon (PA6)"; } else if (radioButton_ptfe.Checked == true) { acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI34"); matPTFE = "PTFE"; } acHatch.Associative = true; // Add the new object to Model space and the transaction acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl); acHatch.EvaluateHatch(true); // General information of the profile MText infoText = new MText(); infoText.SetDatabaseDefaults(); infoText.Location = new Point3d(axisPoint1X + (crossSection * 0.5), insertPointY, 0); // The right side of the drawing infoText.Width = 20; infoText.TextHeight = textHeight; infoText.Layer = "DEFPOINTS"; infoText.Contents = "AUTOGENERATED MALE RING\n" + intDia + "/" + extDia + "x" + height + "\n" + endlessText + splitText + "\nMaterial : " + matNylon + matPTFE; // Add the new object to Model space and the transaction btr.AppendEntity(infoText); trans.AddNewlyCreatedDBObject(infoText, true); // Commit the transaction if (isDataValidated == true) { trans.Commit(); // Complete message doc.Editor.WriteMessage("\nThe profile has been successfully created!\n"); } } // Exception handling catch (System.Exception ex) { doc.Editor.WriteMessage("Error encountered : " + ex.Message); trans.Abort(); } } } }
public static ObjectId AddDimLineAngular(Point3d line1StartPt, Point3d point3d_0, Point3d line2StartPt, Point3d point3d_1, Point3d arcPt, string text, ObjectId style) { LineAngularDimension2 ent = new LineAngularDimension2(line1StartPt, point3d_0, line2StartPt, point3d_1, arcPt, text, style); return(ModelSpace.AddEnt(ent)); }