public static void RemoveDimStyle(string dimStyleName) { Database database = Active.Database; try { DimStyleTable dimStyleTable = GetDimStyleTable(); using (Transaction transaction = database.TransactionManager.StartTransaction()) { foreach (ObjectId dimStyleTableRecordId in dimStyleTable) { DimStyleTableRecord dimStyleTableRecord = transaction.GetObject <DimStyleTableRecord>(dimStyleTableRecordId, OpenMode.ForRead); if (dimStyleTableRecord.Name == dimStyleName) { dimStyleTableRecord.UpgradeOpen(); dimStyleTableRecord.Erase(); } } transaction.Commit(); }//using } catch (Exception ex) { Active.WriteMessage(ex.Message); throw; } }
public void Union(Dictionary <string, ObjectId[]> dicDeleteDimStyles, DimStyleTableRecord[] resultStyleName) { using (Transaction t = targetDB.TransactionManager.StartTransaction()) { DimStyleTable tblStyle = (DimStyleTable)t.GetObject(targetDB.DimStyleTableId, OpenMode.ForWrite); foreach (var _style in dicDeleteDimStyles) { foreach (var _x in _style.Value) { DBObject item = t.GetObject(_x, OpenMode.ForWrite); Dimension y = (Dimension)item; if (y.Annotative != AnnotativeStates.True) { SetStyleAnnotative(resultStyleName, item, y); } SetStyleByType(resultStyleName, item, y); } if (!CanBeRemoved(_style.Key)) { continue; } List <DimStyleTableRecord> dimStyles = tblStyle.Cast <ObjectId>().Select(n => (DimStyleTableRecord)t.GetObject(n, OpenMode.ForWrite, true)).ToList(); DimStyleTableRecord styleDel = dimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals(_style.Key)).ToList()[0]; styleDel.Erase(); } t.Commit(); } }
public void CreatedimStyle() { string text = Interaction.InputBox("输入标注样式的名称、全局标注比例、测量标注比例,用/分开。", "田草CAD工具箱.Net版", "Dim100/100/1", -1, -1); string[] array = new string[3]; string s = text; string text2 = "/"; NF.Str2Arr(s, ref array, ref text2); if (Operators.CompareString(array[0], "", false) != 0) { string text3 = array[0]; int int_ = Conversions.ToInteger(array[1]); double double_ = Conversions.ToDouble(array[2]); Database workingDatabase = HostApplicationServices.WorkingDatabase; Editor editor = Application.DocumentManager.MdiActiveDocument.Editor; using (Transaction transaction = workingDatabase.TransactionManager.StartTransaction()) { DimStyleTable dimStyleTable = (DimStyleTable)transaction.GetObject(workingDatabase.DimStyleTableId, 1); ObjectId objectId = Class36.smethod_78(text3, int_, double_, false); if (objectId != ObjectId.Null) { DimStyleTableRecord dimStyleTableRecord = (DimStyleTableRecord)transaction.GetObject(objectId, 1); } else { editor.WriteMessage("\r标注样式 " + text3 + " 已存在!"); } transaction.Commit(); } } }
public static DimStyleTableRecord GetDimStyle(string styleName) { Document document = Active.Document; Database database = document.Database; using (Transaction transaction = database.TransactionManager.StartTransaction()) { try { DimStyleTable dimStyleTable = GetDimStyleTable(); foreach (ObjectId dimStyleTableRecordId in dimStyleTable) { DimStyleTableRecord dimStyleTableRecord = transaction.GetObject <DimStyleTableRecord>(dimStyleTableRecordId, OpenMode.ForRead); if (dimStyleTableRecord.Name == styleName) { return(dimStyleTableRecord); } } } catch (Exception ex) { Active.WriteMessage(ex.Message); throw; } }// using return(null); }
addLdr(Point3dCollection pnt3ds, ObjectId idLayer, double sizeArrow, double sizeGap, Color color, ObjectId idMTxt, string nameStyle = "Annotative", bool spline = false) { ObjectId idLdr = ObjectId.Null; Leader ldr = new Leader(); try { using (Transaction tr = BaseObjs.startTransactionDb()) { BlockTable BT = Blocks.getBlockTable(); BlockTableRecord MS = (BlockTableRecord)tr.GetObject(BT[BlockTableRecord.ModelSpace], OpenMode.ForWrite); ObjectId idDimStyle = Dim.getDimStyleTableRecord("Annotative"); DimStyleTableRecord dstr = (DimStyleTableRecord)tr.GetObject(idDimStyle, OpenMode.ForRead); ldr.SetDatabaseDefaults(); ldr.HasArrowHead = true; ldr.DimensionStyle = idDimStyle; ldr.SetDimstyleData(dstr); ldr.LayerId = idLayer; ldr.Dimasz = sizeArrow; ldr.Dimgap = sizeGap; ldr.IsSplined = spline; ldr.Color = color; ldr.Annotative = AnnotativeStates.True; for (int i = 0; i < pnt3ds.Count; i++) { try { ldr.AppendVertex(pnt3ds[i]); } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Ldr.cs: line: 60"); } } idLdr = MS.AppendEntity(ldr); tr.AddNewlyCreatedDBObject(ldr, true); if (!idMTxt.IsNull) { ldr.Annotative = AnnotativeStates.True; ldr.Annotation = idMTxt; ldr.Dimtad = 0; ldr.EvaluateLeader(); } tr.Commit(); }// end using } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Ldr.cs: line: 79"); } return(idLdr); }
getDimStyleTableRecord(string name) { ObjectId id = ObjectId.Null; try { using (Transaction tr = BaseObjs.startTransactionDb()) { DimStyleTable dst = (DimStyleTable)HostApplicationServices.WorkingDatabase.DimStyleTableId.GetObject(OpenMode.ForRead); if (dst.Has(name) == true) { //dst.UpgradeOpen(); DimStyleTableRecord dstr = (DimStyleTableRecord)dst[name].GetObject(OpenMode.ForRead); id = dstr.ObjectId; } else { dst.UpgradeOpen(); DimStyleTableRecord dstr = new DimStyleTableRecord(); dstr.Name = name; dstr.Annotative = AnnotativeStates.True; id = dst.Add(dstr); tr.AddNewlyCreatedDBObject(dstr, true); } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " Dim.cs: line: 162"); } return(id); }
public void Union(Dictionary<string, ObjectId[]> dicDeleteDimStyles, DimStyleTableRecord[] resultStyleName) { using (Transaction t = targetDB.TransactionManager.StartTransaction()) { DimStyleTable tblStyle = (DimStyleTable)t.GetObject(targetDB.DimStyleTableId, OpenMode.ForWrite); foreach (var _style in dicDeleteDimStyles) { foreach (var _x in _style.Value) { DBObject item = t.GetObject(_x, OpenMode.ForWrite); Dimension y = (Dimension)item; if (y.Annotative != AnnotativeStates.True) SetStyleAnnotative(resultStyleName, item, y); SetStyleByType(resultStyleName, item, y); } if (!CanBeRemoved(_style.Key)) continue; List<DimStyleTableRecord> dimStyles = tblStyle.Cast<ObjectId>().Select(n => (DimStyleTableRecord)t.GetObject(n, OpenMode.ForWrite, true)).ToList(); DimStyleTableRecord styleDel = dimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals(_style.Key)).ToList()[0]; styleDel.Erase(); } t.Commit(); } }
public void TestAddDimStyle() { var newId = ObjectId.Null; using (var db = AcadDatabase.Active()) { var newDimStyle = new DimStyleTableRecord() { Name = "NewDimStyle" }; db.DimStyles.Add(newDimStyle); newId = newDimStyle.ObjectId; } AcadAssert.That.DimStyleTable.Contains(newId); }
public StringCollection GetDimensionStylesList() { StringCollection dimStylesCollection = new StringCollection(); using (Transaction transaction = _db.TransactionManager.StartTransaction()) { DimStyleTable dimStyleTable = (DimStyleTable)transaction.GetObject(_db.DimStyleTableId, OpenMode.ForRead); foreach (ObjectId dimStyleTableRecordId in dimStyleTable) { DimStyleTableRecord dimStyleTableRecord = (DimStyleTableRecord)transaction.GetObject(dimStyleTableRecordId, OpenMode.ForRead); dimStylesCollection.Add(dimStyleTableRecord.Name); } transaction.Commit(); } return(dimStylesCollection); }
public static bool CheckDimStyleExists(string DimStyleName) { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; using (Transaction tr = doc.TransactionManager.StartTransaction()) { DimStyleTableRecord dstr = new DimStyleTableRecord(); DimStyleTable dst = (DimStyleTable)tr.GetObject(db.DimStyleTableId, OpenMode.ForRead, true); if (dst.Has(DimStyleName)) { return(true); } return(false); } }
//public static ObjectId AddDimStyle(this Database db,string styleName) //{ // DimStyleTable dst = (DimStyleTable)db.DimStyleTableId.GetObject(OpenMode.ForRead); // if (!dst.Has(styleName)) // { // DimStyleTableRecord dstr = new DimStyleTableRecord(); // dstr.Name = styleName; // dstr.Dimscale = 12; // dst.UpgradeOpen(); // dst.Add(dstr); // db.TransactionManager.AddNewlyCreatedDBObject(dstr, true); // dst.DowngradeOpen(); // } // return dst[styleName]; //} public static void AddDimStyle(this Database db, string styleName) { DimStyleTable dst = (DimStyleTable)db.DimStyleTableId.GetObject(OpenMode.ForRead); if (!dst.Has(styleName)) { DimStyleTableRecord dstr = new DimStyleTableRecord { Name = styleName, Dimscale = 12 }; dst.UpgradeOpen(); dst.Add(dstr); db.TransactionManager.AddNewlyCreatedDBObject(dstr, true); dst.DowngradeOpen(); } }
public static void SetCurrentDimStyle(string DimStyleName) { // Establish connections to the document and it's database Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; // Establish a transaction using (Transaction tr = doc.TransactionManager.StartTransaction()) { DimStyleTable dst = (DimStyleTable)tr.GetObject(db.DimStyleTableId, OpenMode.ForRead); ObjectId dimId = ObjectId.Null; string message = string.Empty; if (!dst.Has(DimStyleName)) { CreateModifyDimStyle(DimStyleName, out message); dimId = dst[DimStyleName]; } else { dimId = dst[DimStyleName]; } DimStyleTableRecord dstr = (DimStyleTableRecord)tr.GetObject(dimId, OpenMode.ForRead); /* NOTE: * If this code is used, and the updated style is current, * an override is created for that style. * This is not what I wanted. */ //if (dstr.ObjectId != db.Dimstyle) //{ // db.Dimstyle = dstr.ObjectId; // db.SetDimstyleData(dstr); //} /* Simply by running these two lines all the time, any overrides to updated dimstyles get * cleared away as happens when you select the parent dimstyle in AutoCAD. */ db.Dimstyle = dstr.ObjectId; db.SetDimstyleData(dstr); tr.Commit(); } }
/// <summary> /// 创建一个新的标注样式 /// </summary> /// <param name="db">数据库对象</param> /// <param name="styleName">标注样式名</param> /// <returns>返回新建的标注样式的Id</returns> public static ObjectId AddDimStyle(this Database db, string styleName) { //打开标注样式表 DimStyleTable dst = (DimStyleTable)db.DimStyleTableId.GetObject(OpenMode.ForRead); if (!dst.Has(styleName))//如果不存在名为styleName的标注样式,则新建一个标注样式 { //定义一个新的标注样式表记录 DimStyleTableRecord dstr = new DimStyleTableRecord(); dstr.Name = styleName; //设置标注样式名 dst.UpgradeOpen(); //切换标注样式表的状态为写以添加新的标注样式 dst.Add(dstr); //将标注样式表记录的信息添加到标注样式表中 //把标注式表记录添加到事务处理中 db.TransactionManager.AddNewlyCreatedDBObject(dstr, true); dst.DowngradeOpen(); //为了安全,将标注样式表的状态切换为读 } return(dst[styleName]); //返回新添加的标注样式表记录的ObjectId }
public static void ImportBlocksFromDwg(this Database destDb, string sourceFileName) { //创建一个新的数据库对象,作为源数据库,以读入外部文件中的对象 Database sourceDb = new Database(false, true); try { //把DWG文件读入到一个临时的数据库中 sourceDb.ReadDwgFile(sourceFileName, System.IO.FileShare.Read, true, null); //创建一个变量用来存储块的ObjectId列表 ObjectIdCollection blockIds = new ObjectIdCollection(); //获取源数据库的事务处理管理器 ZwSoft.ZwCAD.DatabaseServices.TransactionManager tm = sourceDb.TransactionManager; //在源数据库中开始事务处理 using (Transaction myT = tm.StartTransaction()) { //打开源数据库中的块表 DimStyleTable bt = (DimStyleTable)tm.GetObject(sourceDb.DimStyleTableId, OpenMode.ForRead, false); //遍历每个块 foreach (ObjectId btrId in bt) { DimStyleTableRecord btr = (DimStyleTableRecord)tm.GetObject(btrId, OpenMode.ForRead, false); //只加入命名块和非布局块到复制列表中 //if (!btr.IsAnonymous && !btr.IsLayout) { blockIds.Add(btrId); } btr.Dispose(); } bt.Dispose(); } //定义一个IdMapping对象 IdMapping mapping = new IdMapping(); //从源数据库向目标数据库复制块表记录 sourceDb.Wblock(destDb, blockIds, Point3d.Origin, DuplicateRecordCloning.Ignore); //操作完成,销毁源数据库 sourceDb.Dispose(); } catch (ZwSoft.ZwCAD.Runtime.Exception ex) { Application.ShowAlertDialog("复制错误: " + ex.Message); } }
public void TransferDimStyles() { LayerManager lm = new LayerManager(); Database dbStandart = new Database(false, true); dbStandart.ReadDwgFile(lm.PathToStadartFile, FileShare.Read, true, ""); List<DimStyleTableRecord> standartDimStyless = GetDimStyles(dbStandart); ObjectIdCollection col = GetStandartDimStyles(standartDimStyless, true); CopyEtalonStyle(col); List<DimStyleTableRecord> docDimStyles = GetDimStyles(targetDB); DimStyleTableRecord pikStyleActive = docDimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals("PIK")).ToList()[0]; DimStyleTableRecord pikStyleDiametricDimension = docDimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals("PIK$2")).ToList()[0]; DimStyleTableRecord pikStyleRadialDimension = docDimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals("PIK$3")).ToList()[0]; DimStyleTableRecord pikStyleLineAngularDimension = docDimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals("PIK$4")).ToList()[0]; DimStyleTableRecord[] masDimStyles = new DimStyleTableRecord[] { pikStyleActive, pikStyleDiametricDimension, pikStyleRadialDimension, pikStyleLineAngularDimension }; targetDB.Dimstyle = pikStyleActive.ObjectId; Dictionary<string, ObjectId[]> dicDeleteDimStyles = GetDependentPrimitives(docDimStyles.Select(x => x.Name).ToArray()); Union(dicDeleteDimStyles, masDimStyles); }
public static ObjectId AddDimStyle(this Database db, string styleName, double dimasz, double dimexe, int dimtad, double dimtxt) { DimStyleTable dst = (DimStyleTable)db.DimStyleTableId.GetObject(OpenMode.ForRead); if (!dst.Has(styleName)) { DimStyleTableRecord dstr = new DimStyleTableRecord { Name = styleName, Dimasz = dimasz, Dimexe = dimexe, Dimtad = dimtad, Dimtxt = dimtxt }; dst.UpgradeOpen(); dst.Add(dstr); db.TransactionManager.AddNewlyCreatedDBObject(dstr, true); dst.DowngradeOpen(); } return(dst[styleName]); }
public void NewDimStyle() { Database db = Application.DocumentManager.MdiActiveDocument.Database; using (Transaction trans = db.TransactionManager.StartTransaction()) { DimStyleTable DimTabb = (DimStyleTable)trans.GetObject(db.DimStyleTableId, OpenMode.ForRead); ObjectId dimId = ObjectId.Null; if (!DimTabb.Has("Test")) { DimTabb.UpgradeOpen(); DimStyleTableRecord newRecord = new DimStyleTableRecord(); newRecord.Name = "Test"; dimId = DimTabb.Add(newRecord); trans.AddNewlyCreatedDBObject(newRecord, true); } else { dimId = DimTabb["Test"]; } DimStyleTableRecord DimTabbRecaord = (DimStyleTableRecord)trans.GetObject(dimId, OpenMode.ForRead); if (DimTabbRecaord.ObjectId != db.Dimstyle) { db.Dimstyle = DimTabbRecaord.ObjectId; db.SetDimstyleData(DimTabbRecaord); } trans.Commit(); } }
public void CreatedimStyle() { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; using (Transaction trans = db.TransactionManager.StartTransaction()) { DimStyleTable dt = (DimStyleTable)trans.GetObject(db.DimStyleTableId, OpenMode.ForWrite); String dimName = "abc"; ObjectId dimId = ISO25(dimName); if (dimId != ObjectId.Null) { DimStyleTableRecord dtr = (DimStyleTableRecord)trans.GetObject(dimId, OpenMode.ForWrite); // 修改箭头大小. dtr.Dimasz = 3; } else { ed.WriteMessage("\n标注样式 " + dimName + " 已存在!"); } trans.Commit(); } }
public void TransferDimStyles() { LayerManager lm = new LayerManager(); Database dbStandart = new Database(false, true); dbStandart.ReadDwgFile(lm.PathToStadartFile, FileShare.Read, true, ""); List <DimStyleTableRecord> standartDimStyless = GetDimStyles(dbStandart); ObjectIdCollection col = GetStandartDimStyles(standartDimStyless, true); CopyEtalonStyle(col); List <DimStyleTableRecord> docDimStyles = GetDimStyles(targetDB); DimStyleTableRecord pikStyleActive = docDimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals("PIK")).ToList()[0]; DimStyleTableRecord pikStyleDiametricDimension = docDimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals("PIK$2")).ToList()[0]; DimStyleTableRecord pikStyleRadialDimension = docDimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals("PIK$3")).ToList()[0]; DimStyleTableRecord pikStyleLineAngularDimension = docDimStyles.Select(x => x).Where(x => x.Name.ToUpper().Equals("PIK$4")).ToList()[0]; DimStyleTableRecord[] masDimStyles = new DimStyleTableRecord[] { pikStyleActive, pikStyleDiametricDimension, pikStyleRadialDimension, pikStyleLineAngularDimension }; targetDB.Dimstyle = pikStyleActive.ObjectId; Dictionary <string, ObjectId[]> dicDeleteDimStyles = GetDependentPrimitives(docDimStyles.Select(x => x.Name).ToArray()); Union(dicDeleteDimStyles, masDimStyles); }
public void AddDimStyleFromDWG() { Document mdiActiveDocument = Application.DocumentManager.MdiActiveDocument; Database database = mdiActiveDocument.Database; try { using (Transaction transaction = database.TransactionManager.StartTransaction()) { DimStyleTable dimStyleTable = (DimStyleTable)transaction.GetObject(database.DimStyleTableId, 1); if (!dimStyleTable.Has("DIM100")) { string text = Class33.Class31_0.Info.DirectoryPath + "\\support\\DimStyle.Dwg"; Database database2 = new Database(false, true); database2.ReadDwgFile(text, FileShare.Read, true, ""); DimStyleTableRecord dimStyleTableRecord; using (Transaction transaction2 = database2.TransactionManager.StartTransaction()) { DimStyleTable dimStyleTable2 = (DimStyleTable)transaction2.GetObject(database2.DimStyleTableId, 0); dimStyleTableRecord = (DimStyleTableRecord)transaction2.GetObject(dimStyleTable2["DIM100"], 0); transaction2.Dispose(); } mdiActiveDocument.Editor.WriteMessage("\n" + dimStyleTableRecord.Name); DimStyleTableRecord dimStyleTableRecord2 = new DimStyleTableRecord(); dimStyleTableRecord2 = (DimStyleTableRecord)dimStyleTableRecord.Clone(); dimStyleTable.Add(dimStyleTableRecord2); transaction.AddNewlyCreatedDBObject(dimStyleTableRecord2, true); mdiActiveDocument.Editor.WriteMessage("\n标注样式:DIM100添加成功"); } transaction.Commit(); } } catch (Exception ex) { mdiActiveDocument.Editor.WriteMessage("\n标注样式加载出错: " + ex.Message); } }
public static ObjectId AddDimStyle(Database db, string DimName)//添加标注样式 { DimStyleTable table = (DimStyleTable)db.DimStyleTableId.GetObject(OpenMode.ForRead); if (!table.Has(DimName)) { DimStyleTableRecord record = new DimStyleTableRecord(); record.Name = DimName; record.Dimasz = 0.5; record.Dimtxt = 0.5; record.Dimtad = 1; record.Dimdec = 3; record.Dimtad = 1; //文字 record.Dimtih = false; record.Dimtoh = false; record.Dimtxtdirection = false; table.UpgradeOpen(); table.Add(record); db.TransactionManager.AddNewlyCreatedDBObject(record, true); table.DowngradeOpen(); } return(table[DimName]); }
public ObjectId ISO25(String dimStyleName) { Database db = HostApplicationServices.WorkingDatabase; ObjectId dimstyleId; try { using (Transaction trans = db.TransactionManager.StartTransaction()) { DimStyleTable dt = (DimStyleTable)trans.GetObject(db.DimStyleTableId, OpenMode.ForWrite); // 新建一个标注样式表记录. DimStyleTableRecord dtr = new DimStyleTableRecord(); // 换算精度 dtr.Dimaltd = 3; // 换算比例因子 dtr.Dimaltf = 0.03937008; // 换算公差精度 dtr.Dimalttd = 3; // 箭头大小 dtr.Dimasz = 2.5; // 圆心标记大小 dtr.Dimcen = 2.5; // 精度 dtr.Dimdec = 2; // 尺寸线间距 dtr.Dimdli = 3.75; // 小数分隔符 dtr.Dimdsep = ','; //尺寸界线超出量 dtr.Dimexe = 1.25; // 尺寸界线偏移 dtr.Dimexo = 0.625; // 文字偏移 dtr.Dimgap = 0.625; // 文字位置垂直 dtr.Dimtad = 1; // 公差精度 dtr.Dimtdec = 2; // 文字在内对齐 dtr.Dimtih = false; // 尺寸线强制 dtr.Dimtofl = true; // 文字外部对齐 dtr.Dimtoh = false; // 公差位置垂直 dtr.Dimtolj = 0; // 文字高度 dtr.Dimtxt = 2.5; // 公差消零 dtr.Dimtzin = 8; // 消零 dtr.Dimzin = 8; //设置标注样式名称. dtr.Name = dimStyleName; dimstyleId = dt.Add(dtr); trans.AddNewlyCreatedDBObject(dtr, true); trans.Commit(); } return(dimstyleId); } catch { ObjectId NullId = ObjectId.Null; return(NullId); } }
private void SetStyleAnnotative(DimStyleTableRecord[] resultStyleName, DBObject item, Dimension y) { AnnotationScale mainScale = new AnnotationScale(); ObjectContextManager ocm = targetDB.ObjectContextManager; double scale = 2.5 / (y.Dimscale * y.Dimtxt); double difference = 200; if (ocm != null) { ObjectContextCollection occ = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES"); ObjectContext currentContext = occ.CurrentContext; foreach (ObjectContext context in occ) { double currentDifference = 200; AnnotationScale annotScale = (AnnotationScale)context; if (annotScale.Scale == scale) { mainScale = annotScale; break; } else { currentDifference = Math.Abs(scale - annotScale.Scale); if (currentDifference < difference) { difference = currentDifference; mainScale = annotScale; } } } SetStyleByType(resultStyleName, item, y); if (y.HasContext(currentContext)) y.RemoveContext(currentContext); y.AddContext(mainScale); y.Dimtxt = 2.5; } }
private static void SetStyleByType(DimStyleTableRecord[] resultStyleName, DBObject item, Dimension y) { if (item is LineAngularDimension2) { Dimension y2 = (LineAngularDimension2)item; y2.DimensionStyleName = resultStyleName[1].Name; } else if (item is DiametricDimension) { Dimension y2 = (DiametricDimension)item; y2.DimensionStyleName = resultStyleName[2].Name; } else if (item is RadialDimension) { Dimension y2 = (RadialDimension)item; y2.DimensionStyleName = resultStyleName[3].Name; } else y.DimensionStyleName = resultStyleName[0].Name; }
public static ObjectId Create_HDC_DimensionStyle(string StyleName) { var DimId = ObjectId.Null; using (Transaction T = AC.DB.TransactionManager.StartTransaction()) { DimStyleTable DST = T.GetObject(AC.DB.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable; switch (StyleName) { case "HDC_Dim_Style": #region 생성 if (!DST.Has(StyleName)) { DST.UpgradeOpen(); var dstr = new DimStyleTableRecord() { Name = StyleName, // 스타일 이름 Dimasz = 0, // 화살표 크기 Dimtxt = 100, // 문자 크기 Dimexo = 100, // 원점에서 간격띄우기 값 Dimclrt = ColorIndex.Yellow, // 문자 색상 Dimclrd = ColorIndex.Yellow, // 치수선 생상 Dimclre = ColorIndex.Gray, // 치수보조선 색생 Dimtad = 0, // 1: 치수선 위에 입력, 0: 치수선 상에 입력 Dimtoh = false, // 문자 정렬(On/On: 수평, Off/Off: 치수선, On/Off: ISO) Dimtih = false, // 문자 정렬(On/On: 수평, Off/Off: 치수선, On/Off: ISO) Dimdec = 0, // 소수점 자릿수 Dimsd1 = true, // 치수선1 억제 Dimsd2 = true, // 치수선2 억제 Dimse1 = true, // 치수보조선1 억제 Dimse2 = true, // 치수보조선1 억제 Dimtix = true, }; DimId = DST.Add(dstr); T.AddNewlyCreatedDBObject(dstr, true); } #endregion #region 수정 else { DimId = DST[StyleName]; var dstr = T.GetObject(DimId, OpenMode.ForWrite) as DimStyleTableRecord; dstr.Name = StyleName; dstr.Dimasz = 0; dstr.Dimtxt = 100; dstr.Dimexo = 100; dstr.Dimgap = 50; dstr.Dimclrt = ColorIndex.Yellow; dstr.Dimclrd = ColorIndex.Yellow; dstr.Dimclre = ColorIndex.Gray; dstr.Dimtad = 0; dstr.Dimtoh = false; dstr.Dimtih = false; dstr.Dimdec = 0; dstr.Dimsd1 = true; // 치수선1 억제 dstr.Dimsd2 = true; // 치수선2 억제 dstr.Dimse1 = true; // 치수보조선1 억제 dstr.Dimse2 = true; // 치수보조선1 억제 dstr.Dimtix = true; } #endregion T.Commit(); break; case "HDC_도면 치수선": #region 생성 if (!DST.Has(StyleName)) { DST.UpgradeOpen(); var dstr = new DimStyleTableRecord(); dstr.Name = StyleName; // 스타일 이름 dstr.Dimasz = 10; // 화살표 크기 dstr.Dimblk = GetArrowObjectId("DIMBLK", "_ARCHTICK"); dstr.Dimblk1 = GetArrowObjectId("DIMBLK1", "_ARCHTICK"); // 화살표 모양 (_ARCHTICK : 건축 눈금) dstr.Dimblk2 = GetArrowObjectId("DIMBLK2", "_ARCHTICK"); // 화살표 모양 (_ARCHTICK : 건축 눈금) dstr.Dimtxt = 100; // 문자 크기 dstr.Dimexo = 150; // 원점에서 간격띄우기 값 dstr.Dimclrt = ColorIndex.Green; // 문자 색상 dstr.Dimclrd = ColorIndex.RGB(255, 63, 0); // 치수선 생상 dstr.Dimclre = ColorIndex.RGB(255, 63, 0); // 치수보조선 색생 dstr.Dimtad = 1; // 1: 치수선 위에 입력, 0: 치수선 상에 입력 dstr.Dimtoh = false; // 문자 정렬(On/On: 수평, Off/Off: 치수선, On/Off: ISO) dstr.Dimtih = false; // 문자 정렬(On/On: 수평, Off/Off: 치수선, On/Off: ISO) dstr.Dimdec = 0; // 소수점 자릿수 dstr.Dimsd1 = false; // 치수선1 억제 dstr.Dimsd2 = false; // 치수선2 억제 dstr.Dimse1 = false; // 치수보조선1 억제 dstr.Dimse2 = false; // 치수보조선1 억제 DimId = DST.Add(dstr); T.AddNewlyCreatedDBObject(dstr, true); } #endregion #region 수정 else { DimId = DST[StyleName]; var dstr = T.GetObject(DimId, OpenMode.ForWrite) as DimStyleTableRecord; dstr.Name = StyleName; dstr.Dimasz = 10; dstr.Dimblk = GetArrowObjectId("DIMBLK", "_ARCHTICK"); dstr.Dimblk1 = GetArrowObjectId("DIMBLK1", "_ARCHTICK"); dstr.Dimblk2 = GetArrowObjectId("DIMBLK2", "_ARCHTICK"); dstr.Dimtxt = 100; dstr.Dimexo = 150; dstr.Dimgap = 50; dstr.Dimclrt = ColorIndex.Green; dstr.Dimclrd = ColorIndex.RGB(255, 63, 0); dstr.Dimclre = ColorIndex.RGB(255, 63, 0); dstr.Dimtad = 1; dstr.Dimtoh = false; dstr.Dimtih = false; dstr.Dimdec = 0; dstr.Dimsd1 = false; // 치수선1 억제 dstr.Dimsd2 = false; // 치수선2 억제 dstr.Dimse1 = false; // 치수보조선1 억제 dstr.Dimse2 = false; // 치수보조선1 억제 //dstr.Dimfxlen = 700; //dstr.Dimtix = true; } #endregion T.Commit(); break; } } return(DimId); }
public static void CADini() { // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Editor ed = acDoc.Editor; // Start a transaction using (Transaction tr = acCurDb.TransactionManager.StartTransaction()) { Dictionary <string, short> ldic = new Dictionary <string, short>() { ["粗线"] = 4, ["细线"] = 2, ["标注"] = 7, ["中心线"] = 1, ["虚线"] = 3, ["填充"] = 8, ["图框"] = 8, ["地质"] = 8, }; List <string> Lname = new List <string>() { "CENTER", "DASHED" }; LayerTable acLyrTbl; acLyrTbl = tr.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable; LinetypeTable acLinTbl; acLinTbl = tr.GetObject(acCurDb.LinetypeTableId, OpenMode.ForRead) as LinetypeTable; foreach (string ltname in Lname) { if (!acLinTbl.Has(ltname)) { acCurDb.LoadLineTypeFile(ltname, "acad.lin"); } } LayerTableRecord acLyrTblRec = new LayerTableRecord(); foreach (string key in ldic.Keys) { short cid = ldic[key]; acLyrTblRec = new LayerTableRecord(); if (!acLyrTbl.Has(key)) { acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid); if (cid != 4) { acLyrTblRec.LineWeight = LineWeight.LineWeight013; } else { acLyrTblRec.LineWeight = LineWeight.LineWeight030; } if (cid == 1) { acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"]; } if (cid == 3) { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; } if (key == "图框") { acLyrTblRec.IsPlottable = false; } if (key == "地质") { acLyrTblRec.IsPlottable = false; } acLyrTblRec.Name = key; if (acLyrTbl.IsWriteEnabled == false) { acLyrTbl.UpgradeOpen(); } acLyrTbl.Add(acLyrTblRec); tr.AddNewlyCreatedDBObject(acLyrTblRec, true); } else { acLyrTblRec = tr.GetObject(acLyrTbl[key], OpenMode.ForWrite) as LayerTableRecord; acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid); if (cid != 4) { acLyrTblRec.LineWeight = LineWeight.LineWeight013; } else { acLyrTblRec.LineWeight = LineWeight.LineWeight030; } if (cid == 1) { acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"]; } if (cid == 3) { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; } if (key == "图框") { acLyrTblRec.IsPlottable = false; } if (key == "地质") { acLyrTblRec.IsPlottable = false; } } } if (!acLyrTbl.Has("sjx")) { acLyrTblRec = new LayerTableRecord(); acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 1); acLyrTblRec.Name = "sjx"; acLyrTblRec.LineWeight = LineWeight.LineWeight015; if (acLyrTbl.IsWriteEnabled == false) { acLyrTbl.UpgradeOpen(); } acLyrTbl.Add(acLyrTblRec); tr.AddNewlyCreatedDBObject(acLyrTblRec, true); } if (!acLyrTbl.Has("dmx")) { acLyrTblRec = new LayerTableRecord(); acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, 8); acLyrTblRec.Name = "dmx"; acLyrTblRec.LineWeight = LineWeight.LineWeight015; if (acLyrTbl.IsWriteEnabled == false) { acLyrTbl.UpgradeOpen(); } acLyrTbl.Add(acLyrTblRec); tr.AddNewlyCreatedDBObject(acLyrTblRec, true); } //------------------------------------------------------------------------------------------- TextStyleTable st = tr.GetObject(acCurDb.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable; if (!st.Has("EN")) { TextStyleTableRecord str = new TextStyleTableRecord() { Name = "En", FileName = "times.ttf", XScale = 0.85, }; st.Add(str); tr.AddNewlyCreatedDBObject(str, true); } else { TextStyleTableRecord str = tr.GetObject(st["En"], OpenMode.ForWrite) as TextStyleTableRecord; str.FileName = "times.ttf"; str.XScale = 0.85; } if (!st.Has("fsdb")) { TextStyleTableRecord str2 = new TextStyleTableRecord() { Name = "fsdb", FileName = "fsdb_e.shx", BigFontFileName = "fsdb.shx", XScale = 0.75, }; ObjectId textstyleid = st.Add(str2); tr.AddNewlyCreatedDBObject(str2, true); } else { TextStyleTableRecord str = tr.GetObject(st["fsdb"], OpenMode.ForWrite) as TextStyleTableRecord; str.FileName = "fsdb_e.shx"; str.BigFontFileName = "fsdb.shx"; str.XScale = 0.75; } if (!st.Has("仿宋")) { TextStyleTableRecord str2 = new TextStyleTableRecord() { Name = "仿宋", FileName = "仿宋_GB2312.ttf", XScale = 0.8, }; ObjectId textstyleid = st.Add(str2); tr.AddNewlyCreatedDBObject(str2, true); } else { TextStyleTableRecord str = tr.GetObject(st["仿宋"], OpenMode.ForWrite) as TextStyleTableRecord; str.FileName = "仿宋_GB2312.ttf"; str.XScale = 0.8; } if (!st.Has("钢筋")) { TextStyleTableRecord str2 = new TextStyleTableRecord() { Name = "钢筋", FileName = "FS-GB2312-Rebar.ttf", XScale = 0.8, }; ObjectId textstyleid = st.Add(str2); tr.AddNewlyCreatedDBObject(str2, true); } else { TextStyleTableRecord str = tr.GetObject(st["钢筋"], OpenMode.ForWrite) as TextStyleTableRecord; str.FileName = "FS-GB2312-Rebar.ttf"; str.XScale = 0.8; } //------------------------------------------------------------------------------------------- DimStyleTable dst = (DimStyleTable)tr.GetObject(acCurDb.DimStyleTableId, OpenMode.ForWrite); foreach (int thescale in new int[] { 50, 75, 100, 125, 150, 200 }) { string scname = "1-" + thescale.ToString(); DimStyleTableRecord dstr = new DimStyleTableRecord(); if (!dst.Has(scname)) { dstr.Name = "1-" + thescale.ToString(); dstr.Dimscale = thescale; dstr.Dimtxsty = st["仿宋"]; dstr.Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, 6); dstr.Dimclre = Color.FromColorIndex(ColorMethod.ByAci, 6); dstr.Dimdli = 5.0; dstr.Dimexe = 1.0; dstr.Dimexo = 1.0; dstr.DimfxlenOn = true; dstr.Dimfxlen = 4; dstr.Dimtxt = 2.5; dstr.Dimasz = 1.5; dstr.Dimtix = true; dstr.Dimtmove = 1; dstr.Dimtad = 1; dstr.Dimgap = 0.8; dstr.Dimdec = 0; dstr.Dimtih = false; dstr.Dimtoh = false; dstr.Dimdsep = '.'; //dstr.Dimlfac = 0.1; dst.Add(dstr); tr.AddNewlyCreatedDBObject(dstr, true); } else { dstr = tr.GetObject(dst[scname], OpenMode.ForWrite) as DimStyleTableRecord; dstr.Name = "1-" + thescale.ToString(); dstr.Dimscale = thescale; dstr.Dimtxsty = st["fsdb"]; dstr.Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, 6); dstr.Dimclre = Color.FromColorIndex(ColorMethod.ByAci, 6); dstr.Dimdli = 5.0; dstr.Dimexe = 1.0; dstr.Dimexo = 1.0; dstr.DimfxlenOn = true; dstr.Dimfxlen = 4; dstr.Dimtxt = 2.5; dstr.Dimasz = 1.5; dstr.Dimtix = true; dstr.Dimtmove = 1; dstr.Dimtad = 1; dstr.Dimgap = 0.8; dstr.Dimdec = 0; dstr.Dimtih = false; dstr.Dimtoh = false; dstr.Dimdsep = '.'; dstr.Dimlfac = 0.1; } } //------------------------------------------------------------------------------------------- // 自定义块 //------------------------------------------------------------------------------------------- BlockTable bt = (BlockTable)tr.GetObject(acCurDb.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = new BlockTableRecord(); //------------------------------------------------------------------------------------------- if (!bt.Has("BG")) { btr.Name = "BG"; bt.UpgradeOpen(); bt.Add(btr); tr.AddNewlyCreatedDBObject(btr, true); Polyline Paa = new Polyline() { //Color = Color.FromColorIndex(ColorMethod.ByAci, 9), //Layer = "标注", }; Paa.AddVertexAt(0, new Point2d(0, 0), 0, 0, 200); Paa.AddVertexAt(1, new Point2d(0, 200), 0, 0, 0); btr.AppendEntity(Paa); tr.AddNewlyCreatedDBObject(Paa, true); AttributeDefinition curbg = new AttributeDefinition(); curbg.Position = new Point3d(120, 200, 0); curbg.Height = 250; curbg.WidthFactor = 0.75; curbg.Tag = "标高"; //curbg.Layer = "标注"; curbg.TextStyleId = st["fsdb"]; btr.AppendEntity(curbg); tr.AddNewlyCreatedDBObject(curbg, true); } //------------------------------------------------------------------------------------------- if (!bt.Has("ZP")) { BlockTableRecord btr2 = new BlockTableRecord(); btr2.Name = "ZP"; bt.UpgradeOpen(); bt.Add(btr2); tr.AddNewlyCreatedDBObject(btr2, true); Polyline Paa2 = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 9), }; Paa2.AddVertexAt(0, new Point2d(0 - 350, 0), 0, 0, 80); Paa2.AddVertexAt(1, new Point2d(200 - 350, 0), 0, 0, 0); Paa2.AddVertexAt(2, new Point2d(900 - 350, 0), 0, 0, 0); btr2.AppendEntity(Paa2); tr.AddNewlyCreatedDBObject(Paa2, true); AttributeDefinition curzp = new AttributeDefinition(); curzp.Position = new Point3d(220 - 350, 0, 0); curzp.Height = 250; curzp.WidthFactor = 0.75; curzp.Tag = "左坡"; curzp.TextStyleId = st["fsdb"]; btr2.AppendEntity(curzp); tr.AddNewlyCreatedDBObject(curzp, true); } //------------------------------------------------------------------------------------------- if (!bt.Has("YP")) { BlockTableRecord btr3 = new BlockTableRecord(); btr3.Name = "YP"; bt.UpgradeOpen(); bt.Add(btr3); tr.AddNewlyCreatedDBObject(btr3, true); Polyline Paa3 = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 9), }; Paa3.AddVertexAt(0, new Point2d(0 + 350, 0), 0, 0, 80); Paa3.AddVertexAt(1, new Point2d(-200 + 350, 0), 0, 0, 0); Paa3.AddVertexAt(2, new Point2d(-900 + 350, 0), 0, 0, 0); btr3.AppendEntity(Paa3); tr.AddNewlyCreatedDBObject(Paa3, true); AttributeDefinition curyp = new AttributeDefinition(); curyp.Position = new Point3d(-220 + 350, 0, 0); curyp.HorizontalMode = TextHorizontalMode.TextRight; curyp.AlignmentPoint = curyp.Position; curyp.Height = 250; curyp.WidthFactor = 0.75; curyp.Tag = "右坡"; curyp.TextStyleId = st["fsdb"]; btr3.AppendEntity(curyp); tr.AddNewlyCreatedDBObject(curyp, true); } //------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------- tr.Commit(); } }
public static void CreateModifyDimStyle(string DimStyleName, out string message) { // Initialise the message value that gets returned by an exception (or not!) message = string.Empty; try { using (Transaction tr = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()) { Database db = Application.DocumentManager.MdiActiveDocument.Database; DimStyleTable dst = (DimStyleTable)tr.GetObject(db.DimStyleTableId, OpenMode.ForWrite, true); // Initialise a DimStyleTableRecord DimStyleTableRecord dstr = null; // If the required dimension style exists if (dst.Has(DimStyleName)) { // get the dimension style table record open for writing dstr = (DimStyleTableRecord)tr.GetObject(dst[DimStyleName], OpenMode.ForWrite); } else { // Initialise as a new dimension style table record dstr = new DimStyleTableRecord(); } // Set all the available dimension style properties // Most/all of these match the variables in AutoCAD. dstr.Name = DimStyleName; dstr.Annotative = AnnotativeStates.True; dstr.Dimadec = 2; dstr.Dimalt = false; dstr.Dimaltd = 2; dstr.Dimaltf = 25.4; dstr.Dimaltrnd = 0; dstr.Dimalttd = 2; dstr.Dimalttz = 0; dstr.Dimaltu = 2; dstr.Dimaltz = 0; dstr.Dimapost = ""; dstr.Dimarcsym = 0; dstr.Dimasz = 3.5; dstr.Dimatfit = 3; dstr.Dimaunit = 0; dstr.Dimazin = 2; dstr.Dimblk = ObjectId.Null; dstr.Dimblk1 = ObjectId.Null; dstr.Dimblk2 = ObjectId.Null; dstr.Dimcen = 0.09; dstr.Dimclrd = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 7); dstr.Dimclre = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 7);; dstr.Dimclrt = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 2);; dstr.Dimdec = 2; dstr.Dimdle = 0; dstr.Dimdli = 7; dstr.Dimdsep = Convert.ToChar("."); dstr.Dimexe = 1; dstr.Dimexo = 2; dstr.Dimfrac = 0; dstr.Dimfxlen = 0.18; dstr.DimfxlenOn = false; dstr.Dimgap = 1; dstr.Dimjogang = 0; dstr.Dimjust = 0; dstr.Dimldrblk = ObjectId.Null; dstr.Dimlfac = 1; dstr.Dimlim = false; ObjectId ltId = GetLinestyleID("Continuous"); dstr.Dimltex1 = ltId; dstr.Dimltex2 = ltId; dstr.Dimltype = ltId; dstr.Dimlunit = 2; dstr.Dimlwd = LineWeight.LineWeight015; dstr.Dimlwe = LineWeight.LineWeight015; dstr.Dimpost = ""; dstr.Dimrnd = 0; dstr.Dimsah = false; dstr.Dimscale = 1; dstr.Dimsd1 = false; dstr.Dimsd2 = false; dstr.Dimse1 = false; dstr.Dimse2 = false; dstr.Dimsoxd = false; dstr.Dimtad = 2; dstr.Dimtdec = 2; dstr.Dimtfac = 1; dstr.Dimtfill = 0; dstr.Dimtfillclr = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 0); dstr.Dimtih = false; dstr.Dimtix = false; dstr.Dimtm = 0; dstr.Dimtmove = 0; dstr.Dimtofl = false; dstr.Dimtoh = false; dstr.Dimtol = false; dstr.Dimtolj = 1; dstr.Dimtp = 0; dstr.Dimtsz = 0; dstr.Dimtvp = 0; // Test for the text style to be used ObjectId tsId = ObjectId.Null; // If it doesn't exist if (!CheckTextStyle("BF-标注文字")) { // Create the required text style CreateTextStyle("BF-标注文字", "simplex.shx", 0, out string massage); tsId = GetTextStyleId("BF-标注文字"); } else { // Get the ObjectId of the text style tsId = GetTextStyleId("BF-标注文字"); } dstr.Dimtxsty = tsId; dstr.Dimtxt = 2.5; dstr.Dimtxtdirection = false; dstr.Dimtzin = 0; dstr.Dimupt = false; dstr.Dimzin = 0; // If the dimension style doesn't exist if (!dst.Has(DimStyleName)) { // Add it to the dimension style table and collect its Id Object dsId = dst.Add(dstr); // Add the new dimension style table record to the document tr.AddNewlyCreatedDBObject(dstr, true); } // Commit the changes. tr.Commit(); } } catch (Autodesk.AutoCAD.Runtime.Exception e) { message = e.Message.ToString(); } }
Stream(ArrayList data, DimStyleTableRecord rec) { data.Add(new Snoop.Data.ClassSeparator(typeof(DimStyleTableRecord))); data.Add(new Snoop.Data.ObjectId("First arrow", rec.GetArrowId(DimArrowFlag.FirstArrow))); data.Add(new Snoop.Data.ObjectId("Second arrow", rec.GetArrowId(DimArrowFlag.SecondArrow))); data.Add(new Snoop.Data.Bool("Is modified for recompute", rec.IsModifiedForRecompute)); data.Add(new Snoop.Data.CategorySeparator("DIMVARS")); // dimvars data.Add(new Snoop.Data.Int("Dimadec", rec.Dimadec)); data.Add(new Snoop.Data.Bool("Dimalt", rec.Dimalt)); data.Add(new Snoop.Data.Int("Dimaltd", rec.Dimaltd)); data.Add(new Snoop.Data.Distance("Dimaltf", rec.Dimaltf)); data.Add(new Snoop.Data.Distance("Dimaltrnd", rec.Dimaltrnd)); data.Add(new Snoop.Data.Int("Dimalttd", rec.Dimalttd)); data.Add(new Snoop.Data.Int("Dimalttz", rec.Dimalttz)); data.Add(new Snoop.Data.Int("Dimaltu", rec.Dimaltu)); data.Add(new Snoop.Data.Int("Dimaltz", rec.Dimaltz)); data.Add(new Snoop.Data.String("Dimapost", rec.Dimapost)); data.Add(new Snoop.Data.Int("Dimarcsym", rec.Dimarcsym)); data.Add(new Snoop.Data.Distance("Dimasz", rec.Dimasz)); data.Add(new Snoop.Data.Int("Dimatfit", rec.Dimatfit)); data.Add(new Snoop.Data.Int("Dimaunit", rec.Dimaunit)); data.Add(new Snoop.Data.Int("Dimazin", rec.Dimazin)); data.Add(new Snoop.Data.ObjectId("Dimblk", rec.Dimblk)); data.Add(new Snoop.Data.ObjectId("Dimblk1", rec.Dimblk1)); data.Add(new Snoop.Data.ObjectId("Dimblk2", rec.Dimblk2)); data.Add(new Snoop.Data.Distance("Dimcen", rec.Dimcen)); data.Add(new Snoop.Data.ObjectToString("Dimclrd", rec.Dimclrd)); data.Add(new Snoop.Data.ObjectToString("Dimclre", rec.Dimclre)); data.Add(new Snoop.Data.ObjectToString("Dimclrt", rec.Dimclrt)); data.Add(new Snoop.Data.Int("Dimdec", rec.Dimdec)); data.Add(new Snoop.Data.Distance("Dimdle", rec.Dimdle)); data.Add(new Snoop.Data.Distance("Dimdli", rec.Dimdli)); data.Add(new Snoop.Data.String("Dimdsep", rec.Dimdsep.ToString())); data.Add(new Snoop.Data.Distance("Dimexe", rec.Dimexe)); data.Add(new Snoop.Data.Distance("Dimexo", rec.Dimexo)); data.Add(new Snoop.Data.Int("Dimfrac", rec.Dimfrac)); data.Add(new Snoop.Data.Distance("Dimfxlen", rec.Dimfxlen)); data.Add(new Snoop.Data.Bool("DimfxlenOn", rec.DimfxlenOn)); data.Add(new Snoop.Data.Distance("Dimgap", rec.Dimgap)); data.Add(new Snoop.Data.Angle("Dimjogang", rec.Dimjogang)); data.Add(new Snoop.Data.Int("Dimjust", rec.Dimjust)); data.Add(new Snoop.Data.ObjectId("Dimldrblk", rec.Dimldrblk)); data.Add(new Snoop.Data.Distance("Dimlfac", rec.Dimlfac)); data.Add(new Snoop.Data.Bool("Dimlim", rec.Dimlim)); data.Add(new Snoop.Data.ObjectId("Dimltex1", rec.Dimltex1)); data.Add(new Snoop.Data.ObjectId("Dimltex2", rec.Dimltex2)); data.Add(new Snoop.Data.ObjectId("Dimltype", rec.Dimltype)); data.Add(new Snoop.Data.Int("Dimlunit", rec.Dimlunit)); data.Add(new Snoop.Data.String("Dimlwd", rec.Dimlwd.ToString())); data.Add(new Snoop.Data.String("Dimlwe", rec.Dimlwe.ToString())); data.Add(new Snoop.Data.String("Dimpost", rec.Dimpost)); data.Add(new Snoop.Data.Distance("Dimrnd", rec.Dimrnd)); data.Add(new Snoop.Data.Bool("Dimsah", rec.Dimsah)); data.Add(new Snoop.Data.Distance("Dimscale", rec.Dimscale)); data.Add(new Snoop.Data.Bool("Dimsd1", rec.Dimsd1)); data.Add(new Snoop.Data.Bool("Dimsd2", rec.Dimsd2)); data.Add(new Snoop.Data.Bool("Dimse1", rec.Dimse1)); data.Add(new Snoop.Data.Bool("Dimse2", rec.Dimse2)); data.Add(new Snoop.Data.Bool("Dimsoxd", rec.Dimsoxd)); data.Add(new Snoop.Data.Int("Dimtad", rec.Dimtad)); data.Add(new Snoop.Data.Int("Dimtdec", rec.Dimtdec)); data.Add(new Snoop.Data.Distance("Dimtfac", rec.Dimtfac)); data.Add(new Snoop.Data.Int("Dimtfill", rec.Dimtfill)); data.Add(new Snoop.Data.Object("Dimtfillclr", rec.Dimtfillclr)); data.Add(new Snoop.Data.Bool("Dimtih", rec.Dimtih)); data.Add(new Snoop.Data.Bool("Dimtix", rec.Dimtix)); data.Add(new Snoop.Data.Distance("Dimtm", rec.Dimtm)); data.Add(new Snoop.Data.Int("Dimtmove", rec.Dimtmove)); data.Add(new Snoop.Data.Bool("Dimtofl", rec.Dimtofl)); data.Add(new Snoop.Data.Bool("Dimtoh", rec.Dimtoh)); data.Add(new Snoop.Data.Bool("Dimtol", rec.Dimtol)); data.Add(new Snoop.Data.Int("Dimtolj", rec.Dimtolj)); data.Add(new Snoop.Data.Distance("Dimtp", rec.Dimtp)); data.Add(new Snoop.Data.Distance("Dimtsz", rec.Dimtsz)); data.Add(new Snoop.Data.Distance("Dimtvp", rec.Dimtvp)); data.Add(new Snoop.Data.ObjectId("Dimtxsty", rec.Dimtxsty)); data.Add(new Snoop.Data.Distance("Dimtxt", rec.Dimtxt)); data.Add(new Snoop.Data.Int("Dimtzin", rec.Dimtzin)); data.Add(new Snoop.Data.Bool("Dimupt", rec.Dimupt)); data.Add(new Snoop.Data.Int("Dimzin", rec.Dimzin)); }
Stream(ArrayList data, AcDb.SymbolTableRecord tblRec) { data.Add(new Snoop.Data.ClassSeparator(typeof(AcDb.SymbolTableRecord))); data.Add(new Snoop.Data.String("Name", tblRec.Name)); data.Add(new Snoop.Data.Bool("Is dependent", tblRec.IsDependent)); data.Add(new Snoop.Data.Bool("Is resolved", tblRec.IsResolved)); // branch to all known major sub-classes AbstractViewTableRecord viewRec = tblRec as AbstractViewTableRecord; if (viewRec != null) { Stream(data, viewRec); return; } BlockTableRecord blkRec = tblRec as BlockTableRecord; if (blkRec != null) { Stream(data, blkRec); return; } DimStyleTableRecord dimRec = tblRec as DimStyleTableRecord; if (dimRec != null) { Stream(data, dimRec); return; } LayerTableRecord layRec = tblRec as LayerTableRecord; if (layRec != null) { Stream(data, layRec); return; } LinetypeTableRecord ltypeRec = tblRec as LinetypeTableRecord; if (ltypeRec != null) { Stream(data, ltypeRec); return; } TextStyleTableRecord textRec = tblRec as TextStyleTableRecord; if (textRec != null) { Stream(data, textRec); return; } UcsTableRecord ucsRec = tblRec as UcsTableRecord; if (ucsRec != null) { Stream(data, ucsRec); return; } }
public static void AddDimStyle(DimStyle dimStyle) { Document document = Active.Document; Database database = document.Database; try { DimStyleTable dimStyleTable = GetDimStyleTable(); TextStyleTableRecord textStyleTableRecord = GetTextStyle(dimStyle.TextStyle); using (Transaction transaction = database.TransactionManager.StartTransaction()) { LinetypeTableRecord lineTypeTableRecord = GetLineType(transaction, "ByLayer"); if (textStyleTableRecord != null & lineTypeTableRecord != null) { DimStyleTableRecord dimStyleTableRecord = new DimStyleTableRecord(); dimStyleTableRecord.Name = dimStyle.Name; // Lines & Arrows dimStyleTableRecord.Dimasz = dimStyle.TextHeight; dimStyleTableRecord.Dimlwd = LineWeight.ByLayer; dimStyleTableRecord.Dimlwe = LineWeight.ByLayer; dimStyleTableRecord.Dimsd1 = false; dimStyleTableRecord.Dimsd2 = false; dimStyleTableRecord.Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, Constants.COLOR_INDEX_BYLAYER); dimStyleTableRecord.Dimltype = lineTypeTableRecord.ObjectId; dimStyleTableRecord.Dimdle = 0; dimStyleTableRecord.Dimltex1 = lineTypeTableRecord.ObjectId; dimStyleTableRecord.Dimltex2 = lineTypeTableRecord.ObjectId; dimStyleTableRecord.Dimse1 = false; dimStyleTableRecord.Dimse2 = false; dimStyleTableRecord.DimfxlenOn = false; dimStyleTableRecord.Dimfxlen = 1; dimStyleTableRecord.Dimclre = Color.FromColorIndex(ColorMethod.ByAci, Constants.COLOR_INDEX_BYLAYER); dimStyleTableRecord.Dimexe = 0.18; dimStyleTableRecord.Dimexo = 0; // Text dimStyleTableRecord.Dimtfill = 0; dimStyleTableRecord.Dimfrac = 0; dimStyleTableRecord.Dimclrt = Color.FromColorIndex(ColorMethod.ByAci, Constants.COLOR_INDEX_BYLAYER); dimStyleTableRecord.Dimtxt = dimStyle.TextHeight; dimStyleTableRecord.Dimgap = 0.5; dimStyleTableRecord.Dimtih = false; dimStyleTableRecord.Dimtoh = false; dimStyleTableRecord.Dimjust = 0; dimStyleTableRecord.Dimtad = 1; dimStyleTableRecord.Dimtxsty = textStyleTableRecord.ObjectId; // Fit dimStyleTableRecord.Dimtofl = true; dimStyleTableRecord.Dimsoxd = false; dimStyleTableRecord.Dimtix = false; dimStyleTableRecord.Dimscale = dimStyle.DimScale; dimStyleTableRecord.Dimatfit = 3; dimStyleTableRecord.Dimtmove = 0; // Primary Units dimStyleTableRecord.Dimdsep = Char.Parse("."); dimStyleTableRecord.Dimpost = ""; dimStyleTableRecord.Dimrnd = 0; dimStyleTableRecord.Dimlfac = 1; dimStyleTableRecord.Dimlunit = 2; dimStyleTableRecord.Dimazin = 2; dimStyleTableRecord.Dimzin = 8; dimStyleTableRecord.Dimdec = 1; // Alternate Units dimStyleTableRecord.Dimalt = false; // Tolerances dimStyleTableRecord.Dimtol = false; dimStyleTable.Add(dimStyleTableRecord); transaction.AddNewlyCreatedDBObject(dimStyleTableRecord, true); }//if transaction.Commit(); }//using } catch (Exception ex) { Active.WriteMessage(ex.Message); throw; } }
/// <summary> /// 치수선 스타일 만들기 /// </summary> /// <param name="StyleName"></param> public static ObjectId Create_DimensionStyle(string StyleName) { var DimId = ObjectId.Null; #region T using (Transaction T = AC.DB.TransactionManager.StartTransaction()) { DimStyleTable DST = T.GetObject(AC.DB.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable; if (!DST.Has(StyleName)) { #region 생성 DST.UpgradeOpen(); var dstr = new DimStyleTableRecord() { Name = StyleName, // 스타일 이름 Dimasz = 100, // 화살표 크기 Dimtxt = 50, // 문자 크기 Dimexo = 50, // 원점에서 간격띄우기 값 Dimclrt = ColorIndex.Yellow, // 문자 색상 Dimclrd = ColorIndex.Yellow, // 치수선 생상 Dimclre = ColorIndex.Gray, // 치수보조선 색생 Dimtad = 0, // 1: 치수선 위에 입력, 0: 치수선 상에 입력 Dimtoh = false, // 문자 정렬(On/On: 수평, Off/Off: 치수선, On/Off: ISO) Dimtih = false, // 문자 정렬(On/On: 수평, Off/Off: 치수선, On/Off: ISO) Dimdec = 0, // 소수점 자릿수 }; DimId = DST.Add(dstr); T.AddNewlyCreatedDBObject(dstr, true); #endregion } else { #region 수정 DimId = DST[StyleName]; var dstr = T.GetObject(DimId, OpenMode.ForWrite) as DimStyleTableRecord; dstr.Name = StyleName; dstr.Dimasz = 50; dstr.Dimtxt = 50; dstr.Dimexo = 0; dstr.Dimgap = 50; dstr.Dimclrt = ColorIndex.Yellow; dstr.Dimclrd = ColorIndex.Yellow; dstr.Dimclre = ColorIndex.Gray; dstr.Dimtad = 0; dstr.Dimtoh = false; dstr.Dimtih = false; dstr.Dimdec = 0; #endregion } T.Commit(); } #endregion return(DimId); }
public static void CADini() { Dictionary <string, short> ldic = new Dictionary <string, short>(); ldic["粗线"] = 4; ldic["细线"] = 2; ldic["标注"] = 7; ldic["中心线"] = 1; ldic["虚线"] = 3; ldic["图框"] = 8; // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; acCurDb.LoadLineTypeFile("CENTER", "acad.lin"); acCurDb.LoadLineTypeFile("DASHED", "acad.lin"); // Start a transaction using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Layer table for read LayerTable acLyrTbl; acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable; LinetypeTable acLinTbl; acLinTbl = acTrans.GetObject(acCurDb.LinetypeTableId, OpenMode.ForRead) as LinetypeTable; foreach (string key in ldic.Keys) { short cid = ldic[key]; using (LayerTableRecord acLyrTblRec = new LayerTableRecord()) { acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, cid); if (cid != 4) { acLyrTblRec.LineWeight = LineWeight.LineWeight013; } else { acLyrTblRec.LineWeight = LineWeight.LineWeight030; } if (cid == 1) { acLyrTblRec.LinetypeObjectId = acLinTbl["CENTER"]; } if (cid == 3) { acLyrTblRec.LinetypeObjectId = acLinTbl["DASHED"]; } if (cid == 8) { acLyrTblRec.IsPlottable = false; } acLyrTblRec.Name = key; acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForWrite); acLyrTbl.Add(acLyrTblRec); } } TextStyleTable st = acTrans.GetObject(acCurDb.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable; TextStyleTableRecord str = new TextStyleTableRecord() { Name = "En", FileName = "ARIALNBI", }; st.Add(str); acTrans.AddNewlyCreatedDBObject(str, true); TextStyleTableRecord str2 = new TextStyleTableRecord() { Name = "fsdb", FileName = "fsdb_e.shx", BigFontFileName = "fsdb.shx", XScale = 0.75, }; ObjectId textstyleid = st.Add(str2); acTrans.AddNewlyCreatedDBObject(str2, true); DimStyleTable dst = (DimStyleTable)acTrans.GetObject(acCurDb.DimStyleTableId, OpenMode.ForWrite); foreach (int thescale in new int[] { 75, 100 }) { DimStyleTableRecord dstr = new DimStyleTableRecord() { Name = "1-" + thescale.ToString(), Dimscale = thescale, Dimtxsty = textstyleid, Dimclrd = Color.FromColorIndex(ColorMethod.ByAci, 6), Dimclre = Color.FromColorIndex(ColorMethod.ByAci, 6), Dimdli = 5.0, Dimexe = 1.0, Dimexo = 1.0, DimfxlenOn = true, Dimfxlen = 4, Dimtxt = 2, Dimasz = 1.5, Dimtix = true, Dimtmove = 1, Dimtad = 1, Dimgap = 0.8, Dimdec = 0, Dimtih = false, Dimtoh = false, Dimdsep = '.', Dimlfac = 0.1, }; ObjectId dsId = dst.Add(dstr); acTrans.AddNewlyCreatedDBObject(dstr, true); } //------------------------------------------------------------------------------------------- // 自定义块 //------------------------------------------------------------------------------------------- BlockTable bt = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = new BlockTableRecord(); btr.Name = "BG"; bt.UpgradeOpen(); ObjectId btrId = bt.Add(btr); acTrans.AddNewlyCreatedDBObject(btr, true); Polyline Paa = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 9), }; Paa.AddVertexAt(0, new Point2d(0, 0), 0, 0, 200); Paa.AddVertexAt(1, new Point2d(0, 200), 0, 0, 0); btr.AppendEntity(Paa); acTrans.AddNewlyCreatedDBObject(Paa, true); AttributeDefinition curbg = new AttributeDefinition(); curbg.Position = new Point3d(120, 200, 0); curbg.Height = 200; curbg.WidthFactor = 0.75; curbg.Tag = "标高"; curbg.TextStyleId = textstyleid; btr.AppendEntity(curbg); acTrans.AddNewlyCreatedDBObject(curbg, true); //------------------------------------------------------------------------------------------- BlockTableRecord btr2 = new BlockTableRecord(); btr2.Name = "ZP"; bt.UpgradeOpen(); bt.Add(btr2); acTrans.AddNewlyCreatedDBObject(btr2, true); Polyline Paa2 = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 9), }; Paa2.AddVertexAt(0, new Point2d(0 - 350, 0), 0, 0, 80); Paa2.AddVertexAt(1, new Point2d(200 - 350, 0), 0, 0, 0); Paa2.AddVertexAt(2, new Point2d(700 - 350, 0), 0, 0, 0); btr2.AppendEntity(Paa2); acTrans.AddNewlyCreatedDBObject(Paa2, true); AttributeDefinition curzp = new AttributeDefinition(); curzp.Position = new Point3d(220 - 350, 0, 0); curzp.Height = 200; curzp.WidthFactor = 0.75; curzp.Tag = "左坡"; curzp.TextStyleId = textstyleid; btr2.AppendEntity(curzp); acTrans.AddNewlyCreatedDBObject(curzp, true); //------------------------------------------------------------------------------------------- BlockTableRecord btr3 = new BlockTableRecord(); btr3.Name = "YP"; bt.UpgradeOpen(); bt.Add(btr3); acTrans.AddNewlyCreatedDBObject(btr3, true); Polyline Paa3 = new Polyline() { Color = Color.FromColorIndex(ColorMethod.ByAci, 9), }; Paa3.AddVertexAt(0, new Point2d(0 + 350, 0), 0, 0, 80); Paa3.AddVertexAt(1, new Point2d(-200 + 350, 0), 0, 0, 0); Paa3.AddVertexAt(2, new Point2d(-700 + 350, 0), 0, 0, 0); btr3.AppendEntity(Paa3); acTrans.AddNewlyCreatedDBObject(Paa3, true); AttributeDefinition curyp = new AttributeDefinition(); curyp.Position = new Point3d(-220 + 350, 0, 0); curyp.HorizontalMode = TextHorizontalMode.TextRight; curyp.AlignmentPoint = curyp.Position; curyp.Height = 200; curyp.WidthFactor = 0.75; curyp.Tag = "右坡"; curyp.TextStyleId = textstyleid; btr3.AppendEntity(curyp); acTrans.AddNewlyCreatedDBObject(curyp, true); //------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------- acTrans.Commit(); } }
public static ObjectId CreateDimStyle(string _name, ObjectId _text, ObjectId _arrow) { Document mdiActiveDocument = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; Database database = mdiActiveDocument.Database; Editor editor = mdiActiveDocument.Editor; ObjectId result; using (mdiActiveDocument.LockDocument()) { using (Transaction transaction = database.TransactionManager.StartTransaction()) { DimStyleTable dimStyleTable = transaction.GetObject(database.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable; if (!dimStyleTable.Has(_name)) { DimStyleTableRecord dimStyleTableRecord = new DimStyleTableRecord(); dimStyleTableRecord.Name = _name; dimStyleTableRecord.Dimadec = 2; dimStyleTableRecord.Dimalt = false; dimStyleTableRecord.Dimaltd = 0; dimStyleTableRecord.Dimaltf = 25.4; dimStyleTableRecord.Dimaltrnd = 0.0; dimStyleTableRecord.Dimalttd = 0; dimStyleTableRecord.Dimalttz = 0; dimStyleTableRecord.Dimaltu = 2; dimStyleTableRecord.Dimaltz = 0; dimStyleTableRecord.Dimapost = ""; dimStyleTableRecord.Dimarcsym = 0; dimStyleTableRecord.Dimatfit = 3; dimStyleTableRecord.Dimaunit = 1; dimStyleTableRecord.Dimazin = 0; dimStyleTableRecord.Dimblk = _arrow; dimStyleTableRecord.Dimblk1 = _arrow; dimStyleTableRecord.Dimblk2 = _arrow; dimStyleTableRecord.Dimcen = 2.0; dimStyleTableRecord.Dimclrd = Color.FromColorIndex(ColorMethod.ByBlock, 8); dimStyleTableRecord.Dimclre = Color.FromColorIndex(ColorMethod.ByBlock, 8); dimStyleTableRecord.Dimclrt = Color.FromColorIndex(ColorMethod.ByBlock, 4); dimStyleTableRecord.Dimdec = 0; dimStyleTableRecord.Dimdle = 0.0; dimStyleTableRecord.Dimdli = 7.0; dimStyleTableRecord.Dimdsep = char.Parse("Null"); dimStyleTableRecord.Dimexe = 0.1; dimStyleTableRecord.Dimexo = 0.1; dimStyleTableRecord.Dimfrac = 1; dimStyleTableRecord.Dimgap = 0.5; dimStyleTableRecord.Dimldrblk = _arrow; dimStyleTableRecord.Dimlfac = 1.0; dimStyleTableRecord.Dimlim = false; dimStyleTableRecord.Dimltex1 = database.ByBlockLinetype; dimStyleTableRecord.Dimltex2 = database.ByBlockLinetype; dimStyleTableRecord.Dimltype = database.ByBlockLinetype; dimStyleTableRecord.Dimlunit = 2; dimStyleTableRecord.Dimlwd = LineWeight.ByBlock; dimStyleTableRecord.Dimlwe = LineWeight.ByBlock; dimStyleTableRecord.Dimpost = ""; dimStyleTableRecord.Dimrnd = 0.5; dimStyleTableRecord.Dimsah = true; dimStyleTableRecord.Dimscale = 0.2; dimStyleTableRecord.Dimsd1 = false; dimStyleTableRecord.Dimsd2 = false; dimStyleTableRecord.Dimse1 = false; dimStyleTableRecord.Dimse2 = false; dimStyleTableRecord.Dimsoxd = false; dimStyleTableRecord.Dimtad = 1; dimStyleTableRecord.Dimtdec = 1; dimStyleTableRecord.Dimtfac = 1.0; dimStyleTableRecord.Dimtih = false; dimStyleTableRecord.Dimtix = true; dimStyleTableRecord.Dimtm = 0.0; dimStyleTableRecord.Dimtmove = 2; dimStyleTableRecord.Dimtofl = true; dimStyleTableRecord.Dimtoh = false; dimStyleTableRecord.Dimtol = false; dimStyleTableRecord.Dimtolj = 0; dimStyleTableRecord.Dimtp = 0.0; dimStyleTableRecord.Dimtsz = 0.0; dimStyleTableRecord.Dimtxsty = _text; dimStyleTableRecord.Dimtvp = 0.0; dimStyleTableRecord.Dimtxt = 1.7; dimStyleTableRecord.Dimtzin = 8; dimStyleTableRecord.Dimupt = false; dimStyleTableRecord.Dimzin = 8; dimStyleTableRecord.DimfxlenOn = true; dimStyleTableRecord.Dimfxlen = 40.0; dimStyleTableRecord.Dimtxt = 0.5; dimStyleTableRecord.Dimasz = 0.2; result = dimStyleTable.Add(dimStyleTableRecord); transaction.AddNewlyCreatedDBObject(dimStyleTableRecord, true); } else { result = dimStyleTable[_name]; } transaction.Commit(); } } return(result); }
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(); } } } }