using System; using System.Collections.Generic; using System.Linq; using System.Text; using GrxCAD.Runtime; using GrxCAD.Geometry; using GrxCAD.DatabaseServices; using GrxCAD.ApplicationServices; using GrxCAD.EditorInput; using GrxCAD.Internal; using System.Windows.Forms; namespace HCTools { class BasicFunction { /// /// 根据点坐标创建圆形标记 /// public void makeflag(double x, double y, double z, double radius, string layername) { Database database = HostApplicationServices.WorkingDatabase; DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); using (Transaction traction = database.TransactionManager.StartTransaction()) { BlockTable blocktable = traction.GetObject(database.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Circle circ = new Circle(); circ.Center = new Point3d(x, y, z); circ.Radius = radius; circ.Normal = new Vector3d(0, 0, 1); circ.SetDatabaseDefaults(); circ.Layer = layername; blocktablerecord.AppendEntity(circ); traction.AddNewlyCreatedDBObject(circ, true); traction.Commit(); doclock.Dispose(); traction.Dispose(); } } /// /// 获取等高线 /// public static ObjectId[] getHeight(string LayerName) { ObjectId[] ids = null; Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; TypedValue[] value = new TypedValue[] { new TypedValue((int)DxfCode.LayerName,LayerName), new TypedValue((int)DxfCode.Start,"LWPOLYLINE") };//设置筛选条件 SelectionFilter filter = new SelectionFilter(value); //选择区域中全部对象 //PromptSelectionResult psr = ed.SelectAll(filter); // 要求在图形区域中手动选择对象 PromptSelectionResult psr = ed.GetSelection(filter); if (psr.Status == PromptStatus.OK) { using (Transaction trans = db.TransactionManager.StartTransaction()) { SelectionSet ss = psr.Value; ids = ss.GetObjectIds(); trans.Commit(); } } return ids; } /// /// 获取二维多段线和多段线 /// public static ObjectId[] getPll() { ObjectId[] ids = null; Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; TypedValue[] value = new TypedValue[] { new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE"), };//设置筛选条件 SelectionFilter filter = new SelectionFilter(value); //选择区域中全部对象 //PromptSelectionResult psr = ed.SelectAll(filter); // 要求在图形区域中手动选择对象 PromptSelectionResult psr = ed.GetSelection(filter); if (psr.Status == PromptStatus.OK) { using (Transaction trans = db.TransactionManager.StartTransaction()) { SelectionSet ss = psr.Value; ids = ss.GetObjectIds(); trans.Commit(); } } return ids; } /// /// 根据Id获取实体 /// public static Entity GetDBObject(ObjectId i) { //Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; //Database db = doc.Database; Database db = HostApplicationServices.WorkingDatabase; Entity ent = null; DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); using (Transaction tr = db.TransactionManager.StartTransaction()) { ent = (Entity)tr.GetObject(i, OpenMode.ForRead, true); tr.Commit(); } doclock.Dispose(); return ent; } /// /// 根据编号判断地物类型 /// //2022-7-25-qyx改 public static string get_TypeName(string key) { string name = ""; //switch (key) //{ // case "011": // name = "水田"; // break; // case "012": // name = "水浇地"; // break; // case "013": // name = "旱地"; // break; // case "021": // name = "果园"; // break; // case "022": // name = "茶园"; // break; // case "023": // name = "其他园地"; // break; // case "031": // name = "有林地"; // break; // case "032": // name = "灌木林地"; // break; // case "033": // name = "其他林地"; // break; // case "041": // name = "天然牧草地"; // break; // case "042": // name = "人工牧草地"; // break; // case "043": // name = "其他草地"; // break; // case "051": // name = "批发零售用地"; // break; // case "052": // name = "住宿餐饮用地"; // break; // case "053": // name = "商务金融用地"; // break; // case "054": // name = "其他商服用地"; // break; // case "061": // name = "工业用地"; // break; // case "062": // name = "采矿用地"; // break; // case "063": // name = "仓储用地"; // break; // case "071": // name = "城镇住宅用地"; // break; // case "072": // name = "农村宅基地"; // break; // case "081": // name = "机关团体用地"; // break; // case "082": // name = "新闻出版用地"; // break; // case "083": // name = "科教用地"; // break; // case "084": // name = "医卫慈善用地"; // break; // case "085": // name = "文体娱乐用地"; // break; // case "086": // name = "公共设施用地"; // break; // case "087": // name = "公园与绿地"; // break; // case "088": // name = "风景名胜设施用地"; // break; // case "091": // name = "军事设施用地"; // break; // case "092": // name = "使领馆用地"; // break; // case "093": // name = "监教场所用地"; // break; // case "094": // name = "宗教用地"; // break; // case "095": // name = "殡葬用地"; // break; // case "101": // name = "铁路用地"; // break; // case "102": // name = "公路用地"; // break; // case "103": // name = "街巷用地"; // break; // case "104": // name = "农村道路"; // break; // case "105": // name = "机场用地"; // break; // case "106": // name = "港口码头用地"; // break; // case "107": // name = "管道运输用地"; // break; // case "111": // name = "河流水面"; // break; // case "112": // name = "湖泊水面"; // break; // case "113": // name = "水库水面"; // break; // case "114": // name = "坑塘水面"; // break; // case "115": // name = "沿海滩涂"; // break; // case "116": // name = "内陆滩涂"; // break; // case "117": // name = "沟渠"; // break; // case "118": // name = "水工建筑用地"; // break; // case "119": // name = "冰川及永久积雪"; // break; // case "121": // name = "空闲地"; // break; // case "122": // name = "设施农用地"; // break; // case "123": // name = "田坎"; // break; // case "124": // name = "盐碱地"; // break; // case "125": // name = "沼泽地"; // break; // case "126": // name = "沙地"; // break; // case "127": // name = "裸地"; // break; // default: // break; //} // 编号不同 switch (key) { case "0101": name = "水田"; break; case "0102": name = "水浇地"; break; case "0103": name = "旱地"; break; case "0201": name = "果园"; break; case "0202": name = "茶园"; break; case "0203": name = "橡胶园"; break; case "0204": name = "其他园地"; break; case "0301": name = "乔木林地"; break; case "0302": name = "竹林地"; break; case "0303": name = "红树林地"; break; case "0304": name = "森林沼泽"; break; case "0305": name = "灌木林地"; break; case "0306": name = "灌丛沼泽"; break; case "0307": name = "其他林地"; break; case "0401": name = "天然牧草地"; break; case "0402": name = "沼泽草地"; break; case "0403": name = "人工牧草地"; break; case "0404": name = "其他草地"; break; case "0501": name = "零售商业用地"; break; case "0502": name = "批发市场用地"; break; case "0503": name = "餐饮用地"; break; case "0504": name = "旅馆用地"; break; case "0505": name = "商业金融用地"; break; case "0506": name = "娱乐用地"; break; case "0507": name = "其他商服用地"; break; case "0601": name = "工业用地"; break; case "0602": name = "采矿用地"; break; case "0603": name = "盐田"; break; case "0604": name = "仓储用地"; break; case "0701": name = "城镇住宅用地"; break; case "0702": name = "农村宅基地"; break; case "0801": name = "机关团体用地"; break; case "0802": name = "新闻出版用地"; break; case "0803": name = "教育用地"; break; case "0804": name = "科研用地"; break; case "0805": name = "医疗卫生用地"; break; case "0806": name = "社会福利用地"; break; case "0807": name = "文化设施用地"; break; case "0808": name = "体育用地"; break; case "0809": name = "公用设施用地"; break; case "0810": name = "公园与绿地"; break; case "0901": name = "军事设施用地"; break; case "0902": name = "使领馆用地"; break; case "0903": name = "监教场所用地"; break; case "0904": name = "宗教用地"; break; case "0905": name = "殡葬用地"; break; case "0906": name = "风景名胜设施用地"; break; case "1001": name = "铁路用地"; break; case "1002": name = "轨道交通用地"; break; case "1003": name = "公路用地"; break; case "1004": name = "城镇村道路用地"; break; case "1005": name = "交通服务场所用地"; break; case "1006": name = "农村道路"; break; case "1007": name = "机场用地"; break; case "1008": name = "港口码头用地"; break; case "1009": name = "管道运输用地"; break; case "1101": name = "河流水面"; break; case "1102": name = "湖泊水面"; break; case "1103": name = "水库水面"; break; case "1104": name = "坑塘水面"; break; case "1105": name = "沿海滩涂"; break; case "1106": name = "内陆滩涂"; break; case "1107": name = "沟渠"; break; case "1108": name = "沼泽地"; break; case "1109": name = "水工建筑用地"; break; case "1110": name = "冰川及永久积雪"; break; case "1201": name = "空闲地"; break; case "1202": name = "设施农用地"; break; case "1203": name = "田坎"; break; case "1204": name = "盐碱地"; break; case "1205": name = "沙地"; break; case "1206": name = "裸土地"; break; case "1207": name = "裸岩石砾地"; break; default: break; } return name; } public static ObjectId AddObj(Document doc,Entity ent) { ObjectId id = new ObjectId(); Database database = doc.Database; DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); using (Transaction traction = database.TransactionManager.StartTransaction()) { BlockTable blocktable = traction.GetObject(database.BlockTableId,OpenMode.ForWrite) as BlockTable; BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; blocktablerecord.AppendEntity(ent); traction.AddNewlyCreatedDBObject(ent, true); id = ent.ObjectId; traction.Commit(); doclock.Dispose(); } return id; } /// /// 添加命令 /// //public void addCommand() //{ // MainClass main = new MainClass(); // Utils.AddCommand("COMMAND1", "PLError", "ТЕСТ1", CommandFlags.Modal, main.PLError); // Utils.AddCommand("COMMAND1", "PLOverlap", "ТЕСТ2", CommandFlags.Modal, main.PLOverlap); // Utils.AddCommand("COMMAND1", "Report", "ТЕСТ3", CommandFlags.Modal, main.Report); // Utils.AddCommand("COMMAND1", "Fills", "ТЕСТ4", CommandFlags.Modal, main.Fill); // Utils.AddCommand("COMMAND1", "BATChange", "ТЕСТ5", CommandFlags.Modal, main.BATChange); // Utils.AddCommand("COMMAND1", "PtCheck", "ТЕСТ6", CommandFlags.Modal, main.PointCheck); // Utils.AddCommand("COMMAND1", "Hierarchy", "ТЕСТ7", CommandFlags.Modal, main.Hierarchy); // Utils.AddCommand("COMMAND1", "CLCheck", "ТЕСТ8", CommandFlags.Modal, main.CLCheck); // //Utils.AddCommand("COMMAND1", "Connect", "ТЕСТ9", CommandFlags.Modal, main.Connect); // Utils.AddCommand("COMMAND1", "SelfIntersect", "ТЕСТ10", CommandFlags.Modal, main.SelfIntersect); // Utils.AddCommand("COMMAND1", "EachIntersect", "ТЕСТ11", CommandFlags.Modal, main.EachIntersect); // Utils.AddCommand("COMMAND1", "combFace", "ТЕСТ12", CommandFlags.Modal, main.combF); // Utils.AddCommand("COMMAND1", "splitFace", "ТЕСТ13", CommandFlags.Modal, main.splitF); // Utils.AddCommand("COMMAND1", "pickupPoint", "ТЕСТ14", CommandFlags.Modal, main.pickupP); // Utils.AddCommand("COMMAND1", "FakeCheck", "ТЕСТ15", CommandFlags.Modal, main.FFake); // Utils.AddCommand("COMMAND1", "HangCheck", "ТЕСТ16", CommandFlags.Modal, main.HFake); // Utils.AddCommand("COMMAND1", "SlopeLine", "ТЕСТ17", CommandFlags.Modal, main.SlpLine); // Utils.AddCommand("COMMAND1", "SheetMap", "ТЕСТ18", CommandFlags.Modal, main.SheetMap); //} /// /// 删除命令 /// //public void deleteCommand() //{ // Utils.RemoveCommand("PLError", "TEST1"); // Utils.RemoveCommand("PLOverlap", "TEST2"); // Utils.RemoveCommand("Report", "TEST3"); // Utils.RemoveCommand("Fills", "TEST4"); // Utils.RemoveCommand("BATChange", "TEST5"); // Utils.RemoveCommand("PtCheck", "TEST6"); // Utils.RemoveCommand("Hierarchy", "TEST7"); // Utils.RemoveCommand("CLCheck", "TEST8"); // //Utils.RemoveCommand("Connect", "TEST9"); // Utils.RemoveCommand("SelfIntersect", "TEST10"); // Utils.RemoveCommand("EachIntersect", "TEST11"); // Utils.RemoveCommand("combFace", "TEST12"); // Utils.RemoveCommand("splitFace", "TEST13"); // Utils.RemoveCommand("pickupPoint", "TEST14"); // Utils.RemoveCommand("FakeCheck", "TEST15"); // Utils.RemoveCommand("HangCheck", "TEST16"); // Utils.RemoveCommand("SlopeLine", "TEST17"); // Utils.RemoveCommand("SheetMap", "TEST18"); //} } /// /// 对图层的操作处理,包括新建图层、 /// 把指定图层设置为当前图层和检查是否包含某个图层名 /// class LayerControl { /// /// 创建高程点错误标记层 /// /// 要创建的图层的名字 /// RGB三原色 public void creatlayer(string layername, colorgb colo) { Database database = GrxCAD.DatabaseServices.HostApplicationServices.WorkingDatabase; DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); Transaction traction = database.TransactionManager.StartTransaction(); LayerTable lt = traction.GetObject(database.LayerTableId, OpenMode.ForWrite) as LayerTable; try { LayerTableRecord layertablerecord = new LayerTableRecord(); layertablerecord.Name = layername;//设置层表记录的名字 layertablerecord.Color = GrxCAD.Colors.Color.FromRgb(colo.red, colo.green, colo.blue);//为层表记录赋颜色紫色 //layertablerecord.Color = GrxCAD.Colors.Color.FromColor(System.Drawing.Color.Magenta); lt.Add(layertablerecord); traction.AddNewlyCreatedDBObject(layertablerecord, true); traction.Commit(); } catch (GrxCAD.Runtime.Exception) { traction.Abort(); } finally { traction.Dispose(); doclock.Dispose(); } } /// /// 将指定图层设置为当前图层 /// /// 要设置为当前图层的图层名字 public void movelayertofront(string layername) { Database database = GrxCAD.DatabaseServices.HostApplicationServices.WorkingDatabase; DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); Transaction traction = database.TransactionManager.StartTransaction(); try { LayerTable layertable = traction.GetObject(database.LayerTableId, OpenMode.ForRead) as LayerTable; database.Clayer = layertable[layername];//把图层选为当前图层 traction.Commit(); } catch (GrxCAD.Runtime.Exception) { traction.Abort(); } finally { traction.Dispose(); doclock.Dispose(); } } /// /// 判断所命图层名是否已经存在 /// /// 要判断的图层名字 /// 返回true表示在层表中存在要判断的图层名, /// 返回false表示层表中不存在判断的图层名 public bool haslayername(string layername) { Database database = GrxCAD.DatabaseServices.HostApplicationServices.WorkingDatabase; using (Transaction traction = database.TransactionManager.StartTransaction()) { LayerTable lt = traction.GetObject(database.LayerTableId, OpenMode.ForRead) as LayerTable; if (lt.Has(layername)) { traction.Commit(); return true; } else { traction.Commit(); return false; } } } public void clear(string layername) { Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database database = HostApplicationServices.WorkingDatabase; DocumentLock documentlock = null; Transaction traction = null; try { traction = database.TransactionManager.StartTransaction(); documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); BlockTable blocktable = traction.GetObject(database.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; TypedValue[] typedvalue = new TypedValue[2]; typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "Circle"), 0); typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, "Cir"), 1); SelectionFilter selectionfilter = new SelectionFilter(typedvalue); PromptSelectionResult select = editor.SelectAll(selectionfilter); if (select.Status == PromptStatus.OK) { SelectionSet set = select.Value; ObjectId[] obj = new ObjectId[set.Count]; obj = set.GetObjectIds(); for (int i = 0; i < obj.Length; i++) { ObjectId objid = obj[i]; Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForWrite); entity.Erase(); } } traction.Commit(); } catch (GrxCAD.Runtime.Exception) { } } } /// /// RGB三原色 /// public struct colorgb { public byte red; public byte green; public byte blue; public colorgb(byte r, byte g, byte b) { this.red = r; this.green = g; this.blue = b; } } /// /// 创建图廓 /// class CreateSheetMap { private Point3d LB; private Point3d LT; private Point3d RB; private Point3d RT; private List> TKpts = new List>(); double dist = 200; //格网间距 string layername = "9800"; string Number; //图幅号 string Left_Number; string Right_Number; string Leftup_Number; string Leftdown_Number; string Rightup_Number; string Rightdown_Number; string Centrolup_Number; string Centroldown_Number; public void create() { int BLC = TKInfo.BLC; if (BLC == 1000) { dist = 100; } if (BLC == 500) { dist = 50; } getinfo(); for (int i = 0; i < TKpts.Count; i++) { LB = TKpts[i][0]; LT = TKpts[i][1]; RB = TKpts[i][2]; RT = TKpts[i][3]; //左编号 Point3d p1 = new Point3d(LB.X - dist * 5 - 100, LB.Y - 100, 0); Point3d p2 = new Point3d(LT.X + 50, LT.Y + 50, 0); Left_Number = GetNumber(p1, p2); //右编号 p1 = new Point3d(RT.X + dist * 5 + 100, RT.Y + 100, 0); p2 = new Point3d(RB.X - 50, RB.Y - 50, 0); Right_Number = GetNumber(p1, p2); //左上编号 p1 = new Point3d(LT.X - dist * 5 - 100, LT.Y + dist * 5 + 100, 0); p2 = new Point3d(LT.X + 50, LT.Y - 50, 0); Leftup_Number = GetNumber(p1, p2); //左下编号 p1 = new Point3d(LB.X - dist * 5 - 100, LB.Y - dist * 5 - 100, 0); p2 = new Point3d(LB.X + 50, LB.Y + 50, 0); Leftdown_Number = GetNumber(p1, p2); //中上编号 p1 = new Point3d(LT.X - 100, LT.Y - 100, 0); p2 = new Point3d(RT.X + 50, RT.Y + dist * 5 + 50, 0); Centrolup_Number = GetNumber(p1, p2); //中下编号 p1 = new Point3d(LB.X - 100, LB.Y - dist * 5 - 100, 0); p2 = new Point3d(RB.X + 50, RB.Y + 50, 0); Centroldown_Number = GetNumber(p1, p2); //右上编号 p1 = new Point3d(RT.X - 100, RT.Y - 100, 0); p2 = new Point3d(RT.X + dist * 5 + 50, RT.Y + dist * 5 + 50, 0); Rightup_Number = GetNumber(p1, p2); //右下编号 p1 = new Point3d(RB.X - 100, RB.Y + 100, 0); p2 = new Point3d(RB.X + dist * 5 + 50, RB.Y - dist * 5 - 50, 0); Rightdown_Number = GetNumber(p1, p2); //图幅号 p1 = new Point3d(LB.X - 100, LB.Y - 100, 0); p2 = new Point3d(RT.X + 100, RT.Y + 100, 0); Number = GetNumber(p1, p2); //新建一个dwg string templatePath = "acad.dwt"; DocumentCollection documentcoll = GrxCAD.ApplicationServices.Application.DocumentManager; Document document = documentcoll.Add(templatePath); Database database = document.Database; LayerControl layerscontrol = new LayerControl(); if (layerscontrol.haslayername(layername) == false) { colorgb col = new colorgb(255, 0, 0); layerscontrol.creatlayer(layername, col); layerscontrol.movelayertofront(layername); } else layerscontrol.movelayertofront(layername); createTextStyle(); draw(); zoom(); //database.SaveAs(TKInfo.SV + "\\" + Number.ToString() + ".dwg", DwgVersion.AC1024); database.SaveAs(TKInfo.SV + "\\" + Number.ToString() + ".dwg", true, DwgVersion.AC1021, database.SecurityParameters); //document.CloseAndSave(Number.ToString() + ".dwg"); document.CloseAndDiscard(); } } private void getinfo() { Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database database = HostApplicationServices.WorkingDatabase; using (Transaction traction = database.TransactionManager.StartTransaction()) { DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); BlockTable blocktable = traction.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable; Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; TypedValue[] typedvalue = new TypedValue[1]; typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "3dFace,LWPolyline"), 0); SelectionFilter selectionfilter = new SelectionFilter(typedvalue); PromptSelectionResult psr = editor.GetSelection(selectionfilter); if (psr.Status == PromptStatus.OK) { SelectionSet selectionset = psr.Value; ObjectId[] obj = new ObjectId[selectionset.Count]; obj = selectionset.GetObjectIds(); for (int i = 0; i < obj.Length; i++) { ObjectId objid = obj[i]; Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead); Point3dCollection coll = new Point3dCollection(); if (entity is Face) { Face f = entity as Face; f.GetStretchPoints(coll); } else if (entity is Polyline) { Polyline line = entity as Polyline; line.GetStretchPoints(coll); } LB = coll[0]; LT = coll[0]; RB = coll[0]; RT = coll[0]; for (int ii = 1; ii < coll.Count; ii++) { double x = coll[ii].X; double y = coll[ii].Y; if (x <= LB.X && y <= LB.Y) { LB = coll[ii]; } if (x <= LT.X && y >= LT.Y) { LT = coll[ii]; } if (x >= RB.X && y <= RB.Y) { RB = coll[ii]; } if (x >= RT.X && y >= RT.Y) { RT = coll[ii]; } } List temp = new List(); temp.Add(LB); temp.Add(LT); temp.Add(RB); temp.Add(RT); TKpts.Add(temp); } } traction.Commit(); documentlock.Dispose(); } } private void draw() { int BLC = TKInfo.BLC; double len = 10; //分幅框标长度 double D22 = 22; //内图廓线和外图廓线距离 double D1 = 1.0; //间距为1 double D2 = 2.0; //间距为2 double D3 = 3.0; //间距为3 double D4 = 4.0; //间距为4 double D4_8 = 4.8; //间距为4.8 double D5 = 5.0; //间距为5 double D6 = 6.0; //间距为6 double D7 = 7.0; //间距为7 double D8 = 8.0; //间距为8 double D10 = 10.0; //间距为10 double D12 = 12.0; //间距为12 double D140 = 140; //右下角附注 double D90 = 90; double D48 = 48; double dist1 = 1.625; //接图表第一格填充间距 double dist2 = Math.Sqrt(8); //接图表填充间距 if (BLC == 1000) { len = len / 2; //分幅框标长度 D22 = D22 / 2; //内图廓线和外图廓线距离 D1 = D1 / 2; //间距为1 D2 = D2 / 2; //间距为2 D3 = D3 / 2; //间距为3 D4 = D4 / 2; //间距为4 D4_8 = D4_8 / 2; //间距为4.8 D5 = D5 / 2; //间距为5 D6 = D6 / 2; //间距为6 D7 = D7 / 2; //间距为7 D8 = D8 / 2; //间距为8 D10 = D10 / 2; //间距为10 D12 = D12 / 2; //间距为12 D140 = D140 / 2; //右下角附注 D90 = D90 / 2; D48 = D48 / 2; dist1 = dist1 / 2; //接图表第一格填充间距 dist2 = dist2 / 2; //接图表填充间距 } if (BLC == 500) { len = len / 4; //分幅框标长度 D22 = D22 / 4; //内图廓线和外图廓线距离 D1 = D1 / 4; //间距为1 D2 = D2 / 4; //间距为2 D3 = D3 / 4; //间距为3 D4 = D4 / 4; //间距为4 D4_8 = D4_8 / 4; //间距为4.8 D5 = D5 / 4; //间距为5 D6 = D6 / 4; //间距为6 D7 = D7 / 4; //间距为7 D8 = D8 / 4; //间距为8 D10 = D10 / 4; //间距为10 D12 = D12 / 4; //间距为12 D140 = D140 / 4; //右下角附注 D90 = D90 / 4; D48 = D48 / 4; dist1 = dist1 / 4; //接图表第一格填充间距 dist2 = dist2 / 4; //接图表填充间距 } ObjectId HZ = gettextstyleID("HZ"); ObjectId st = gettextstyleID("st"); ObjectId ht = gettextstyleID("ht"); ObjectId Standard = gettextstyleID("Standard"); ObjectId ID12 = gettextstyleID("12"); ObjectId ID123 = gettextstyleID("123"); //ObjectId XDXT = gettextstyleID("细等线体"); //ObjectId ZDXT = gettextstyleID("中等线体"); //ObjectId ST = gettextstyleID("宋体"); double xx1, yy1; double xx2, yy2; int DH; Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database database = HostApplicationServices.WorkingDatabase; Transaction traction = database.TransactionManager.StartTransaction(); DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); BlockTable blocktable = traction.GetObject(database.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; //try //{ //内图廓 //左边线 Point3dCollection In1 = new Point3dCollection(); In1.Add(new Point3d(LT.X, LT.Y + D22 + D1, 0)); In1.Add(new Point3d(LB.X, LB.Y - D22 - D1, 0)); Polyline2d LeftLine = new Polyline2d(Poly2dType.SimplePoly, In1, 0, false, 0, 0, null); //LeftLine.Color = GrxCAD.Colors.Color.FromColor(System.Drawing.Color.Red); LeftLine.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); LeftLine.Layer = layername; LeftLine.SetDatabaseDefaults(); blocktablerecord.AppendEntity(LeftLine); traction.AddNewlyCreatedDBObject(LeftLine, true); //下边线 Point3dCollection In2 = new Point3dCollection(); In2.Add(new Point3d(LB.X - D22 - D1, LB.Y, 0)); In2.Add(new Point3d(RB.X + D22 + D1, RB.Y, 0)); Polyline2d LowLine = new Polyline2d(Poly2dType.SimplePoly, In2, 0, false, 0, 0, null); LowLine.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); LowLine.SetDatabaseDefaults(); blocktablerecord.AppendEntity(LowLine); traction.AddNewlyCreatedDBObject(LowLine, true); //右边线 Point3dCollection In3 = new Point3dCollection(); In3.Add(new Point3d(RT.X, RT.Y + D22 + D1, 0)); In3.Add(new Point3d(RB.X, RB.Y - D22 - D1, 0)); Polyline2d RightLine = new Polyline2d(Poly2dType.SimplePoly, In3, 0, false, 0, 0, null); RightLine.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); RightLine.Layer = layername; RightLine.SetDatabaseDefaults(); blocktablerecord.AppendEntity(RightLine); traction.AddNewlyCreatedDBObject(RightLine, true); //上边线 Point3dCollection In4 = new Point3dCollection(); In4.Add(new Point3d(LT.X - D22 - D1, LT.Y, 0)); In4.Add(new Point3d(RT.X + D22 + D1, RT.Y, 0)); Polyline2d TOPLine = new Polyline2d(Poly2dType.SimplePoly, In4, 0, false, 0, 0, null); TOPLine.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); TOPLine.Layer = layername; TOPLine.SetDatabaseDefaults(); blocktablerecord.AppendEntity(TOPLine); traction.AddNewlyCreatedDBObject(TOPLine, true); //外图廓 Point3dCollection Outcoll = new Point3dCollection(); Outcoll.Add(new Point3d(LT.X - D22 - D1, LT.Y + D22 + D1, 0)); Outcoll.Add(new Point3d(LB.X - D22 - D1, LB.Y - D22 - D1, 0)); Outcoll.Add(new Point3d(RB.X + D22 + D1, RB.Y - D22 - D1, 0)); Outcoll.Add(new Point3d(RT.X + D22 + D1, RT.Y + D22 + D1, 0)); Outcoll.Add(new Point3d(LT.X - D22 - D1, LT.Y + D22 + D1, 0)); Polyline2d line = new Polyline2d(Poly2dType.SimplePoly, Outcoll, 0, true, D2, D2, null); line.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); line.Layer = layername; line.SetDatabaseDefaults(); blocktablerecord.AppendEntity(line); traction.AddNewlyCreatedDBObject(line, true); line.UpgradeOpen(); line.ConstantWidth = D2; //分幅框标 for (int i = 1; i <= 4; i++) { for (int j = 1; j <= 4; j++) { //中心点 double x = LB.X + i * dist; double y = LB.Y + j * dist; //横线 Point3d p1 = new Point3d(x - len, y, 0); Point3d p2 = new Point3d(x + len, y, 0); Point3dCollection kb = new Point3dCollection(); kb.Add(p1); kb.Add(p2); Polyline2d kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null); kbline.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); kbline.Layer = layername; kbline.SetDatabaseDefaults(); blocktablerecord.AppendEntity(kbline); traction.AddNewlyCreatedDBObject(kbline, true); //竖线 p1 = new Point3d(x, y - len, 0); p2 = new Point3d(x, y + len, 0); kb = new Point3dCollection(); kb.Add(p1); kb.Add(p2); kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null); kbline.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); kbline.Layer = layername; kbline.SetDatabaseDefaults(); blocktablerecord.AppendEntity(kbline); traction.AddNewlyCreatedDBObject(kbline, true); } } for (int i = 1; i <= 4; i++) { double x; double y; Point3d p1; Point3d p2; //下边线 x = LB.X; y = LB.Y; p1 = new Point3d(x + i * dist, y + len, 0); p2 = new Point3d(x + i * dist, y, 0); Point3dCollection kb = new Point3dCollection(); kb.Add(p1); kb.Add(p2); Polyline2d kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null); kbline.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); kbline.Layer = layername; kbline.SetDatabaseDefaults(); blocktablerecord.AppendEntity(kbline); traction.AddNewlyCreatedDBObject(kbline, true); //上边线 x = LB.X; y = LT.Y; p1 = new Point3d(x + i * dist, y - len, 0); p2 = new Point3d(x + i * dist, y, 0); kb = new Point3dCollection(); kb.Add(p1); kb.Add(p2); kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null); kbline.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); kbline.Layer = layername; kbline.SetDatabaseDefaults(); blocktablerecord.AppendEntity(kbline); traction.AddNewlyCreatedDBObject(kbline, true); //左边线 x = LB.X; y = LB.Y; p1 = new Point3d(x, y + i * dist, 0); p2 = new Point3d(x + len, y + i * dist, 0); kb = new Point3dCollection(); kb.Add(p1); kb.Add(p2); kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null); kbline.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); kbline.Layer = layername; kbline.SetDatabaseDefaults(); blocktablerecord.AppendEntity(kbline); traction.AddNewlyCreatedDBObject(kbline, true); //右边线 x = RB.X; y = LB.Y; p1 = new Point3d(x, y + i * dist, 0); p2 = new Point3d(x - len, y + i * dist, 0); kb = new Point3dCollection(); kb.Add(p1); kb.Add(p2); kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null); kbline.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); kbline.Layer = layername; kbline.SetDatabaseDefaults(); blocktablerecord.AppendEntity(kbline); traction.AddNewlyCreatedDBObject(kbline, true); } //右下角附注 double xx = RB.X; double yy = RB.Y; xx = xx - D140; yy = yy - D22 - D2 - D6; List RLnote = new List(); string str = ""; if (string.IsNullOrEmpty(TKInfo.CTY) == false) { str = TKInfo.CTY; RLnote.Add(str); } if (string.IsNullOrEmpty(TKInfo.TDY) == false) { str = TKInfo.TDY; RLnote.Add(str); } if (string.IsNullOrEmpty(TKInfo.SHY) == false) { str = TKInfo.SHY; RLnote.Add(str); } if (string.IsNullOrEmpty(TKInfo.JCY) == false) { str = TKInfo.JCY; RLnote.Add(str); } str = "复查员 "; RLnote.Add(str); //秘密等级 if (string.IsNullOrEmpty(TKInfo.Secret) == false) { str = TKInfo.Secret; DBText text1_secret = new DBText(); text1_secret.TextString = str; text1_secret.WidthFactor = 1.333; text1_secret.HorizontalMode = TextHorizontalMode.TextLeft; text1_secret.Height = D6; text1_secret.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4); text1_secret.Layer = layername; text1_secret.TextStyleId = ht; double s_x = RT.X - (text1_secret.Bounds.Value.MaxPoint.X - text1_secret.Bounds.Value.MinPoint.X) - D1; double s_y = LT.Y + D22 + D2 + D10; text1_secret.Position = new Point3d(s_x, s_y, 0); text1_secret.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text1_secret); traction.AddNewlyCreatedDBObject(text1_secret, true); } for (int i = 0; i < RLnote.Count; i++) { yy = yy - D6; DBText text1_fz = new DBText(); text1_fz.TextString = RLnote[i]; text1_fz.Position = new Point3d(xx, yy, 0); text1_fz.Height = D6; text1_fz.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4); text1_fz.Layer = layername; text1_fz.TextStyleId = HZ; text1_fz.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text1_fz); traction.AddNewlyCreatedDBObject(text1_fz, true); yy = yy - D4; } //比例尺 xx = (RB.X - LB.X) / 2 + LB.X; yy = LB.Y - D22 - D2 - D10 - D8; DBText text2_blc = new DBText(); text2_blc.TextString = "1:" + BLC; text2_blc.Position = new Point3d(xx, yy, 0); text2_blc.Height = D8; text2_blc.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 2); text2_blc.Layer = layername; text2_blc.HorizontalMode = TextHorizontalMode.TextCenter; text2_blc.AlignmentPoint = new Point3d(xx, yy, 0); text2_blc.TextStyleId = st; text2_blc.WidthFactor = 0.75; text2_blc.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text2_blc); traction.AddNewlyCreatedDBObject(text2_blc, true); //图幅号 xx = (RB.X - LB.X) / 2 + LB.X; yy = LT.Y + D22 + D2 + D10; DBText text3_tfh = new DBText(); text3_tfh.TextString = "(" + Number.ToString() + ")"; text3_tfh.Position = new Point3d(xx, yy, 0); text3_tfh.Height = D10; text3_tfh.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 2); text3_tfh.Layer = layername; text3_tfh.HorizontalMode = TextHorizontalMode.TextCenter; text3_tfh.AlignmentPoint = new Point3d(xx, yy, 0); text3_tfh.TextStyleId = HZ; text3_tfh.WidthFactor = 0.8; text3_tfh.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text3_tfh); traction.AddNewlyCreatedDBObject(text3_tfh, true); //图名 xx = (RB.X - LB.X) / 2 + LB.X; yy = LT.Y + D22 + D2 + D10 + D10 + D6; DBText text4_tm = new DBText(); text4_tm.TextString = TKInfo.name; text4_tm.Position = new Point3d(xx, yy, 0); text4_tm.Height = D10; text4_tm.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 6); text4_tm.Layer = layername; text4_tm.HorizontalMode = TextHorizontalMode.TextCenter; text4_tm.AlignmentPoint = new Point3d(xx, yy, 0); text4_tm.TextStyleId = ht; text4_tm.WidthFactor = 1; text4_tm.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text4_tm); traction.AddNewlyCreatedDBObject(text4_tm, true); //图名后的日期 //string Time_str = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00"); ////左括号 //string tem_str = text4_tm.TextString; //xx = (RB.X - LB.X) / 2 + LB.X + tem_str.Length / 2.0 * (D12); //yy = LT.Y + D22 + D2 + D10 + D10 + D6; //DBText text_F = new DBText(); //string black = ""; //for (int i = 0; i < D12; i++) //{ // black += " "; //} //text_F.TextString = "(" + Time_str + ")"; //text_F.Position = new Point3d(xx, yy, 0); //text_F.Height = D12; //text_F.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 2); //text_F.Layer = layername; //text_F.HorizontalMode = TextHorizontalMode.TextLeft; ////text_F.TextStyleId = ID12; //text_F.TextStyleId = ht; //text_F.SetDatabaseDefaults(); //blocktablerecord.AppendEntity(text_F); //traction.AddNewlyCreatedDBObject(text_F, true); //日期 //xx = xx + D1; //yy = LT.Y + D22 + D2 + D10 + D10 + D6; //DBText text_T = new DBText(); //text_T.TextString = Time_str; //text_T.Position = new Point3d(xx, yy, 0); //text_T.Height = D12; //text_T.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 2); //text_T.Layer = layername; //text_T.HorizontalMode = TextHorizontalMode.TextLeft; //text_T.TextStyleId = ht; //text_T.SetDatabaseDefaults(); //blocktablerecord.AppendEntity(text_T); //traction.AddNewlyCreatedDBObject(text_T, true); //左下附注 string notes = TKInfo.note; char[] ch = new char[] { '\r', '\n' }; string[] strs = notes.Split(ch); xx = LB.X; yy = LB.Y - D22 - D2 - D6; for (int i = 0; i < strs.Length; i++) { xx = LB.X; yy = yy - D6; if (i == strs.Length - 3) { string[] str1 = strs[i].Split(' '); DBText text_fz1 = new DBText(); text_fz1.TextString = str1[0]; text_fz1.Position = new Point3d(xx, yy, 0); text_fz1.Height = D6; text_fz1.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4); text_fz1.Layer = layername; text_fz1.TextStyleId = HZ; text_fz1.WidthFactor = 0.8; text_fz1.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text_fz1); traction.AddNewlyCreatedDBObject(text_fz1, true); xx = xx + D140 / 2 + D2; DBText text_fz2 = new DBText(); text_fz2.TextString = str1[1] + " " + str1[2]; text_fz2.Position = new Point3d(xx, yy, 0); text_fz2.Height = D6; text_fz2.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4); text_fz2.Layer = layername; text_fz2.TextStyleId = HZ; text_fz2.WidthFactor = 1; text_fz2.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text_fz2); traction.AddNewlyCreatedDBObject(text_fz2, true); yy = yy - D4; continue; } else if (i == strs.Length - 2) { string[] str2 = strs[i].Split(' '); DBText text_1 = new DBText(); text_1.TextString = str2[0]+" "+ str2[1] + " "+ str2[2]; text_1.Position = new Point3d(xx, yy, 0); text_1.Height = D6; text_1.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4); text_1.Layer = layername; text_1.TextStyleId = HZ; text_1.WidthFactor = 0.8; text_1.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text_1); traction.AddNewlyCreatedDBObject(text_1, true); xx = xx + D90; DBText text_2 = new DBText(); text_2.TextString = str2[3]; text_2.Position = new Point3d(xx, yy, 0); text_2.Height = D6; text_2.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4); text_2.Layer = layername; text_2.TextStyleId = HZ; text_2.WidthFactor = 1; text_2.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text_2); traction.AddNewlyCreatedDBObject(text_2, true); yy = yy - D4; continue; } DBText text5 = new DBText(); text5.TextString = strs[i]; text5.Position = new Point3d(xx, yy, 0); text5.Height = D6; text5.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4); text5.Layer = layername; text5.TextStyleId = HZ; text5.WidthFactor = 1; text5.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text5); traction.AddNewlyCreatedDBObject(text5, true); yy = yy - D4; } //公司名称 string Company = "四川中水成勘院测绘工程有限责任公司"; xx = LB.X - D22 - D2 - D6 - D8; yy = LB.Y; for (int i = Company.Length - 1; i >= 0; i--) { DBText text6_gs = new DBText(); text6_gs.TextString = Company[i].ToString(); text6_gs.Position = new Point3d(xx, yy, 0); text6_gs.Height = D8; text6_gs.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 2); text6_gs.Layer = layername; text6_gs.TextStyleId = HZ; text6_gs.WidthFactor = 1; text6_gs.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text6_gs); traction.AddNewlyCreatedDBObject(text6_gs, true); yy = yy + D8 + D2; } //接图表 //接图表左下角坐标 xx = LT.X; yy = LT.Y + D22 + D2 + D6; for (int i = 0; i < 2; i++) { Point3dCollection Lcoll = new Point3dCollection(); Lcoll.Add(new Point3d(xx, yy + D48, 0)); Lcoll.Add(new Point3d(xx, yy, 0)); Polyline2d JTB = new Polyline2d(Poly2dType.SimplePoly, Lcoll, 0, true, 0, 0, null); JTB.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); JTB.Layer = layername; JTB.SetDatabaseDefaults(); blocktablerecord.AppendEntity(JTB); traction.AddNewlyCreatedDBObject(JTB, true); xx = xx + D90; } xx = LT.X; yy = LT.Y + D22 + D2 + D6; for (int i = 0; i < 4; i++) { Point3dCollection Lcoll = new Point3dCollection(); Lcoll.Add(new Point3d(xx, yy, 0)); Lcoll.Add(new Point3d(xx + D90, yy, 0)); Polyline2d JTB = new Polyline2d(Poly2dType.SimplePoly, Lcoll, 0, true, 0, 0, null); JTB.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); JTB.Layer = layername; JTB.SetDatabaseDefaults(); blocktablerecord.AppendEntity(JTB); traction.AddNewlyCreatedDBObject(JTB, true); yy = yy + D48 / 3; } xx = LT.X; yy = LT.Y + D22 + D2 + D6; for (int i = 0; i < 2; i++) { Point3dCollection Lcoll = new Point3dCollection(); //Lcoll.Add(new Point3d(xx + D90 / 3, yy + D48 / 3, 0)); Lcoll.Add(new Point3d(xx + D90 / 3, yy, 0)); //Lcoll.Add(new Point3d(xx + D90 / 3, yy + D48 / 3 * 2, 0)); Lcoll.Add(new Point3d(xx + D90 / 3, yy + D48, 0)); Polyline2d JTB = new Polyline2d(Poly2dType.SimplePoly, Lcoll, 0, true, 0, 0, null); JTB.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); JTB.Layer = layername; JTB.SetDatabaseDefaults(); blocktablerecord.AppendEntity(JTB); traction.AddNewlyCreatedDBObject(JTB, true); xx = xx + D90 / 3; } //接图表填充 //接图表左上角坐标 xx = LT.X + D90 / 3; yy = LT.Y + D22 + D2 + D6 + (D48 / 3) * 2; Point3dCollection coll = new Point3dCollection(); coll.Add(new Point3d(xx, yy, 0)); coll.Add(new Point3d(xx, yy - D48 / 3, 0)); coll.Add(new Point3d(xx + D90 / 3, yy - D48 / 3, 0)); coll.Add(new Point3d(xx + D90 / 3, yy, 0)); coll.Add(new Point3d(xx, yy, 0)); Polyline2d line2d = new Polyline2d(Poly2dType.SimplePoly, coll, 0, false, 0, 0, null); xx = xx + dist1; for (int i = 0; i < 30; i++) { Line l = new Line(); l.StartPoint = new Point3d(xx + 90, yy + 90, 0); l.EndPoint = new Point3d(xx - 90, yy - 90, 0); Point3dCollection IP = new Point3dCollection(); l.IntersectWith(line2d, Intersect.ExtendThis, IP, IntPtr.Zero, IntPtr.Zero); Polyline2d FillLine = new Polyline2d(Poly2dType.SimplePoly, IP, 0, false, 0, 0, null); FillLine.Layer = layername; FillLine.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1); FillLine.SetDatabaseDefaults(); blocktablerecord.AppendEntity(FillLine); traction.AddNewlyCreatedDBObject(FillLine, true); xx = xx + Math.Sqrt(dist2); } //接图表中间行——左 if (string.IsNullOrEmpty(Left_Number) == false) { //接图表左下角坐标 xx1 = LT.X; yy1 = LT.Y + D22 + D2 + D6; xx2 = xx1 + D90 / 3 / 2; yy2 = yy1 + D48 / 3 * 1.5; DBText text_L = new DBText(); text_L.TextString = Left_Number; text_L.Position = new Point3d(xx2, yy2, 0); text_L.Height = D5; text_L.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4); text_L.Layer = layername; text_L.TextStyleId = HZ; text_L.HorizontalMode = TextHorizontalMode.TextCenter; text_L.VerticalMode = TextVerticalMode.TextVerticalMid; text_L.AlignmentPoint = new Point3d(xx2, yy2, 0); text_L.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text_L); traction.AddNewlyCreatedDBObject(text_L, true); } //接图表中间行——右 if (string.IsNullOrEmpty(Right_Number) == false) { //接图表左下角坐标 xx1 = LT.X; yy1 = LT.Y + D22 + D2 + D6; xx2 = xx1 + D90 / 3 * 2.5; yy2 = yy1 + D48 / 3 * 1.5; DBText text_R = new DBText(); text_R.TextString = Right_Number; text_R.Position = new Point3d(xx2, yy2, 0); text_R.Height = D5; text_R.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4); text_R.Layer = layername; text_R.TextStyleId = HZ; text_R.HorizontalMode = TextHorizontalMode.TextCenter; text_R.VerticalMode = TextVerticalMode.TextVerticalMid; text_R.AlignmentPoint = new Point3d(xx2, yy2, 0); text_R.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text_R); traction.AddNewlyCreatedDBObject(text_R, true); } //接图表首行——左 if (string.IsNullOrEmpty(Leftup_Number) == false) { xx1 = LT.X; yy1 = LT.Y + D22 + D2 + D6; xx2 = xx1 + D90 / 3 / 2; yy2 = yy1 + D48 / 3 * 2.5; filjtb(Leftup_Number,traction, HZ, blocktablerecord, xx2, yy2, D5); } //接图表首行——中 if (string.IsNullOrEmpty(Centrolup_Number) == false) { xx1 = LT.X; yy1 = LT.Y + D22 + D2 + D6; xx2 = xx1 + D90 / 3 * 1.5; yy2 = yy1 + D48 / 3 * 2.5; filjtb(Centrolup_Number,traction, HZ, blocktablerecord, xx2, yy2, D5); } //接图表首行——右 if (string.IsNullOrEmpty(Rightup_Number) == false) { xx1 = LT.X; yy1 = LT.Y + D22 + D2 + D6; xx2 = xx1 + D90 / 3 * 2.5; yy2 = yy1 + D48 / 3 * 2.5; filjtb(Rightup_Number,traction, HZ, blocktablerecord, xx2, yy2, D5); } //接图表尾行——左 if (string.IsNullOrEmpty(Leftdown_Number) == false) { xx1 = LT.X; yy1 = LT.Y + D22 + D2 + D6; xx2 = xx1 + D90 / 3 / 2; yy2 = yy1 + D48 / 3 / 2; filjtb(Leftdown_Number,traction, HZ, blocktablerecord, xx2, yy2, D5); } //接图表尾行——中 if (string.IsNullOrEmpty(Centroldown_Number) == false) { xx1 = LT.X; yy1 = LT.Y + D22 + D2 + D6; xx2 = xx1 + D90 / 3 * 1.5; yy2 = yy1 + D48 / 3 / 2; filjtb(Centroldown_Number,traction, HZ, blocktablerecord, xx2, yy2, D5); } //接图表尾行——右 if (string.IsNullOrEmpty(Rightdown_Number) == false) { xx1 = LT.X; yy1 = LT.Y + D22 + D2 + D6; xx2 = xx1 + D90 / 3 * 2.5; yy2 = yy1 + D48 / 3 / 2; filjtb(Rightdown_Number,traction, HZ, blocktablerecord, xx2, yy2, D5); } ////坐标 //左上 xx = LT.X; yy = LT.Y; //X坐标 xx1 = xx - D4_8 * 0.75 * 2 - D1; yy1 = yy + D22 - D7; DBText text7 = new DBText(); string value7 = (xx / 1000.0 % 100).ToString("F1"); if (value7.Length == 3) { value7 = "0" + value7; } text7.TextString = value7; text7.Position = new Point3d(xx1, yy1, 0); text7.Height = D4_8; text7.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text7.Layer = layername; text7.TextStyleId = HZ; text7.WidthFactor = 0.75; text7.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text7); traction.AddNewlyCreatedDBObject(text7, true); //带号 xx1 = xx - D4_8 * 0.75 * 2 - D3 * 0.75 * 3 - D2; yy1 = yy + D22 - D7 + (D4_8 - D3); if (TKInfo.DH != -1) { DH = TKInfo.DH * 10 + (int)xx / 1000 / 100; } else { DH = (int)xx / 1000 / 100; } DBText text8 = new DBText(); text8.TextString = DH.ToString(); text8.Position = new Point3d(xx1, yy1, 0); text8.Height = D3; text8.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text8.Layer = layername; text8.HorizontalMode = TextHorizontalMode.TextRight; text8.VerticalMode = TextVerticalMode.TextTop; xx2 = xx - D4_8 * 0.75 * 2 - D2; yy2 = yy + D22 - D7 + D4_8; text8.AlignmentPoint = new Point3d(xx2, yy2, 0); text8.TextStyleId = HZ; text8.WidthFactor = 0.75; text8.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text8); traction.AddNewlyCreatedDBObject(text8, true); //Y坐标下标 xx1 = xx - D4_8 * 0.75 * 4 - D1; yy1 = yy + D2; DBText text9 = new DBText(); string value9 = (yy / 1000.0 % 100).ToString("F1"); if (value9.Length == 3) { value9 = "0" + value9; } text9.TextString = value9; text9.Position = new Point3d(xx1, yy1, 0); text9.Height = D4_8; text9.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text9.Layer = layername; text9.TextStyleId = HZ; text9.WidthFactor = 0.75; text9.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text9); traction.AddNewlyCreatedDBObject(text9, true); //Y坐标上标 xx1 = xx - D4_8 * 0.75 * 4 - D1; yy1 = yy + D2 + D4_8 - D3; DBText text10 = new DBText(); int value10 = (int)(yy / 1000 / 100); text10.TextString = value10.ToString(); text10.Position = new Point3d(xx1, yy1, 0); text10.Height = D3; text10.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text10.Layer = layername; text10.HorizontalMode = TextHorizontalMode.TextRight; text10.VerticalMode = TextVerticalMode.TextTop; xx2 = xx - D4_8 * 0.75 * 4 - D1; yy2 = yy + D2 + D4_8; text10.AlignmentPoint = new Point3d(xx2, yy2, 0); text10.TextStyleId = HZ; text10.WidthFactor = 0.75; text10.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text10); traction.AddNewlyCreatedDBObject(text10, true); //左下 xx = LB.X; yy = LB.Y; //X坐标 xx1 = xx - D4_8 * 0.75 * 2 - D1; yy1 = yy - D22 + D2; DBText text11 = new DBText(); string value11 = (xx / 1000.0 % 100).ToString("F1"); if (value11.Length == 3) { value11 = "0" + value11; } text11.TextString = value11; text11.Position = new Point3d(xx1, yy1, 0); text11.Height = D4_8; text11.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text11.Layer = layername; text11.TextStyleId = HZ; text11.WidthFactor = 0.75; text11.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text11); traction.AddNewlyCreatedDBObject(text11, true); //带号 xx1 = xx - D4_8 * 0.75 * 2 - D3 * 0.75 * 3 - D2; yy1 = yy - D22 + D7 - (D4_8 - D3); if (TKInfo.DH != -1) { DH = TKInfo.DH * 10 + (int)xx / 1000 / 100; } else { DH = (int)xx / 1000 / 100; } DBText text12 = new DBText(); text12.TextString = DH.ToString(); text12.Position = new Point3d(xx1, yy1, 0); text12.Height = D3; text12.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text12.Layer = layername; text12.HorizontalMode = TextHorizontalMode.TextRight; text12.VerticalMode = TextVerticalMode.TextTop; xx2 = xx - D4_8 * 0.75 * 2 - D2; yy2 = yy - D22 + D7; text12.AlignmentPoint = new Point3d(xx2, yy2, 0); text12.TextStyleId = HZ; text12.WidthFactor = 0.75; text12.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text12); traction.AddNewlyCreatedDBObject(text12, true); //Y坐标 xx1 = xx - D4_8 * 0.75 * 4 - D1; yy1 = yy + D2; DBText text13 = new DBText(); string value13 = (yy / 1000.0 % 100).ToString("F1"); if (value13.Length == 3) { value13 = "0" + value13; } text13.TextString = value13; text13.Position = new Point3d(xx1, yy1, 0); text13.Height = D4_8; text13.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text13.Layer = layername; text13.TextStyleId = HZ; text13.WidthFactor = 0.75; text13.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text13); traction.AddNewlyCreatedDBObject(text13, true); //Y坐标上标 xx1 = xx - D4_8 * 0.75 * 4 - D1; yy1 = yy + D2 + D4_8 - D3; DBText text14 = new DBText(); int value14 = (int)(LB.Y / 1000 / 100); text14.TextString = value14.ToString(); text14.Position = new Point3d(xx1, yy1, 0); text14.Height = D3; text14.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text14.Layer = layername; text14.HorizontalMode = TextHorizontalMode.TextRight; text14.VerticalMode = TextVerticalMode.TextTop; xx2 = xx - D4_8 * 0.75 * 4 - D1; yy2 = yy + D2 + D4_8; text14.AlignmentPoint = new Point3d(xx2, yy2, 0); text14.TextStyleId = HZ; text14.WidthFactor = 0.75; text14.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text14); traction.AddNewlyCreatedDBObject(text14, true); //右上 xx = RT.X; yy = RT.Y; //X坐标 xx1 = xx - D4_8 * 0.75 * 2 - D1; yy1 = yy + D22 - D7; DBText text15 = new DBText(); string value15 = (RT.X / 1000.0 % 100).ToString("F1"); if (value15.Length == 3) { value15 = "0" + value15; } text15.TextString = value15; text15.Position = new Point3d(xx1, yy1, 0); text15.Height = D4_8; text15.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text15.Layer = layername; text15.TextStyleId = HZ; text15.WidthFactor = 0.75; text15.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text15); traction.AddNewlyCreatedDBObject(text15, true); //带号 xx1 = xx - D4_8 * 0.75 * 2 - D3 * 0.75 * 3 - D2; yy1 = yy + D22 - D7 + (D4_8 - D3); if (TKInfo.DH != -1) { DH = TKInfo.DH * 10 + (int)RT.X / 1000 / 100; } else { DH = (int)RT.X / 1000 / 100; } DBText text16 = new DBText(); text16.TextString = DH.ToString(); text16.Position = new Point3d(xx1, yy1, 0); text16.Height = D3; text16.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text16.Layer = layername; text16.HorizontalMode = TextHorizontalMode.TextRight; text16.VerticalMode = TextVerticalMode.TextTop; xx2 = xx - D4_8 * 0.75 * 2 - D2; yy2 = yy + D22 - D7 + D4_8; text16.AlignmentPoint = new Point3d(xx2, yy2, 0); text16.TextStyleId = HZ; text16.WidthFactor = 0.75; text16.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text16); traction.AddNewlyCreatedDBObject(text16, true); //Y坐标 xx1 = xx + D7; yy1 = yy + D2; DBText text17 = new DBText(); string value17 = (RT.Y / 1000.0 % 100).ToString("F1"); if (value17.Length == 3) { value17 = "0" + value17; } text17.TextString = value17; text17.Position = new Point3d(xx1, yy1, 0); text17.Height = D4_8; text17.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text17.Layer = layername; text17.TextStyleId = HZ; text17.WidthFactor = 0.75; text17.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text17); traction.AddNewlyCreatedDBObject(text17, true); //Y坐标上标 xx1 = xx + D7; yy1 = yy + D2 + D4_8 - D3; DBText text18 = new DBText(); int value18 = (int)(RT.Y / 1000 / 100); text18.TextString = value18.ToString(); text18.Position = new Point3d(xx1, yy1, 0); text18.Height = D3; text18.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text18.Layer = layername; text18.HorizontalMode = TextHorizontalMode.TextRight; text18.VerticalMode = TextVerticalMode.TextTop; xx2 = xx + D7; yy2 = yy + D2 + D4_8; text18.AlignmentPoint = new Point3d(xx2, yy2, 0); text18.TextStyleId = HZ; text18.WidthFactor = 0.75; text18.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text18); traction.AddNewlyCreatedDBObject(text18, true); //右下 xx = RB.X; yy = RB.Y; //X坐标 xx1 = xx - D4_8 * 0.75 * 2 - D1; yy1 = yy - D22 + D2; DBText text19 = new DBText(); string value19 = (RB.X / 1000.0 % 100).ToString("F1"); if (value19.Length == 3) { value19 = "0" + value19; } text19.TextString = value19; text19.Position = new Point3d(xx1, yy1, 0); text19.Height = D4_8; text19.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text19.Layer = layername; text19.TextStyleId = HZ; text19.WidthFactor = 0.75; text19.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text19); traction.AddNewlyCreatedDBObject(text19, true); //带号 xx1 = xx - D4_8 * 0.75 * 2 - D3 * 0.75 * 3 - D2; yy1 = yy - D22 + D7 - D3; if (TKInfo.DH != -1) { DH = TKInfo.DH * 10 + (int)RT.X / 1000 / 100; } else { DH = (int)RT.X / 1000 / 100; } DBText text20 = new DBText(); text20.TextString = DH.ToString(); text20.Position = new Point3d(xx1, yy1, 0); text20.Height = D3; text20.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text20.Layer = layername; text20.HorizontalMode = TextHorizontalMode.TextRight; text20.VerticalMode = TextVerticalMode.TextTop; xx2 = xx - D4_8 * 0.75 * 2 - D2; yy2 = yy - D22 + D7; text20.AlignmentPoint = new Point3d(xx2, yy2, 0); text20.TextStyleId = HZ; text20.WidthFactor = 0.75; text20.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text20); traction.AddNewlyCreatedDBObject(text20, true); //Y坐标 xx1 = xx + D7; yy1 = yy + D2; DBText text21 = new DBText(); string value21 = (RB.Y / 1000.0 % 100).ToString("F1"); if (value21.Length == 3) { value21 = "0" + value21; } text21.TextString = value21; text21.Position = new Point3d(xx1, yy1, 0); text21.Height = D4_8; text21.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text21.Layer = layername; text21.TextStyleId = HZ; text21.WidthFactor = 0.75; text21.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text21); traction.AddNewlyCreatedDBObject(text21, true); //Y坐标上标 xx1 = xx + D7; yy1 = yy + D2 + D4_8 - D3; DBText text22 = new DBText(); int value22 = (int)(RB.Y / 1000 / 100); text22.TextString = value18.ToString(); text22.Position = new Point3d(xx1, yy1, 0); text22.Height = D3; text22.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3); text22.Layer = layername; text22.HorizontalMode = TextHorizontalMode.TextRight; text22.VerticalMode = TextVerticalMode.TextTop; xx2 = xx + D7; yy2 = yy + D2 + D4_8; text22.AlignmentPoint = new Point3d(xx2, yy2, 0); text22.TextStyleId = HZ; text22.WidthFactor = 0.75; text22.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text22); traction.AddNewlyCreatedDBObject(text22, true); document.Database.SaveAs(TKInfo.SV + "\\" + Number.ToString() + ".dwg", true, DwgVersion.AC1021, document.Database.SecurityParameters); //database.SaveAs(TKInfo.SV + "\\" + Number.ToString() + ".dwg", DwgVersion.AC1024); traction.Commit(); //} //catch (GrxCAD.Runtime.Exception e) //{ // MessageBox.Show (e.Message); //} //finally //{ traction.Dispose(); documentlock.Dispose(); //} } public void createTextStyle() { Database database = HostApplicationServices.WorkingDatabase; Transaction traction = database.TransactionManager.StartTransaction(); DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); TextStyleTable styletable = traction.GetObject(database.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable; string stylename = "ht"; if (styletable.Has(stylename) == false) { TextStyleTableRecord R1 = new TextStyleTableRecord(); R1.Name = stylename; //R1.FileName = "方正细等线简体"; R1.FileName = "SIMHEI.TTF"; //record.BigFontFileName = "hztxt.shx"; R1.ObliquingAngle = 0; R1.XScale = 1; ObjectId textstyleID = styletable.Add(R1); traction.AddNewlyCreatedDBObject(R1, true); //database.TextStyleId = textstyleID; } stylename = "HZ"; if (styletable.Has(stylename) == false) { TextStyleTableRecord R1 = new TextStyleTableRecord(); R1.Name = stylename; //R1.FileName = "方正细等线简体"; R1.FileName = "rs.shx"; R1.BigFontFileName = "hztxt.shx"; R1.ObliquingAngle = 0; R1.XScale = 0.75; ObjectId textstyleID = styletable.Add(R1); traction.AddNewlyCreatedDBObject(R1, true); //database.TextStyleId = textstyleID; } stylename = "st"; if (styletable.Has(stylename) == false) { TextStyleTableRecord R1 = new TextStyleTableRecord(); R1.Name = stylename; //R1.FileName = "方正细等线简体"; R1.FileName = "STSONG.TTF"; //R1.BigFontFileName = "hztxt.shx"; R1.ObliquingAngle = 0; R1.XScale = 1; ObjectId textstyleID = styletable.Add(R1); traction.AddNewlyCreatedDBObject(R1, true); //database.TextStyleId = textstyleID; } stylename = "Standard"; if (styletable.Has(stylename) == false) { TextStyleTableRecord R1 = new TextStyleTableRecord(); R1.Name = stylename; //R1.FileName = "方正细等线简体"; R1.FileName = "rs.shx"; R1.BigFontFileName = "hztxt.shx"; R1.ObliquingAngle = 0; R1.XScale = 0.75; ObjectId textstyleID = styletable.Add(R1); traction.AddNewlyCreatedDBObject(R1, true); //database.TextStyleId = textstyleID; } stylename = "123"; if (styletable.Has(stylename) == false) { TextStyleTableRecord R1 = new TextStyleTableRecord(); R1.Name = stylename; //R1.FileName = "方正细等线简体"; R1.FileName = "SIMHEI.TTF"; //R1.BigFontFileName = "hztxt.shx"; R1.ObliquingAngle = 0; R1.XScale = 0.75; ObjectId textstyleID = styletable.Add(R1); traction.AddNewlyCreatedDBObject(R1, true); //database.TextStyleId = textstyleID; } stylename = "12"; if (styletable.Has(stylename) == false) { TextStyleTableRecord R1 = new TextStyleTableRecord(); R1.Name = stylename; //R1.FileName = "方正细等线简体"; R1.FileName = "complex.shx"; //R1.BigFontFileName = "hztxt.shx"; R1.ObliquingAngle = 0; R1.XScale = 0.75; ObjectId textstyleID = styletable.Add(R1); traction.AddNewlyCreatedDBObject(R1, true); //database.TextStyleId = textstyleID; } stylename = "细等线体"; if (styletable.Has(stylename) == false) { TextStyleTableRecord R1 = new TextStyleTableRecord(); R1.Name = stylename; //R1.FileName = "方正细等线简体"; R1.FileName = "FZXDXJW.TTF"; //record.BigFontFileName = "hztxt.shx"; R1.ObliquingAngle = 0; R1.XScale = 1; ObjectId textstyleID = styletable.Add(R1); traction.AddNewlyCreatedDBObject(R1, true); //database.TextStyleId = textstyleID; } stylename = "中等线体"; if (styletable.Has(stylename) == false) { TextStyleTableRecord R2 = new TextStyleTableRecord(); R2.Name = stylename; //R2.FileName = "方正中等线简体"; R2.FileName = "FZZDXJW.TTF"; //record.BigFontFileName = "hztxt.shx"; R2.ObliquingAngle = 0; R2.XScale = 1; ObjectId textstyleID = styletable.Add(R2); traction.AddNewlyCreatedDBObject(R2, true); //database.TextStyleId = textstyleID; } stylename = "宋体"; if (styletable.Has(stylename) == false) { TextStyleTableRecord R3 = new TextStyleTableRecord(); R3.Name = stylename; //R3.FileName = "华文宋体"; R3.FileName = "STSONG.TTF"; //record.BigFontFileName = "hztxt.shx"; R3.ObliquingAngle = 0; R3.XScale = 1; ObjectId textstyleID = styletable.Add(R3); traction.AddNewlyCreatedDBObject(R3, true); //database.TextStyleId = textstyleID; } traction.Commit(); documentlock.Dispose(); } public ObjectId gettextstyleID(string Name) { Database database = HostApplicationServices.WorkingDatabase; Transaction traction = database.TransactionManager.StartTransaction(); DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); TextStyleTable styletable = traction.GetObject(database.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable; //BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace], // OpenMode.ForWrite) as BlockTableRecord; TextStyleTableRecord record = traction.GetObject(styletable[Name], OpenMode.ForRead) as TextStyleTableRecord; ObjectId ID = record.ObjectId; traction.Commit(); documentlock.Dispose(); return ID; } private void zoom() { Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database database = HostApplicationServices.WorkingDatabase; Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; using (Transaction traction = database.TransactionManager.StartTransaction()) { //删除坐标原点多段线 Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; Point3d pt1 = new Point3d(-1, 1, 0); Point3d pt2 = new Point3d(0, 0, 0); PromptSelectionResult psr = ed.SelectCrossingWindow(pt1, pt2); if (psr.Status == PromptStatus.OK) { SelectionSet sSet = psr.Value; ObjectId[] ids = sSet.GetObjectIds(); foreach (ObjectId id in ids) { Entity entity1 = traction.GetObject(id, OpenMode.ForWrite) as Entity; entity1.Erase(); } } ViewTableRecord currview = editor.GetCurrentView(); currview.CenterPoint = new Point2d((RT.X - LT.X) / 2 + LT.X, (LT.Y - LB.Y) / 2 + LB.Y); currview.ViewDirection = new Vector3d(0, 0, 1); currview.Width = RT.X - LT.X + TKInfo.BLC / 10; currview.Height = LT.Y - LB.Y + TKInfo.BLC / 10; editor.SetCurrentView(currview); traction.Commit(); } } private string GetNumber(Point3d p1, Point3d p2) { string TValue = ""; Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database database = HostApplicationServices.WorkingDatabase; using (Transaction traction = database.TransactionManager.StartTransaction()) { DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument(); BlockTable blocktable = traction.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable; Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; TypedValue[] typed = new TypedValue[1]; typed.SetValue(new TypedValue((int)DxfCode.Start, "Polyline,LWPolyline"), 0); SelectionFilter filter = new SelectionFilter(typed); PromptSelectionResult psr = editor.SelectWindow(p1, p2, filter); if (psr.Status == PromptStatus.OK) { SelectionSet selectionset = psr.Value; ObjectId[] obj = new ObjectId[selectionset.Count]; obj = selectionset.GetObjectIds(); for (int i = 0; i < obj.Length; i++) { ObjectId objid = obj[i]; Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead); if (entity is Face) { TypedValue[] typed_T = new TypedValue[1]; typed_T.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0); SelectionFilter filter_T = new SelectionFilter(typed_T); PromptSelectionResult psr_T = editor.SelectWindow(p1, p2, filter_T); if (psr_T.Status == PromptStatus.OK) { SelectionSet set_T = psr_T.Value; ObjectId[] obj_T = new ObjectId[set_T.Count]; obj_T = set_T.GetObjectIds(); for (int j = 0; j < obj_T.Length; j++) { ObjectId id_T = obj_T[i]; Entity entits = (Entity)traction.GetObject(id_T, OpenMode.ForRead); if (entits is DBText) { DBText text = entits as DBText; TValue = text.TextString; break; } } } break; } else if (entity is Polyline) { TypedValue[] typed_T = new TypedValue[1]; typed_T.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0); SelectionFilter filter_T = new SelectionFilter(typed_T); PromptSelectionResult psr_T = editor.SelectWindow(p1, p2, filter_T); if (psr_T.Status == PromptStatus.OK) { SelectionSet set_T = psr_T.Value; ObjectId[] obj_T = new ObjectId[set_T.Count]; obj_T = set_T.GetObjectIds(); for (int j = 0; j < obj_T.Length; j++) { ObjectId id_T = obj_T[i]; Entity entits = (Entity)traction.GetObject(id_T, OpenMode.ForRead); if (entits is DBText) { DBText text = entits as DBText; TValue = text.TextString; break; } } } break; } } } documentlock.Dispose(); traction.Commit(); } return TValue; } private void filjtb(string num,Transaction traction,ObjectId HZ,BlockTableRecord blocktablerecord,double xx2,double yy2,double height) { DBText text_L = new DBText(); text_L.TextString = num; text_L.Position = new Point3d(xx2, yy2, 0); text_L.Height = height; text_L.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4); text_L.Layer = layername; text_L.TextStyleId = HZ; text_L.HorizontalMode = TextHorizontalMode.TextCenter; text_L.VerticalMode = TextVerticalMode.TextVerticalMid; text_L.AlignmentPoint = new Point3d(xx2, yy2, 0); text_L.SetDatabaseDefaults(); blocktablerecord.AppendEntity(text_L); traction.AddNewlyCreatedDBObject(text_L, true); } } }