1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543 |
- using System;
- using System.Collections.Generic;
-
- using System.Text;
-
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.EditorInput;
-
- namespace T_cad
- {
- class Frame5000
- {
- private Point3d LB;
- private Point3d LT;
- private Point3d RB;
- private Point3d RT;
- double dist = 500; //格网间距
-
-
- string Title = "";
- string Left_Number;
- string Right_Number;
-
- public void Produce()
- {
- getinfo();
- //左编号
- 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(LB.X, LB.Y, 0);
- //p2 = new Point3d(RT.X, RT.Y, 0);
- //Number = GetNumber(p1, p2);
-
- //图名
- Title = "";
- p1 = new Point3d(LB.X, LB.Y, 0);
- p2 = new Point3d(RT.X, RT.Y, 0);
- Title = GetNumber(p1, p2);
-
-
- //新建一个dwg
- //string templatePath = "acad.dwt";
- //DocumentCollection documentcoll = Application.DocumentManager;
- //Document document = documentcoll.Add(templatePath);
- //Database database = document.Database;
-
-
-
-
- LayerControl layerscontrol = new LayerControl();
- if (layerscontrol.haslayername("9800") == false)
- {
- colorgb col = new colorgb(255, 0, 0);
- layerscontrol.creatlayer("9800", col);
- }
-
-
-
- createTextStyle();
-
- draw();
-
- zoom();
-
- }
-
-
-
- private void getinfo()
- {
- Document document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
-
-
- Database database = HostApplicationServices.WorkingDatabase;
- Transaction traction = database.TransactionManager.StartTransaction();
- try
- {
-
- DocumentLock documentlock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
-
- BlockTable blocktable = traction.GetObject(database.BlockTableId,
- OpenMode.ForRead) as BlockTable;
-
- Editor editor = Autodesk.AutoCAD.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);
- }
-
-
-
-
- List<double> x_list = new List<double>();
- List<double> y_list = new List<double>();
-
- List<int> flags = new List<int>();
-
-
- for (int ii = 0; ii < 4; ii++)
- {
- x_list.Add(coll[ii].X);
- y_list.Add(coll[ii].Y);
- }
- x_list.Sort();
- y_list.Sort();
-
-
- //右上
- for (int ii = 0; ii < 4; ii++)
- {
- int x1 = (int)coll[ii].X;
- int y1 = (int)coll[ii].Y;
-
- if (x1 == (int)x_list[3] || x1 == (int)x_list[2])
- {
- if (y1 == (int)y_list[3] || y1 == (int)y_list[2])
- {
- RT = coll[ii];
- flags.Add(ii);
-
- if (x1 == (int)x_list[3])
- {
- x_list.RemoveAt(3);
- }
- else
- {
- x_list.RemoveAt(2);
- }
-
-
- if (y1 == (int)y_list[3])
- {
- y_list.RemoveAt(3);
- }
- else
- {
- y_list.RemoveAt(2);
- }
-
-
- break;
- }
- }
-
- }
-
-
- //右下
- for (int ii = 0; ii < 4; ii++)
- {
- int x1 = (int)coll[ii].X;
-
- //
- int y1 = (int)coll[ii].Y;
- //
-
- if (x1 == (int)x_list[2])
- {
-
- if (y1 == (int)y_list[0] || y1 == (int)y_list[1])
- {
- RB = coll[ii];
- flags.Add(ii);
- x_list.RemoveAt(2);
- break;
- }
- }
-
- }
-
- //左上
- for (int ii = 0; ii < 4; ii++)
- {
-
- int y1 = (int)coll[ii].Y;
- //
- int x1 = (int)coll[ii].X;
- //
- if (y1 == (int)y_list[2])
- {
- if (x1 == (int)x_list[0] || x1 == (int)x_list[1])
- {
- LT = coll[ii];
- flags.Add(ii);
- y_list.RemoveAt(2);
- break;
- }
- }
-
- }
-
-
- //左下
- for (int ii = 0; ii < 4; ii++)
- {
- if (flags.Contains(ii) == false)
- {
- LB = coll[ii];
- }
- }
-
-
-
-
-
-
- }
- }
-
- traction.Commit();
- documentlock.Dispose();
- }
- catch (Exception ex)
- {
-
- System.Windows.Forms.MessageBox.Show(ex.ToString());
-
- }
- finally
- {
- traction.Dispose();
- }
-
- }
-
-
-
- private void draw()
- {
-
-
- double D2_5 = 2.5;
-
- double D15 = 15;
- double D20 = 20;
- double D47_5 = 47.5; //内图廓线和外图廓线距离
- double D120 = 120;
- double D225 = 225;
- double D245 = 245; //右下角附注
-
- double dist1 = 4; //接图表第一格填充间距
- double dist2 = 7.071; //接图表填充间距
-
-
-
- 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("宋体");
-
-
-
-
- Document document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database database = HostApplicationServices.WorkingDatabase;
-
- Transaction traction = database.TransactionManager.StartTransaction();
-
- DocumentLock documentlock = Autodesk.AutoCAD.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 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
-
-
- try
- {
-
-
- //内图廓
-
-
- ////左边线
- //Point3dCollection In1 = new Point3dCollection();
- //In1.Add(new Point3d(LT.X, LT.Y, 0));
- //In1.Add(new Point3d(LB.X, LB.Y, 0));
- //Polyline2d LeftLine = new Polyline2d(Poly2dType.SimplePoly, In1, 0, true, 0, 0, null);
- ////LeftLine.Color = Autodesk.AutoCAD.Colors.Color.FromColor(System.Drawing.Color.Red);
- //LeftLine.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
- //LeftLine.Layer = "9800";
-
- //LeftLine.SetDatabaseDefaults();
- //blocktablerecord.AppendEntity(LeftLine);
- //traction.AddNewlyCreatedDBObject(LeftLine, true);
-
- ////下边线
- //Point3dCollection In2 = new Point3dCollection();
- //In2.Add(new Point3d(LB.X, LB.Y, 0));
- //In2.Add(new Point3d(RB.X, RB.Y, 0));
- //Polyline2d LowLine = new Polyline2d(Poly2dType.SimplePoly, In2, 0, true, 0, 0, null);
- //LowLine.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.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, 0));
- //In3.Add(new Point3d(RB.X, RB.Y, 0));
- //Polyline2d RightLine = new Polyline2d(Poly2dType.SimplePoly, In3, 0, true, 0, 0, null);
- //RightLine.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
- //RightLine.Layer = "9800";
-
- //RightLine.SetDatabaseDefaults();
- //blocktablerecord.AppendEntity(RightLine);
- //traction.AddNewlyCreatedDBObject(RightLine, true);
-
- //上边线
- //Point3dCollection In4 = new Point3dCollection();
- //In4.Add(new Point3d(LT.X, LT.Y, 0));
- //In4.Add(new Point3d(RT.X, RT.Y, 0));
- //Polyline2d TOPLine = new Polyline2d(Poly2dType.SimplePoly, In4, 0, true, 0, 0, null);
- //TOPLine.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
- //TOPLine.Layer = "9800";
-
- //TOPLine.SetDatabaseDefaults();
- //blocktablerecord.AppendEntity(TOPLine);
- //traction.AddNewlyCreatedDBObject(TOPLine, true);
-
-
-
-
- //外图廓
- Point3dCollection Outcoll = new Point3dCollection();
- Outcoll.Add(new Point3d(LT.X - D47_5, LT.Y + D47_5, 0));
- Outcoll.Add(new Point3d(LB.X - D47_5, LB.Y - D47_5, 0));
- Outcoll.Add(new Point3d(RB.X + D47_5, RB.Y - D47_5, 0));
- Outcoll.Add(new Point3d(RT.X + D47_5, RT.Y + D47_5, 0));
- Outcoll.Add(new Point3d(LT.X - D47_5, LT.Y + D47_5, 0));
-
- Polyline2d line = new Polyline2d(Poly2dType.SimplePoly, Outcoll, 0, true, D2_5, D2_5, null);
- line.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
- line.Layer = "9800";
-
- line.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(line);
- traction.AddNewlyCreatedDBObject(line, true);
-
-
-
-
- // 下边线
- Point3dCollection coll_B = new Point3dCollection();
- Line ll_B = new Line();
-
- double x1 = LB.X - 100;
- double ks = (RB.Y - LB.Y) / (RB.X - LB.X);
- double y1 = ks * (x1 - LB.X) + LB.Y;
- ll_B.StartPoint = new Point3d(x1, y1, 0);
-
- double x2 = RB.X + 100;
- double y2 = ks * (x2 - LB.X) + LB.Y;
- ll_B.EndPoint = new Point3d(x2, y2, 0);
- ll_B.IntersectWith(line, Intersect.ExtendThis, coll_B, 0, 0);
- Polyline2d Line_B = new Polyline2d(Poly2dType.SimplePoly, coll_B, 0, false, 0, 0, null);
- Line_B.Layer = "9800";
- Line_B.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
-
- Line_B.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(Line_B);
- traction.AddNewlyCreatedDBObject(Line_B, true);
-
- //上边线
- Point3dCollection coll_T = new Point3dCollection();
- Line ll_T = new Line();
-
- x1 = LT.X - 100;
- ks = (RT.Y - LT.Y) / (RT.X - LT.X);
- y1 = ks * (x1 - LT.X) + LT.Y;
- ll_T.StartPoint = new Point3d(x1, y1, 0);
-
- x2 = LT.X + 100;
- y2 = ks * (x2 - LT.X) + LT.Y;
- ll_T.EndPoint = new Point3d(x2, y2, 0);
- ll_T.IntersectWith(line, Intersect.ExtendThis, coll_T, 0, 0);
- Polyline2d Line_T = new Polyline2d(Poly2dType.SimplePoly, coll_T, 0, false, 0, 0, null);
- Line_T.Layer = "9800";
- Line_T.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
-
- Line_T.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(Line_T);
- traction.AddNewlyCreatedDBObject(Line_T, true);
-
-
- //左边线
- Point3dCollection coll_L = new Point3dCollection();
- Line ll_L = new Line();
-
-
- y1 = LB.Y - 100;
- ks = (LT.Y - LB.Y) / (LT.X - LB.X);
- x1 = LB.X + (y1 - LB.Y) / ks;
- ll_L.StartPoint = new Point3d(x1, y1, 0);
-
- y2 = LT.Y + 100;
- x2 = LB.X + (y2 - LB.Y) / ks;
- ll_L.EndPoint = new Point3d(x2, y2, 0);
-
-
- ll_L.IntersectWith(line, Intersect.ExtendThis, coll_L, 0, 0);
- Polyline2d Line_L = new Polyline2d(Poly2dType.SimplePoly, coll_L, 0, false, 0, 0, null);
- Line_L.Layer = "9800";
- Line_L.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
-
- Line_L.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(Line_L);
- traction.AddNewlyCreatedDBObject(Line_L, true);
-
-
- //右边线
- Point3dCollection coll_R = new Point3dCollection();
- Line ll_R = new Line();
-
-
- y1 = RB.Y - 100;
- ks = (RT.Y - RB.Y) / (RT.X - RB.X);
- x1 = RB.X + (y1 - RB.Y) / ks;
- ll_R.StartPoint = new Point3d(x1, y1, 0);
-
- y2 = RT.Y + 100;
- x2 = RB.X + (y2 - RB.Y) / ks;
- ll_R.EndPoint = new Point3d(x2, y2, 0);
-
-
- ll_R.IntersectWith(line, Intersect.ExtendThis, coll_R, 0, 0);
- Polyline2d Line_R = new Polyline2d(Poly2dType.SimplePoly, coll_R, 0, false, 0, 0, null);
- Line_R.Layer = "9800";
- Line_R.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
-
- Line_R.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(Line_R);
- traction.AddNewlyCreatedDBObject(Line_R, true);
-
-
-
-
- //
- //x坐标
- List<double> list_x = new List<double>();
- double x0 = 500 - LB.X % 500;
- x0 = LB.X + x0;
- list_x.Add(x0);
-
- while (x0 + 500 < RB.X)
- {
- x0 = x0 + 500;
- list_x.Add(x0);
- }
-
- //y坐标
- List<double> list_y = new List<double>();
- double y0 = 500 - LB.Y % 500;
- y0 = LB.Y + y0;
- list_y.Add(y0);
-
- while (y0 + 500 < LT.Y)
- {
- y0 = y0 + 500;
- list_y.Add(y0);
- }
- //
-
-
- //十字框标
- for (int i = 0; i < list_x.Count; i++)
- {
- for (int j = 0; j < list_y.Count; j++)
- {
- double x = list_x[i];
- double y = list_y[j];
- Point3d p1 = new Point3d(x - 25, y, 0);
- Point3d p2 = new Point3d(x + 25, 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 = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
- kbline.Layer = "9800";
-
- kbline.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(kbline);
- traction.AddNewlyCreatedDBObject(kbline, true);
-
-
- p1 = new Point3d(x, y - 25, 0);
- p2 = new Point3d(x, y + 25, 0);
- Point3dCollection kb2 = new Point3dCollection();
- kb2.Add(p1);
- kb2.Add(p2);
- Polyline2d kbline2 = new Polyline2d(Poly2dType.SimplePoly, kb2, 0, false, 0, 0, null);
- kbline2.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
- kbline2.Layer = "9800";
-
- kbline2.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(kbline2);
- traction.AddNewlyCreatedDBObject(kbline2, true);
-
- }
-
- }
-
-
- List<Point3d> Below_List = new List<Point3d>();
- List<Point3d> Top_List = new List<Point3d>();
- List<Point3d> Left_List = new List<Point3d>();
- List<Point3d> Right_List = new List<Point3d>();
-
- //上下边线的短线
- for (int i = 0; i < list_x.Count; i++)
- {
- double x = list_x[i];
-
- double k = (RB.Y - LB.Y) / (RB.X - LB.X);
- double y = k * (x - LB.X) + LB.Y;
-
- Point3d p1 = new Point3d(x, y, 0);
- Point3d p2 = new Point3d(x, y - 47.5, 0);
- Point3dCollection pc = new Point3dCollection();
- pc.Add(p1);
- pc.Add(p2);
- Polyline2d Kline = new Polyline2d(Poly2dType.SimplePoly, pc, 0, false, 0, 0, null);
- Kline.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
- Kline.Layer = "9800";
-
- Kline.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(Kline);
- traction.AddNewlyCreatedDBObject(Kline, true);
-
- Below_List.Add(p1);
-
- y = k * (x - LT.X) + LT.Y;
- p1 = new Point3d(x, y, 0);
- p2 = new Point3d(x, y + 47.5, 0);
- pc = new Point3dCollection();
- pc.Add(p1);
- pc.Add(p2);
- Kline = new Polyline2d(Poly2dType.SimplePoly, pc, 0, false, 0, 0, null);
- Kline.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
- Kline.Layer = "9800";
-
- Kline.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(Kline);
- traction.AddNewlyCreatedDBObject(Kline, true);
-
- Top_List.Add(p1);
-
- }
-
- //左右边线的短线
- for (int i = 0; i < list_y.Count; i++)
- {
- double y = list_y[i];
- double k = (LT.Y - LB.Y) / (LT.X - LB.X);
- double x = LB.X + (y - LB.Y) / k;
-
- Point3d p1 = new Point3d(x, y, 0);
- Point3d p2 = new Point3d(x - 47.5, y, 0);
- Point3dCollection pc = new Point3dCollection();
- pc.Add(p1);
- pc.Add(p2);
- Polyline2d Kline = new Polyline2d(Poly2dType.SimplePoly, pc, 0, false, 0, 0, null);
- Kline.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
- Kline.Layer = "9800";
-
- Kline.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(Kline);
- traction.AddNewlyCreatedDBObject(Kline, true);
-
- Left_List.Add(p1);
-
- x = RB.X + (y - RB.Y) / k;
- p1 = new Point3d(x, y, 0);
- p2 = new Point3d(x + 47.5, y, 0);
- pc = new Point3dCollection();
- pc.Add(p1);
- pc.Add(p2);
- Kline = new Polyline2d(Poly2dType.SimplePoly, pc, 0, false, 0, 0, null);
- Kline.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
- Kline.Layer = "9800";
-
- Kline.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(Kline);
- traction.AddNewlyCreatedDBObject(Kline, true);
-
- Right_List.Add(p1);
- }
-
-
-
-
- //下边线坐标
- for (int i = 0; i < Below_List.Count; i++)
- {
- double x = Below_List[i].X;
- double y = Below_List[i].Y;
-
- DBText text7 = new DBText();
- string value7 = (x / 1000.0 % 100).ToString("F1");
- if (value7.Length == 3)
- {
- value7 = "0" + value7;
- }
- text7.TextString = value7;
- text7.Position = new Point3d(x - 22.5, y - 41.25, 0);
- text7.Height = 15;
- text7.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
- text7.Layer = "9800";
- text7.TextStyle = HZ;
- text7.WidthFactor = 0.75;
-
- text7.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text7);
- traction.AddNewlyCreatedDBObject(text7, true);
-
-
- if (i == 0 || i == Below_List.Count - 1)
- {
- DBText text = new DBText();
- string value = "34" + ((int)x / 1000 / 100).ToString();
-
- text.TextString = value;
- text.Position = new Point3d(x - 43, y - 36.25, 0);
- text.Height = 10;
- text.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
- text.Layer = "9800";
- text.TextStyle = HZ;
- text.WidthFactor = 0.75;
-
- text.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text);
- traction.AddNewlyCreatedDBObject(text, true);
- }
-
- }
- //上边线坐标
- for (int i = 0; i < Top_List.Count; i++)
- {
- double x = Top_List[i].X;
- double y = Top_List[i].Y;
-
- DBText text7 = new DBText();
- string value7 = (x / 1000.0 % 100).ToString("F1");
- if (value7.Length == 3)
- {
- value7 = "0" + value7;
- }
- text7.TextString = value7;
- text7.Position = new Point3d(x - 22.5, y + 26.25, 0);
- text7.Height = 15;
- text7.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
- text7.Layer = "9800";
- text7.TextStyle = HZ;
- text7.WidthFactor = 0.75;
-
- text7.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text7);
- traction.AddNewlyCreatedDBObject(text7, true);
-
-
- if (i == 0 || i == Below_List.Count - 1)
- {
- DBText text = new DBText();
- string value = "34" + ((int)x / 1000 / 100).ToString();
-
- text.TextString = value;
- text.Position = new Point3d(x - 43, y + 31.25, 0);
- text.Height = 10;
- text.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
- text.Layer = "9800";
- text.TextStyle = HZ;
- text.WidthFactor = 0.75;
-
- text.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text);
- traction.AddNewlyCreatedDBObject(text, true);
- }
- }
-
- //左边线坐标
- for (int i = 0; i < Left_List.Count; i++)
- {
- double x = Left_List[i].X;
- double y = Left_List[i].Y;
-
- DBText text7 = new DBText();
- string value7 = (y / 1000.0 % 100).ToString("F1");
- if (value7.Length == 3)
- {
- value7 = "0" + value7;
- }
- text7.TextString = value7;
- text7.Position = new Point3d(x - 37.5, y + 5, 0);
- text7.Height = 15;
- text7.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
- text7.Layer = "9800";
- text7.TextStyle = HZ;
- text7.WidthFactor = 0.75;
-
- text7.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text7);
- traction.AddNewlyCreatedDBObject(text7, true);
-
-
- if (i == 0 || i == Left_List.Count - 1)
- {
- DBText text = new DBText();
- string value = ((int)y / 1000 / 100).ToString();
-
- text.TextString = value;
- text.Position = new Point3d(x - 46.5, y + 21, 0);
- text.Height = 10;
- text.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
- text.Layer = "9800";
- text.TextStyle = HZ;
- text.WidthFactor = 0.75;
-
- text.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text);
- traction.AddNewlyCreatedDBObject(text, true);
- }
-
- }
- //右边线坐标
- for (int i = 0; i < Right_List.Count; i++)
- {
- double x = Right_List[i].X;
- double y = Right_List[i].Y;
-
- DBText text7 = new DBText();
- string value7 = (y / 1000.0 % 100).ToString("F1");
- if (value7.Length == 3)
- {
- value7 = "0" + value7;
- }
- text7.TextString = value7;
- text7.Position = new Point3d(x + 8.5, y + 5, 0);
- text7.Height = 15;
- text7.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
- text7.Layer = "9800";
- text7.TextStyle = HZ;
- text7.WidthFactor = 0.75;
-
- text7.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text7);
- traction.AddNewlyCreatedDBObject(text7, true);
-
-
- if (i == 0 || i == Right_List.Count - 1)
- {
- DBText text = new DBText();
- string value = ((int)y / 1000 / 100).ToString();
-
- text.TextString = value;
- text.Position = new Point3d(x, y + 21, 0);
- text.Height = 10;
- text.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
- text.Layer = "9800";
- text.TextStyle = HZ;
- text.WidthFactor = 0.75;
-
- text.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text);
- traction.AddNewlyCreatedDBObject(text, true);
- }
- }
-
-
-
-
-
-
-
-
-
- //右下角附注
- double xx = 0;
- double yy = 0;
- xx = RB.X - D245;
- yy = RB.Y - 78.75;
-
- List<string> RLnote = new List<string>();
- string str = "";
- str = "调查员: 赵永健";
- RLnote.Add(str);
-
- str = "检查员: 葛礼辉";
- RLnote.Add(str);
-
- for (int i = 0; i < RLnote.Count; i++)
- {
-
- DBText text1 = new DBText();
- text1.TextString = RLnote[i];
- text1.Position = new Point3d(xx, yy, 0);
- text1.Height = D15;
- text1.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 4);
- text1.Layer = "9800";
- text1.TextStyle = HZ;
-
- text1.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text1);
- traction.AddNewlyCreatedDBObject(text1, true);
-
- yy = yy - 30;
- }
-
-
-
- //比例尺
- xx = (RB.X - LB.X) / 2 + LB.X;
- yy = LB.Y - 93.75;
-
- DBText text2 = new DBText();
- text2.TextString = "1:5000";
- text2.Position = new Point3d(xx, yy, 0);
- text2.Height = D20;
- text2.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 2);
- text2.Layer = "9800";
- text2.HorizontalMode = TextHorizontalMode.TextCenter;
- text2.AlignmentPoint = new Point3d(xx, yy, 0);
- text2.TextStyle = ID12;
- text2.WidthFactor = 0.75;
-
- text2.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text2);
- traction.AddNewlyCreatedDBObject(text2, true);
-
-
-
-
-
-
-
- //图名
- xx = (RB.X - LB.X) / 2 + LB.X;
- yy = LT.Y + 138.75;
- DBText text4 = new DBText();
- text4.TextString = Title;
- text4.Position = new Point3d(xx, yy, 0);
- text4.Height = 25;
- text4.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 6);
- text4.Layer = "9800";
- text4.HorizontalMode = TextHorizontalMode.TextCenter;
- text4.AlignmentPoint = new Point3d(xx, yy, 0);
- text4.TextStyle = ID123;
- text4.WidthFactor = 1;
-
- text4.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text4);
- traction.AddNewlyCreatedDBObject(text4, true);
-
-
- string[] str_lbtxt = new string[3];
- str_lbtxt[0] = "2012年8月调查。";
- str_lbtxt[1] = "1980西安坐标系。";
- str_lbtxt[2] = "1985国家高程基准。";
-
- xx = LB.X;
- yy = LB.Y - 78.75;
- for (int i = 0; i < 3; i++)
- {
- DBText text_1 = new DBText();
- text_1.TextString = str_lbtxt[i];
- text_1.Position = new Point3d(xx, yy, 0);
- text_1.Height = D15;
- text_1.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 4);
- text_1.Layer = "9800";
- text_1.TextStyle = HZ;
- text_1.WidthFactor = 1;
-
- text_1.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text_1);
- traction.AddNewlyCreatedDBObject(text_1, true);
-
- yy = yy - 30;
- }
-
-
-
-
-
-
- //公司名称
-
- string Company = "四川中水成勘院测绘工程有限责任公司";
- xx = LB.X - 82.75;
- yy = LB.Y;
- for (int i = Company.Length - 1; i >= 0; i--)
- {
- DBText text6 = new DBText();
- text6.TextString = Company[i].ToString();
- text6.Position = new Point3d(xx, yy, 0);
- text6.Height = D20;
- text6.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 2);
- text6.Layer = "9800";
- text6.TextStyle = HZ;
- text6.WidthFactor = 1;
-
- text6.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(text6);
- traction.AddNewlyCreatedDBObject(text6, true);
- yy = yy + 25;
- }
-
-
- //接图表
- //接图表左下角坐标
- xx = LT.X;
- yy = LT.Y + 63.75;
-
- for (int i = 0; i < 4; i++)
- {
- Point3dCollection Lcoll = new Point3dCollection();
- Lcoll.Add(new Point3d(xx, yy + D120, 0));
- Lcoll.Add(new Point3d(xx, yy, 0));
- Polyline2d JTB = new Polyline2d(Poly2dType.SimplePoly, Lcoll, 0, true, 0, 0, null);
- JTB.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
- JTB.Layer = "9800";
-
- JTB.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(JTB);
- traction.AddNewlyCreatedDBObject(JTB, true);
-
- xx = xx + 75;
- }
-
- xx = LT.X;
- yy = LT.Y + 63.75;
- for (int i = 0; i < 4; i++)
- {
- Point3dCollection Lcoll = new Point3dCollection();
- Lcoll.Add(new Point3d(xx, yy, 0));
- Lcoll.Add(new Point3d(xx + D225, yy, 0));
- Polyline2d JTB = new Polyline2d(Poly2dType.SimplePoly, Lcoll, 0, true, 0, 0, null);
- JTB.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
- JTB.Layer = "9800";
-
- JTB.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(JTB);
- traction.AddNewlyCreatedDBObject(JTB, true);
-
- yy = yy + 40;
- }
-
-
-
-
-
-
-
-
- //接图表填充
- //接图表左上角坐标
- xx = LT.X + D225 / 3;
- yy = LT.Y + 63.75 + (D120 / 3) * 2;
- Point3dCollection coll = new Point3dCollection();
- coll.Add(new Point3d(xx, yy, 0));
- coll.Add(new Point3d(xx, yy - D120 / 3, 0));
- coll.Add(new Point3d(xx + D225 / 3, yy - D120 / 3, 0));
- coll.Add(new Point3d(xx + D225 / 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, 0, 0);
- Polyline2d FillLine = new Polyline2d(Poly2dType.SimplePoly, IP, 0, false, 0, 0, null);
- FillLine.Layer = "9800";
- FillLine.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
-
- FillLine.SetDatabaseDefaults();
- blocktablerecord.AppendEntity(FillLine);
- traction.AddNewlyCreatedDBObject(FillLine, true);
-
- xx = xx + dist2;
- }
-
-
-
- Point3d pp1 = new Point3d(LT.X - 3000, LT.Y + 2000, 0);
- Point3d pp2 = LT;
- string str1 = GetNumber(pp1, pp2);
-
- pp1 = LT;
- pp2 = new Point3d(LT.X + 3000, LT.Y + 2000, 0);
- string str2 = GetNumber(pp1, pp2);
-
- pp1 = RT;
- pp2 = new Point3d(RT.X + 3000, RT.Y + 2000, 0);
- string str3 = GetNumber(pp1, pp2);
-
-
- pp1 = LT;
- pp2 = new Point3d(LT.X - 3000, LT.Y - 2000, 0);
- string str4 = GetNumber(pp1, pp2);
-
-
- pp1 = RB;
- pp2 = new Point3d(RB.X + 3000, RB.Y + 2000, 0);
- string str5 = GetNumber(pp1, pp2);
-
-
- pp1 = LB;
- pp2 = new Point3d(LB.X - 3000, LB.Y - 2000, 0);
- string str6 = GetNumber(pp1, pp2);
-
- pp1 = RB;
- pp2 = new Point3d(RB.X - 3000, RB.Y - 2000, 0);
- string str7 = GetNumber(pp1, pp2);
-
-
- pp1 = RB;
- pp2 = new Point3d(RB.X + 3000, RB.Y - 2000, 0);
- string str8 = GetNumber(pp1, pp2);
-
-
- double xx1 = LT.X + 37.5;
- double yy1 = LT.Y + 83.75;
-
- double xx2 = 0;
- double yy2 = 0;
-
- for (int i = 1; i < 9; i++)
- {
- string value = "";
-
- switch (i)
- {
- case 1:
-
- value = str1;
- xx2 = xx1;
- yy2 = yy1 + 80;
- break;
-
- case 2:
- value = str2;
- xx2 = xx1 + 75;
- yy2 = yy1 + 80;
- break;
- case 3:
- value = str3;
- xx2 = xx1 + 150;
- yy2 = yy1 + 80;
- break;
-
- case 4:
- value = str4;
- xx2 = xx1;
- yy2 = yy1 + 40;
- break;
-
- case 5:
- value = str5;
- xx2 = xx1 + 150;
- yy2 = yy1 + 40;
- break;
-
- case 6:
- value = str6;
- xx2 = xx1;
- yy2 = yy1;
- break;
-
- case 7:
- value = str7;
- xx2 = xx1 + 75;
- yy2 = yy1;
- break;
- case 8:
- value = str6;
- xx2 = xx1 + 150;
- yy2 = yy1;
- break;
-
- default:
- break;
- }
-
- if (value != "")
- {
- value = value.Substring(value.Length - 3);
- }
-
-
- DBText text_L = new DBText();
- text_L.TextString = value;
- text_L.Position = new Point3d(xx2, yy2, 0);
- text_L.Height = 12.5;
- text_L.WidthFactor = 0.75;
- text_L.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
- text_L.Layer = "9800";
- text_L.TextStyle = 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(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 = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
- // text_L.Layer = layername;
- // text_L.TextStyle = 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 = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
- // text_R.Layer = layername;
- // text_R.TextStyle = 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);
- //}
-
-
- traction.Commit();
-
- }
- catch (Autodesk.AutoCAD.Runtime.Exception ex)
- {
- System.Windows.Forms.MessageBox.Show(ex.ToString());
- }
- finally
- {
- traction.Dispose();
- documentlock.Dispose();
-
- }
-
- }
-
-
-
-
-
- private void createTextStyle()
- {
- Database database = HostApplicationServices.WorkingDatabase;
-
- Transaction traction = database.TransactionManager.StartTransaction();
-
- DocumentLock documentlock = Autodesk.AutoCAD.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.Textstyle = 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.Textstyle = 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.Textstyle = 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.Textstyle = 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.Textstyle = 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.Textstyle = 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.Textstyle = 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.Textstyle = 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.Textstyle = textstyleID;
- }
-
- traction.Commit();
- documentlock.Dispose();
-
- }
-
-
-
-
- private ObjectId gettextstyleID(string Name)
- {
- Database database = HostApplicationServices.WorkingDatabase;
-
- Transaction traction = database.TransactionManager.StartTransaction();
-
- DocumentLock documentlock = Autodesk.AutoCAD.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 = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database database = HostApplicationServices.WorkingDatabase;
- Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- using (Transaction traction = database.TransactionManager.StartTransaction())
- {
- 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 + 500;
- currview.Height = LT.Y - LB.Y + 500;
- editor.SetCurrentView(currview);
- traction.Commit();
- }
- }
-
-
-
-
- private string GetNumber(Point3d p1, Point3d p2)
- {
- string TValue = "";
-
- Document document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database database = HostApplicationServices.WorkingDatabase;
-
-
- using (Transaction traction = database.TransactionManager.StartTransaction())
- {
- DocumentLock documentlock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
-
- BlockTable blocktable = traction.GetObject(database.BlockTableId,
- OpenMode.ForRead) as BlockTable;
-
- Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- TypedValue[] typed = new TypedValue[1];
- typed.SetValue(new TypedValue((int)DxfCode.Start, "3dFace,LWPolyline,Polyline,Polyline2d"), 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[2];
- typed_T.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0);
- typed_T.SetValue(new TypedValue((int)DxfCode.LayerName, "TREE_LAYER"), 1);
-
- 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[2];
- typed_T.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0);
- typed_T.SetValue(new TypedValue((int)DxfCode.LayerName, "TREE_LAYER"), 1);
-
- 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[j];
- 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;
- }
-
-
-
-
-
-
-
- }
- }
|