工具箱相关
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Frame5000.cs 58KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Autodesk.AutoCAD.Geometry;
  5. using Autodesk.AutoCAD.DatabaseServices;
  6. using Autodesk.AutoCAD.ApplicationServices;
  7. using Autodesk.AutoCAD.EditorInput;
  8. namespace T_cad
  9. {
  10. class Frame5000
  11. {
  12. private Point3d LB;
  13. private Point3d LT;
  14. private Point3d RB;
  15. private Point3d RT;
  16. double dist = 500; //格网间距
  17. string Title = "";
  18. string Left_Number;
  19. string Right_Number;
  20. public void Produce()
  21. {
  22. getinfo();
  23. //左编号
  24. Point3d p1 = new Point3d(LB.X - dist * 5 - 100, LB.Y - 100, 0);
  25. Point3d p2 = new Point3d(LT.X + 50, LT.Y + 50, 0);
  26. Left_Number = GetNumber(p1, p2);
  27. //右编号
  28. p1 = new Point3d(RT.X + dist * 5 + 100, RT.Y + 100, 0);
  29. p2 = new Point3d(RB.X - 50, RB.Y - 50, 0);
  30. Right_Number = GetNumber(p1, p2);
  31. ////图幅号
  32. //p1 = new Point3d(LB.X, LB.Y, 0);
  33. //p2 = new Point3d(RT.X, RT.Y, 0);
  34. //Number = GetNumber(p1, p2);
  35. //图名
  36. Title = "";
  37. p1 = new Point3d(LB.X, LB.Y, 0);
  38. p2 = new Point3d(RT.X, RT.Y, 0);
  39. Title = GetNumber(p1, p2);
  40. //新建一个dwg
  41. //string templatePath = "acad.dwt";
  42. //DocumentCollection documentcoll = Application.DocumentManager;
  43. //Document document = documentcoll.Add(templatePath);
  44. //Database database = document.Database;
  45. LayerControl layerscontrol = new LayerControl();
  46. if (layerscontrol.haslayername("9800") == false)
  47. {
  48. colorgb col = new colorgb(255, 0, 0);
  49. layerscontrol.creatlayer("9800", col);
  50. }
  51. createTextStyle();
  52. draw();
  53. zoom();
  54. }
  55. private void getinfo()
  56. {
  57. Document document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  58. Database database = HostApplicationServices.WorkingDatabase;
  59. Transaction traction = database.TransactionManager.StartTransaction();
  60. try
  61. {
  62. DocumentLock documentlock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  63. BlockTable blocktable = traction.GetObject(database.BlockTableId,
  64. OpenMode.ForRead) as BlockTable;
  65. Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  66. TypedValue[] typedvalue = new TypedValue[1];
  67. typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "3dFace,LWPolyline"), 0);
  68. SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
  69. PromptSelectionResult psr = editor.GetSelection(selectionfilter);
  70. if (psr.Status == PromptStatus.OK)
  71. {
  72. SelectionSet selectionset = psr.Value;
  73. ObjectId[] obj = new ObjectId[selectionset.Count];
  74. obj = selectionset.GetObjectIds();
  75. for (int i = 0; i < obj.Length; i++)
  76. {
  77. ObjectId objid = obj[i];
  78. Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead);
  79. Point3dCollection coll = new Point3dCollection();
  80. if (entity is Face)
  81. {
  82. Face f = entity as Face;
  83. f.GetStretchPoints(coll);
  84. }
  85. else if (entity is Polyline)
  86. {
  87. Polyline line = entity as Polyline;
  88. line.GetStretchPoints(coll);
  89. }
  90. List<double> x_list = new List<double>();
  91. List<double> y_list = new List<double>();
  92. List<int> flags = new List<int>();
  93. for (int ii = 0; ii < 4; ii++)
  94. {
  95. x_list.Add(coll[ii].X);
  96. y_list.Add(coll[ii].Y);
  97. }
  98. x_list.Sort();
  99. y_list.Sort();
  100. //右上
  101. for (int ii = 0; ii < 4; ii++)
  102. {
  103. int x1 = (int)coll[ii].X;
  104. int y1 = (int)coll[ii].Y;
  105. if (x1 == (int)x_list[3] || x1 == (int)x_list[2])
  106. {
  107. if (y1 == (int)y_list[3] || y1 == (int)y_list[2])
  108. {
  109. RT = coll[ii];
  110. flags.Add(ii);
  111. if (x1 == (int)x_list[3])
  112. {
  113. x_list.RemoveAt(3);
  114. }
  115. else
  116. {
  117. x_list.RemoveAt(2);
  118. }
  119. if (y1 == (int)y_list[3])
  120. {
  121. y_list.RemoveAt(3);
  122. }
  123. else
  124. {
  125. y_list.RemoveAt(2);
  126. }
  127. break;
  128. }
  129. }
  130. }
  131. //右下
  132. for (int ii = 0; ii < 4; ii++)
  133. {
  134. int x1 = (int)coll[ii].X;
  135. //
  136. int y1 = (int)coll[ii].Y;
  137. //
  138. if (x1 == (int)x_list[2])
  139. {
  140. if (y1 == (int)y_list[0] || y1 == (int)y_list[1])
  141. {
  142. RB = coll[ii];
  143. flags.Add(ii);
  144. x_list.RemoveAt(2);
  145. break;
  146. }
  147. }
  148. }
  149. //左上
  150. for (int ii = 0; ii < 4; ii++)
  151. {
  152. int y1 = (int)coll[ii].Y;
  153. //
  154. int x1 = (int)coll[ii].X;
  155. //
  156. if (y1 == (int)y_list[2])
  157. {
  158. if (x1 == (int)x_list[0] || x1 == (int)x_list[1])
  159. {
  160. LT = coll[ii];
  161. flags.Add(ii);
  162. y_list.RemoveAt(2);
  163. break;
  164. }
  165. }
  166. }
  167. //左下
  168. for (int ii = 0; ii < 4; ii++)
  169. {
  170. if (flags.Contains(ii) == false)
  171. {
  172. LB = coll[ii];
  173. }
  174. }
  175. }
  176. }
  177. traction.Commit();
  178. documentlock.Dispose();
  179. }
  180. catch (Exception ex)
  181. {
  182. System.Windows.Forms.MessageBox.Show(ex.ToString());
  183. }
  184. finally
  185. {
  186. traction.Dispose();
  187. }
  188. }
  189. private void draw()
  190. {
  191. double D2_5 = 2.5;
  192. double D15 = 15;
  193. double D20 = 20;
  194. double D47_5 = 47.5; //内图廓线和外图廓线距离
  195. double D120 = 120;
  196. double D225 = 225;
  197. double D245 = 245; //右下角附注
  198. double dist1 = 4; //接图表第一格填充间距
  199. double dist2 = 7.071; //接图表填充间距
  200. ObjectId HZ = gettextstyleID("HZ");
  201. ObjectId st = gettextstyleID("st");
  202. ObjectId ht = gettextstyleID("ht");
  203. ObjectId Standard = gettextstyleID("Standard");
  204. ObjectId ID12 = gettextstyleID("12");
  205. ObjectId ID123 = gettextstyleID("123");
  206. //ObjectId XDXT = gettextstyleID("细等线体");
  207. //ObjectId ZDXT = gettextstyleID("中等线体");
  208. //ObjectId ST = gettextstyleID("宋体");
  209. Document document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  210. Database database = HostApplicationServices.WorkingDatabase;
  211. Transaction traction = database.TransactionManager.StartTransaction();
  212. DocumentLock documentlock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  213. BlockTable blocktable = traction.GetObject(database.BlockTableId,
  214. OpenMode.ForWrite) as BlockTable;
  215. BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
  216. OpenMode.ForWrite) as BlockTableRecord;
  217. Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  218. try
  219. {
  220. //内图廓
  221. ////左边线
  222. //Point3dCollection In1 = new Point3dCollection();
  223. //In1.Add(new Point3d(LT.X, LT.Y, 0));
  224. //In1.Add(new Point3d(LB.X, LB.Y, 0));
  225. //Polyline2d LeftLine = new Polyline2d(Poly2dType.SimplePoly, In1, 0, true, 0, 0, null);
  226. ////LeftLine.Color = Autodesk.AutoCAD.Colors.Color.FromColor(System.Drawing.Color.Red);
  227. //LeftLine.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  228. //LeftLine.Layer = "9800";
  229. //LeftLine.SetDatabaseDefaults();
  230. //blocktablerecord.AppendEntity(LeftLine);
  231. //traction.AddNewlyCreatedDBObject(LeftLine, true);
  232. ////下边线
  233. //Point3dCollection In2 = new Point3dCollection();
  234. //In2.Add(new Point3d(LB.X, LB.Y, 0));
  235. //In2.Add(new Point3d(RB.X, RB.Y, 0));
  236. //Polyline2d LowLine = new Polyline2d(Poly2dType.SimplePoly, In2, 0, true, 0, 0, null);
  237. //LowLine.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  238. //LowLine.SetDatabaseDefaults();
  239. //blocktablerecord.AppendEntity(LowLine);
  240. //traction.AddNewlyCreatedDBObject(LowLine, true);
  241. ////右边线
  242. //Point3dCollection In3 = new Point3dCollection();
  243. //In3.Add(new Point3d(RT.X, RT.Y, 0));
  244. //In3.Add(new Point3d(RB.X, RB.Y, 0));
  245. //Polyline2d RightLine = new Polyline2d(Poly2dType.SimplePoly, In3, 0, true, 0, 0, null);
  246. //RightLine.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  247. //RightLine.Layer = "9800";
  248. //RightLine.SetDatabaseDefaults();
  249. //blocktablerecord.AppendEntity(RightLine);
  250. //traction.AddNewlyCreatedDBObject(RightLine, true);
  251. //上边线
  252. //Point3dCollection In4 = new Point3dCollection();
  253. //In4.Add(new Point3d(LT.X, LT.Y, 0));
  254. //In4.Add(new Point3d(RT.X, RT.Y, 0));
  255. //Polyline2d TOPLine = new Polyline2d(Poly2dType.SimplePoly, In4, 0, true, 0, 0, null);
  256. //TOPLine.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  257. //TOPLine.Layer = "9800";
  258. //TOPLine.SetDatabaseDefaults();
  259. //blocktablerecord.AppendEntity(TOPLine);
  260. //traction.AddNewlyCreatedDBObject(TOPLine, true);
  261. //外图廓
  262. Point3dCollection Outcoll = new Point3dCollection();
  263. Outcoll.Add(new Point3d(LT.X - D47_5, LT.Y + D47_5, 0));
  264. Outcoll.Add(new Point3d(LB.X - D47_5, LB.Y - D47_5, 0));
  265. Outcoll.Add(new Point3d(RB.X + D47_5, RB.Y - D47_5, 0));
  266. Outcoll.Add(new Point3d(RT.X + D47_5, RT.Y + D47_5, 0));
  267. Outcoll.Add(new Point3d(LT.X - D47_5, LT.Y + D47_5, 0));
  268. Polyline2d line = new Polyline2d(Poly2dType.SimplePoly, Outcoll, 0, true, D2_5, D2_5, null);
  269. line.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  270. line.Layer = "9800";
  271. line.SetDatabaseDefaults();
  272. blocktablerecord.AppendEntity(line);
  273. traction.AddNewlyCreatedDBObject(line, true);
  274. // 下边线
  275. Point3dCollection coll_B = new Point3dCollection();
  276. Line ll_B = new Line();
  277. double x1 = LB.X - 100;
  278. double ks = (RB.Y - LB.Y) / (RB.X - LB.X);
  279. double y1 = ks * (x1 - LB.X) + LB.Y;
  280. ll_B.StartPoint = new Point3d(x1, y1, 0);
  281. double x2 = RB.X + 100;
  282. double y2 = ks * (x2 - LB.X) + LB.Y;
  283. ll_B.EndPoint = new Point3d(x2, y2, 0);
  284. ll_B.IntersectWith(line, Intersect.ExtendThis, coll_B, 0, 0);
  285. Polyline2d Line_B = new Polyline2d(Poly2dType.SimplePoly, coll_B, 0, false, 0, 0, null);
  286. Line_B.Layer = "9800";
  287. Line_B.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  288. Line_B.SetDatabaseDefaults();
  289. blocktablerecord.AppendEntity(Line_B);
  290. traction.AddNewlyCreatedDBObject(Line_B, true);
  291. //上边线
  292. Point3dCollection coll_T = new Point3dCollection();
  293. Line ll_T = new Line();
  294. x1 = LT.X - 100;
  295. ks = (RT.Y - LT.Y) / (RT.X - LT.X);
  296. y1 = ks * (x1 - LT.X) + LT.Y;
  297. ll_T.StartPoint = new Point3d(x1, y1, 0);
  298. x2 = LT.X + 100;
  299. y2 = ks * (x2 - LT.X) + LT.Y;
  300. ll_T.EndPoint = new Point3d(x2, y2, 0);
  301. ll_T.IntersectWith(line, Intersect.ExtendThis, coll_T, 0, 0);
  302. Polyline2d Line_T = new Polyline2d(Poly2dType.SimplePoly, coll_T, 0, false, 0, 0, null);
  303. Line_T.Layer = "9800";
  304. Line_T.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  305. Line_T.SetDatabaseDefaults();
  306. blocktablerecord.AppendEntity(Line_T);
  307. traction.AddNewlyCreatedDBObject(Line_T, true);
  308. //左边线
  309. Point3dCollection coll_L = new Point3dCollection();
  310. Line ll_L = new Line();
  311. y1 = LB.Y - 100;
  312. ks = (LT.Y - LB.Y) / (LT.X - LB.X);
  313. x1 = LB.X + (y1 - LB.Y) / ks;
  314. ll_L.StartPoint = new Point3d(x1, y1, 0);
  315. y2 = LT.Y + 100;
  316. x2 = LB.X + (y2 - LB.Y) / ks;
  317. ll_L.EndPoint = new Point3d(x2, y2, 0);
  318. ll_L.IntersectWith(line, Intersect.ExtendThis, coll_L, 0, 0);
  319. Polyline2d Line_L = new Polyline2d(Poly2dType.SimplePoly, coll_L, 0, false, 0, 0, null);
  320. Line_L.Layer = "9800";
  321. Line_L.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  322. Line_L.SetDatabaseDefaults();
  323. blocktablerecord.AppendEntity(Line_L);
  324. traction.AddNewlyCreatedDBObject(Line_L, true);
  325. //右边线
  326. Point3dCollection coll_R = new Point3dCollection();
  327. Line ll_R = new Line();
  328. y1 = RB.Y - 100;
  329. ks = (RT.Y - RB.Y) / (RT.X - RB.X);
  330. x1 = RB.X + (y1 - RB.Y) / ks;
  331. ll_R.StartPoint = new Point3d(x1, y1, 0);
  332. y2 = RT.Y + 100;
  333. x2 = RB.X + (y2 - RB.Y) / ks;
  334. ll_R.EndPoint = new Point3d(x2, y2, 0);
  335. ll_R.IntersectWith(line, Intersect.ExtendThis, coll_R, 0, 0);
  336. Polyline2d Line_R = new Polyline2d(Poly2dType.SimplePoly, coll_R, 0, false, 0, 0, null);
  337. Line_R.Layer = "9800";
  338. Line_R.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  339. Line_R.SetDatabaseDefaults();
  340. blocktablerecord.AppendEntity(Line_R);
  341. traction.AddNewlyCreatedDBObject(Line_R, true);
  342. //
  343. //x坐标
  344. List<double> list_x = new List<double>();
  345. double x0 = 500 - LB.X % 500;
  346. x0 = LB.X + x0;
  347. list_x.Add(x0);
  348. while (x0 + 500 < RB.X)
  349. {
  350. x0 = x0 + 500;
  351. list_x.Add(x0);
  352. }
  353. //y坐标
  354. List<double> list_y = new List<double>();
  355. double y0 = 500 - LB.Y % 500;
  356. y0 = LB.Y + y0;
  357. list_y.Add(y0);
  358. while (y0 + 500 < LT.Y)
  359. {
  360. y0 = y0 + 500;
  361. list_y.Add(y0);
  362. }
  363. //
  364. //十字框标
  365. for (int i = 0; i < list_x.Count; i++)
  366. {
  367. for (int j = 0; j < list_y.Count; j++)
  368. {
  369. double x = list_x[i];
  370. double y = list_y[j];
  371. Point3d p1 = new Point3d(x - 25, y, 0);
  372. Point3d p2 = new Point3d(x + 25, y, 0);
  373. Point3dCollection kb = new Point3dCollection();
  374. kb.Add(p1);
  375. kb.Add(p2);
  376. Polyline2d kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null);
  377. kbline.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  378. kbline.Layer = "9800";
  379. kbline.SetDatabaseDefaults();
  380. blocktablerecord.AppendEntity(kbline);
  381. traction.AddNewlyCreatedDBObject(kbline, true);
  382. p1 = new Point3d(x, y - 25, 0);
  383. p2 = new Point3d(x, y + 25, 0);
  384. Point3dCollection kb2 = new Point3dCollection();
  385. kb2.Add(p1);
  386. kb2.Add(p2);
  387. Polyline2d kbline2 = new Polyline2d(Poly2dType.SimplePoly, kb2, 0, false, 0, 0, null);
  388. kbline2.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  389. kbline2.Layer = "9800";
  390. kbline2.SetDatabaseDefaults();
  391. blocktablerecord.AppendEntity(kbline2);
  392. traction.AddNewlyCreatedDBObject(kbline2, true);
  393. }
  394. }
  395. List<Point3d> Below_List = new List<Point3d>();
  396. List<Point3d> Top_List = new List<Point3d>();
  397. List<Point3d> Left_List = new List<Point3d>();
  398. List<Point3d> Right_List = new List<Point3d>();
  399. //上下边线的短线
  400. for (int i = 0; i < list_x.Count; i++)
  401. {
  402. double x = list_x[i];
  403. double k = (RB.Y - LB.Y) / (RB.X - LB.X);
  404. double y = k * (x - LB.X) + LB.Y;
  405. Point3d p1 = new Point3d(x, y, 0);
  406. Point3d p2 = new Point3d(x, y - 47.5, 0);
  407. Point3dCollection pc = new Point3dCollection();
  408. pc.Add(p1);
  409. pc.Add(p2);
  410. Polyline2d Kline = new Polyline2d(Poly2dType.SimplePoly, pc, 0, false, 0, 0, null);
  411. Kline.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  412. Kline.Layer = "9800";
  413. Kline.SetDatabaseDefaults();
  414. blocktablerecord.AppendEntity(Kline);
  415. traction.AddNewlyCreatedDBObject(Kline, true);
  416. Below_List.Add(p1);
  417. y = k * (x - LT.X) + LT.Y;
  418. p1 = new Point3d(x, y, 0);
  419. p2 = new Point3d(x, y + 47.5, 0);
  420. pc = new Point3dCollection();
  421. pc.Add(p1);
  422. pc.Add(p2);
  423. Kline = new Polyline2d(Poly2dType.SimplePoly, pc, 0, false, 0, 0, null);
  424. Kline.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  425. Kline.Layer = "9800";
  426. Kline.SetDatabaseDefaults();
  427. blocktablerecord.AppendEntity(Kline);
  428. traction.AddNewlyCreatedDBObject(Kline, true);
  429. Top_List.Add(p1);
  430. }
  431. //左右边线的短线
  432. for (int i = 0; i < list_y.Count; i++)
  433. {
  434. double y = list_y[i];
  435. double k = (LT.Y - LB.Y) / (LT.X - LB.X);
  436. double x = LB.X + (y - LB.Y) / k;
  437. Point3d p1 = new Point3d(x, y, 0);
  438. Point3d p2 = new Point3d(x - 47.5, y, 0);
  439. Point3dCollection pc = new Point3dCollection();
  440. pc.Add(p1);
  441. pc.Add(p2);
  442. Polyline2d Kline = new Polyline2d(Poly2dType.SimplePoly, pc, 0, false, 0, 0, null);
  443. Kline.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  444. Kline.Layer = "9800";
  445. Kline.SetDatabaseDefaults();
  446. blocktablerecord.AppendEntity(Kline);
  447. traction.AddNewlyCreatedDBObject(Kline, true);
  448. Left_List.Add(p1);
  449. x = RB.X + (y - RB.Y) / k;
  450. p1 = new Point3d(x, y, 0);
  451. p2 = new Point3d(x + 47.5, y, 0);
  452. pc = new Point3dCollection();
  453. pc.Add(p1);
  454. pc.Add(p2);
  455. Kline = new Polyline2d(Poly2dType.SimplePoly, pc, 0, false, 0, 0, null);
  456. Kline.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  457. Kline.Layer = "9800";
  458. Kline.SetDatabaseDefaults();
  459. blocktablerecord.AppendEntity(Kline);
  460. traction.AddNewlyCreatedDBObject(Kline, true);
  461. Right_List.Add(p1);
  462. }
  463. //下边线坐标
  464. for (int i = 0; i < Below_List.Count; i++)
  465. {
  466. double x = Below_List[i].X;
  467. double y = Below_List[i].Y;
  468. DBText text7 = new DBText();
  469. string value7 = (x / 1000.0 % 100).ToString("F1");
  470. if (value7.Length == 3)
  471. {
  472. value7 = "0" + value7;
  473. }
  474. text7.TextString = value7;
  475. text7.Position = new Point3d(x - 22.5, y - 41.25, 0);
  476. text7.Height = 15;
  477. text7.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
  478. text7.Layer = "9800";
  479. text7.TextStyle = HZ;
  480. text7.WidthFactor = 0.75;
  481. text7.SetDatabaseDefaults();
  482. blocktablerecord.AppendEntity(text7);
  483. traction.AddNewlyCreatedDBObject(text7, true);
  484. if (i == 0 || i == Below_List.Count - 1)
  485. {
  486. DBText text = new DBText();
  487. string value = "34" + ((int)x / 1000 / 100).ToString();
  488. text.TextString = value;
  489. text.Position = new Point3d(x - 43, y - 36.25, 0);
  490. text.Height = 10;
  491. text.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
  492. text.Layer = "9800";
  493. text.TextStyle = HZ;
  494. text.WidthFactor = 0.75;
  495. text.SetDatabaseDefaults();
  496. blocktablerecord.AppendEntity(text);
  497. traction.AddNewlyCreatedDBObject(text, true);
  498. }
  499. }
  500. //上边线坐标
  501. for (int i = 0; i < Top_List.Count; i++)
  502. {
  503. double x = Top_List[i].X;
  504. double y = Top_List[i].Y;
  505. DBText text7 = new DBText();
  506. string value7 = (x / 1000.0 % 100).ToString("F1");
  507. if (value7.Length == 3)
  508. {
  509. value7 = "0" + value7;
  510. }
  511. text7.TextString = value7;
  512. text7.Position = new Point3d(x - 22.5, y + 26.25, 0);
  513. text7.Height = 15;
  514. text7.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
  515. text7.Layer = "9800";
  516. text7.TextStyle = HZ;
  517. text7.WidthFactor = 0.75;
  518. text7.SetDatabaseDefaults();
  519. blocktablerecord.AppendEntity(text7);
  520. traction.AddNewlyCreatedDBObject(text7, true);
  521. if (i == 0 || i == Below_List.Count - 1)
  522. {
  523. DBText text = new DBText();
  524. string value = "34" + ((int)x / 1000 / 100).ToString();
  525. text.TextString = value;
  526. text.Position = new Point3d(x - 43, y + 31.25, 0);
  527. text.Height = 10;
  528. text.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
  529. text.Layer = "9800";
  530. text.TextStyle = HZ;
  531. text.WidthFactor = 0.75;
  532. text.SetDatabaseDefaults();
  533. blocktablerecord.AppendEntity(text);
  534. traction.AddNewlyCreatedDBObject(text, true);
  535. }
  536. }
  537. //左边线坐标
  538. for (int i = 0; i < Left_List.Count; i++)
  539. {
  540. double x = Left_List[i].X;
  541. double y = Left_List[i].Y;
  542. DBText text7 = new DBText();
  543. string value7 = (y / 1000.0 % 100).ToString("F1");
  544. if (value7.Length == 3)
  545. {
  546. value7 = "0" + value7;
  547. }
  548. text7.TextString = value7;
  549. text7.Position = new Point3d(x - 37.5, y + 5, 0);
  550. text7.Height = 15;
  551. text7.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
  552. text7.Layer = "9800";
  553. text7.TextStyle = HZ;
  554. text7.WidthFactor = 0.75;
  555. text7.SetDatabaseDefaults();
  556. blocktablerecord.AppendEntity(text7);
  557. traction.AddNewlyCreatedDBObject(text7, true);
  558. if (i == 0 || i == Left_List.Count - 1)
  559. {
  560. DBText text = new DBText();
  561. string value = ((int)y / 1000 / 100).ToString();
  562. text.TextString = value;
  563. text.Position = new Point3d(x - 46.5, y + 21, 0);
  564. text.Height = 10;
  565. text.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
  566. text.Layer = "9800";
  567. text.TextStyle = HZ;
  568. text.WidthFactor = 0.75;
  569. text.SetDatabaseDefaults();
  570. blocktablerecord.AppendEntity(text);
  571. traction.AddNewlyCreatedDBObject(text, true);
  572. }
  573. }
  574. //右边线坐标
  575. for (int i = 0; i < Right_List.Count; i++)
  576. {
  577. double x = Right_List[i].X;
  578. double y = Right_List[i].Y;
  579. DBText text7 = new DBText();
  580. string value7 = (y / 1000.0 % 100).ToString("F1");
  581. if (value7.Length == 3)
  582. {
  583. value7 = "0" + value7;
  584. }
  585. text7.TextString = value7;
  586. text7.Position = new Point3d(x + 8.5, y + 5, 0);
  587. text7.Height = 15;
  588. text7.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
  589. text7.Layer = "9800";
  590. text7.TextStyle = HZ;
  591. text7.WidthFactor = 0.75;
  592. text7.SetDatabaseDefaults();
  593. blocktablerecord.AppendEntity(text7);
  594. traction.AddNewlyCreatedDBObject(text7, true);
  595. if (i == 0 || i == Right_List.Count - 1)
  596. {
  597. DBText text = new DBText();
  598. string value = ((int)y / 1000 / 100).ToString();
  599. text.TextString = value;
  600. text.Position = new Point3d(x, y + 21, 0);
  601. text.Height = 10;
  602. text.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
  603. text.Layer = "9800";
  604. text.TextStyle = HZ;
  605. text.WidthFactor = 0.75;
  606. text.SetDatabaseDefaults();
  607. blocktablerecord.AppendEntity(text);
  608. traction.AddNewlyCreatedDBObject(text, true);
  609. }
  610. }
  611. //右下角附注
  612. double xx = 0;
  613. double yy = 0;
  614. xx = RB.X - D245;
  615. yy = RB.Y - 78.75;
  616. List<string> RLnote = new List<string>();
  617. string str = "";
  618. str = "调查员: 赵永健";
  619. RLnote.Add(str);
  620. str = "检查员: 葛礼辉";
  621. RLnote.Add(str);
  622. for (int i = 0; i < RLnote.Count; i++)
  623. {
  624. DBText text1 = new DBText();
  625. text1.TextString = RLnote[i];
  626. text1.Position = new Point3d(xx, yy, 0);
  627. text1.Height = D15;
  628. text1.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 4);
  629. text1.Layer = "9800";
  630. text1.TextStyle = HZ;
  631. text1.SetDatabaseDefaults();
  632. blocktablerecord.AppendEntity(text1);
  633. traction.AddNewlyCreatedDBObject(text1, true);
  634. yy = yy - 30;
  635. }
  636. //比例尺
  637. xx = (RB.X - LB.X) / 2 + LB.X;
  638. yy = LB.Y - 93.75;
  639. DBText text2 = new DBText();
  640. text2.TextString = "1:5000";
  641. text2.Position = new Point3d(xx, yy, 0);
  642. text2.Height = D20;
  643. text2.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 2);
  644. text2.Layer = "9800";
  645. text2.HorizontalMode = TextHorizontalMode.TextCenter;
  646. text2.AlignmentPoint = new Point3d(xx, yy, 0);
  647. text2.TextStyle = ID12;
  648. text2.WidthFactor = 0.75;
  649. text2.SetDatabaseDefaults();
  650. blocktablerecord.AppendEntity(text2);
  651. traction.AddNewlyCreatedDBObject(text2, true);
  652. //图名
  653. xx = (RB.X - LB.X) / 2 + LB.X;
  654. yy = LT.Y + 138.75;
  655. DBText text4 = new DBText();
  656. text4.TextString = Title;
  657. text4.Position = new Point3d(xx, yy, 0);
  658. text4.Height = 25;
  659. text4.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 6);
  660. text4.Layer = "9800";
  661. text4.HorizontalMode = TextHorizontalMode.TextCenter;
  662. text4.AlignmentPoint = new Point3d(xx, yy, 0);
  663. text4.TextStyle = ID123;
  664. text4.WidthFactor = 1;
  665. text4.SetDatabaseDefaults();
  666. blocktablerecord.AppendEntity(text4);
  667. traction.AddNewlyCreatedDBObject(text4, true);
  668. string[] str_lbtxt = new string[3];
  669. str_lbtxt[0] = "2012年8月调查。";
  670. str_lbtxt[1] = "1980西安坐标系。";
  671. str_lbtxt[2] = "1985国家高程基准。";
  672. xx = LB.X;
  673. yy = LB.Y - 78.75;
  674. for (int i = 0; i < 3; i++)
  675. {
  676. DBText text_1 = new DBText();
  677. text_1.TextString = str_lbtxt[i];
  678. text_1.Position = new Point3d(xx, yy, 0);
  679. text_1.Height = D15;
  680. text_1.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 4);
  681. text_1.Layer = "9800";
  682. text_1.TextStyle = HZ;
  683. text_1.WidthFactor = 1;
  684. text_1.SetDatabaseDefaults();
  685. blocktablerecord.AppendEntity(text_1);
  686. traction.AddNewlyCreatedDBObject(text_1, true);
  687. yy = yy - 30;
  688. }
  689. //公司名称
  690. string Company = "四川中水成勘院测绘工程有限责任公司";
  691. xx = LB.X - 82.75;
  692. yy = LB.Y;
  693. for (int i = Company.Length - 1; i >= 0; i--)
  694. {
  695. DBText text6 = new DBText();
  696. text6.TextString = Company[i].ToString();
  697. text6.Position = new Point3d(xx, yy, 0);
  698. text6.Height = D20;
  699. text6.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 2);
  700. text6.Layer = "9800";
  701. text6.TextStyle = HZ;
  702. text6.WidthFactor = 1;
  703. text6.SetDatabaseDefaults();
  704. blocktablerecord.AppendEntity(text6);
  705. traction.AddNewlyCreatedDBObject(text6, true);
  706. yy = yy + 25;
  707. }
  708. //接图表
  709. //接图表左下角坐标
  710. xx = LT.X;
  711. yy = LT.Y + 63.75;
  712. for (int i = 0; i < 4; i++)
  713. {
  714. Point3dCollection Lcoll = new Point3dCollection();
  715. Lcoll.Add(new Point3d(xx, yy + D120, 0));
  716. Lcoll.Add(new Point3d(xx, yy, 0));
  717. Polyline2d JTB = new Polyline2d(Poly2dType.SimplePoly, Lcoll, 0, true, 0, 0, null);
  718. JTB.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  719. JTB.Layer = "9800";
  720. JTB.SetDatabaseDefaults();
  721. blocktablerecord.AppendEntity(JTB);
  722. traction.AddNewlyCreatedDBObject(JTB, true);
  723. xx = xx + 75;
  724. }
  725. xx = LT.X;
  726. yy = LT.Y + 63.75;
  727. for (int i = 0; i < 4; i++)
  728. {
  729. Point3dCollection Lcoll = new Point3dCollection();
  730. Lcoll.Add(new Point3d(xx, yy, 0));
  731. Lcoll.Add(new Point3d(xx + D225, yy, 0));
  732. Polyline2d JTB = new Polyline2d(Poly2dType.SimplePoly, Lcoll, 0, true, 0, 0, null);
  733. JTB.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  734. JTB.Layer = "9800";
  735. JTB.SetDatabaseDefaults();
  736. blocktablerecord.AppendEntity(JTB);
  737. traction.AddNewlyCreatedDBObject(JTB, true);
  738. yy = yy + 40;
  739. }
  740. //接图表填充
  741. //接图表左上角坐标
  742. xx = LT.X + D225 / 3;
  743. yy = LT.Y + 63.75 + (D120 / 3) * 2;
  744. Point3dCollection coll = new Point3dCollection();
  745. coll.Add(new Point3d(xx, yy, 0));
  746. coll.Add(new Point3d(xx, yy - D120 / 3, 0));
  747. coll.Add(new Point3d(xx + D225 / 3, yy - D120 / 3, 0));
  748. coll.Add(new Point3d(xx + D225 / 3, yy, 0));
  749. coll.Add(new Point3d(xx, yy, 0));
  750. Polyline2d line2d = new Polyline2d(Poly2dType.SimplePoly, coll, 0, false, 0, 0, null);
  751. xx = xx + dist1;
  752. for (int i = 0; i < 30; i++)
  753. {
  754. Line l = new Line();
  755. l.StartPoint = new Point3d(xx + 90, yy + 90, 0);
  756. l.EndPoint = new Point3d(xx - 90, yy - 90, 0);
  757. Point3dCollection IP = new Point3dCollection();
  758. l.IntersectWith(line2d, Intersect.ExtendThis, IP, 0, 0);
  759. Polyline2d FillLine = new Polyline2d(Poly2dType.SimplePoly, IP, 0, false, 0, 0, null);
  760. FillLine.Layer = "9800";
  761. FillLine.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 1);
  762. FillLine.SetDatabaseDefaults();
  763. blocktablerecord.AppendEntity(FillLine);
  764. traction.AddNewlyCreatedDBObject(FillLine, true);
  765. xx = xx + dist2;
  766. }
  767. Point3d pp1 = new Point3d(LT.X - 3000, LT.Y + 2000, 0);
  768. Point3d pp2 = LT;
  769. string str1 = GetNumber(pp1, pp2);
  770. pp1 = LT;
  771. pp2 = new Point3d(LT.X + 3000, LT.Y + 2000, 0);
  772. string str2 = GetNumber(pp1, pp2);
  773. pp1 = RT;
  774. pp2 = new Point3d(RT.X + 3000, RT.Y + 2000, 0);
  775. string str3 = GetNumber(pp1, pp2);
  776. pp1 = LT;
  777. pp2 = new Point3d(LT.X - 3000, LT.Y - 2000, 0);
  778. string str4 = GetNumber(pp1, pp2);
  779. pp1 = RB;
  780. pp2 = new Point3d(RB.X + 3000, RB.Y + 2000, 0);
  781. string str5 = GetNumber(pp1, pp2);
  782. pp1 = LB;
  783. pp2 = new Point3d(LB.X - 3000, LB.Y - 2000, 0);
  784. string str6 = GetNumber(pp1, pp2);
  785. pp1 = RB;
  786. pp2 = new Point3d(RB.X - 3000, RB.Y - 2000, 0);
  787. string str7 = GetNumber(pp1, pp2);
  788. pp1 = RB;
  789. pp2 = new Point3d(RB.X + 3000, RB.Y - 2000, 0);
  790. string str8 = GetNumber(pp1, pp2);
  791. double xx1 = LT.X + 37.5;
  792. double yy1 = LT.Y + 83.75;
  793. double xx2 = 0;
  794. double yy2 = 0;
  795. for (int i = 1; i < 9; i++)
  796. {
  797. string value = "";
  798. switch (i)
  799. {
  800. case 1:
  801. value = str1;
  802. xx2 = xx1;
  803. yy2 = yy1 + 80;
  804. break;
  805. case 2:
  806. value = str2;
  807. xx2 = xx1 + 75;
  808. yy2 = yy1 + 80;
  809. break;
  810. case 3:
  811. value = str3;
  812. xx2 = xx1 + 150;
  813. yy2 = yy1 + 80;
  814. break;
  815. case 4:
  816. value = str4;
  817. xx2 = xx1;
  818. yy2 = yy1 + 40;
  819. break;
  820. case 5:
  821. value = str5;
  822. xx2 = xx1 + 150;
  823. yy2 = yy1 + 40;
  824. break;
  825. case 6:
  826. value = str6;
  827. xx2 = xx1;
  828. yy2 = yy1;
  829. break;
  830. case 7:
  831. value = str7;
  832. xx2 = xx1 + 75;
  833. yy2 = yy1;
  834. break;
  835. case 8:
  836. value = str6;
  837. xx2 = xx1 + 150;
  838. yy2 = yy1;
  839. break;
  840. default:
  841. break;
  842. }
  843. if (value != "")
  844. {
  845. value = value.Substring(value.Length - 3);
  846. }
  847. DBText text_L = new DBText();
  848. text_L.TextString = value;
  849. text_L.Position = new Point3d(xx2, yy2, 0);
  850. text_L.Height = 12.5;
  851. text_L.WidthFactor = 0.75;
  852. text_L.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
  853. text_L.Layer = "9800";
  854. text_L.TextStyle = HZ;
  855. text_L.HorizontalMode = TextHorizontalMode.TextCenter;
  856. text_L.VerticalMode = TextVerticalMode.TextVerticalMid;
  857. text_L.AlignmentPoint = new Point3d(xx2, yy2, 0);
  858. text_L.SetDatabaseDefaults();
  859. blocktablerecord.AppendEntity(text_L);
  860. traction.AddNewlyCreatedDBObject(text_L, true);
  861. }
  862. ////接图表中间行——左
  863. //if (string.IsNullOrEmpty(Left_Number) == false)
  864. //{
  865. // //接图表左下角坐标
  866. // xx1 = LT.X;
  867. // yy1 = LT.Y + D22 + D2 + D6;
  868. // xx2 = xx1 + D90 / 3 / 2;
  869. // yy2 = yy1 + D48 / 3 * 1.5;
  870. // DBText text_L = new DBText();
  871. // text_L.TextString = Left_Number;
  872. // text_L.Position = new Point3d(xx2, yy2, 0);
  873. // text_L.Height = D5;
  874. // text_L.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
  875. // text_L.Layer = layername;
  876. // text_L.TextStyle = HZ;
  877. // text_L.HorizontalMode = TextHorizontalMode.TextCenter;
  878. // text_L.VerticalMode = TextVerticalMode.TextVerticalMid;
  879. // text_L.AlignmentPoint = new Point3d(xx2, yy2, 0);
  880. // text_L.SetDatabaseDefaults();
  881. // blocktablerecord.AppendEntity(text_L);
  882. // traction.AddNewlyCreatedDBObject(text_L, true);
  883. //}
  884. ////接图表中间行——右
  885. //if (string.IsNullOrEmpty(Right_Number) == false)
  886. //{
  887. // //接图表左下角坐标
  888. // xx1 = LT.X;
  889. // yy1 = LT.Y + D22 + D2 + D6;
  890. // xx2 = xx1 + D90 / 3 * 2.5;
  891. // yy2 = yy1 + D48 / 3 * 1.5;
  892. // DBText text_R = new DBText();
  893. // text_R.TextString = Right_Number;
  894. // text_R.Position = new Point3d(xx2, yy2, 0);
  895. // text_R.Height = D5;
  896. // text_R.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByColor, 3);
  897. // text_R.Layer = layername;
  898. // text_R.TextStyle = HZ;
  899. // text_R.HorizontalMode = TextHorizontalMode.TextCenter;
  900. // text_R.VerticalMode = TextVerticalMode.TextVerticalMid;
  901. // text_R.AlignmentPoint = new Point3d(xx2, yy2, 0);
  902. // text_R.SetDatabaseDefaults();
  903. // blocktablerecord.AppendEntity(text_R);
  904. // traction.AddNewlyCreatedDBObject(text_R, true);
  905. //}
  906. traction.Commit();
  907. }
  908. catch (Autodesk.AutoCAD.Runtime.Exception ex)
  909. {
  910. System.Windows.Forms.MessageBox.Show(ex.ToString());
  911. }
  912. finally
  913. {
  914. traction.Dispose();
  915. documentlock.Dispose();
  916. }
  917. }
  918. private void createTextStyle()
  919. {
  920. Database database = HostApplicationServices.WorkingDatabase;
  921. Transaction traction = database.TransactionManager.StartTransaction();
  922. DocumentLock documentlock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  923. TextStyleTable styletable = traction.GetObject(database.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
  924. string stylename = "ht";
  925. if (styletable.Has(stylename) == false)
  926. {
  927. TextStyleTableRecord R1 = new TextStyleTableRecord();
  928. R1.Name = stylename;
  929. //R1.FileName = "方正细等线简体";
  930. R1.FileName = "SIMHEI.TTF";
  931. //record.BigFontFileName = "hztxt.shx";
  932. R1.ObliquingAngle = 0;
  933. R1.XScale = 1;
  934. ObjectId textstyleID = styletable.Add(R1);
  935. traction.AddNewlyCreatedDBObject(R1, true);
  936. //database.Textstyle = textstyleID;
  937. }
  938. stylename = "HZ";
  939. if (styletable.Has(stylename) == false)
  940. {
  941. TextStyleTableRecord R1 = new TextStyleTableRecord();
  942. R1.Name = stylename;
  943. //R1.FileName = "方正细等线简体";
  944. R1.FileName = "rs.shx";
  945. R1.BigFontFileName = "hztxt.shx";
  946. R1.ObliquingAngle = 0;
  947. R1.XScale = 0.75;
  948. ObjectId textstyleID = styletable.Add(R1);
  949. traction.AddNewlyCreatedDBObject(R1, true);
  950. //database.Textstyle = textstyleID;
  951. }
  952. stylename = "st";
  953. if (styletable.Has(stylename) == false)
  954. {
  955. TextStyleTableRecord R1 = new TextStyleTableRecord();
  956. R1.Name = stylename;
  957. //R1.FileName = "方正细等线简体";
  958. R1.FileName = "STSONG.TTF";
  959. //R1.BigFontFileName = "hztxt.shx";
  960. R1.ObliquingAngle = 0;
  961. R1.XScale = 1;
  962. ObjectId textstyleID = styletable.Add(R1);
  963. traction.AddNewlyCreatedDBObject(R1, true);
  964. //database.Textstyle = textstyleID;
  965. }
  966. stylename = "Standard";
  967. if (styletable.Has(stylename) == false)
  968. {
  969. TextStyleTableRecord R1 = new TextStyleTableRecord();
  970. R1.Name = stylename;
  971. //R1.FileName = "方正细等线简体";
  972. R1.FileName = "rs.shx";
  973. R1.BigFontFileName = "hztxt.shx";
  974. R1.ObliquingAngle = 0;
  975. R1.XScale = 0.75;
  976. ObjectId textstyleID = styletable.Add(R1);
  977. traction.AddNewlyCreatedDBObject(R1, true);
  978. //database.Textstyle = textstyleID;
  979. }
  980. stylename = "123";
  981. if (styletable.Has(stylename) == false)
  982. {
  983. TextStyleTableRecord R1 = new TextStyleTableRecord();
  984. R1.Name = stylename;
  985. //R1.FileName = "方正细等线简体";
  986. R1.FileName = "SIMHEI.TTF";
  987. //R1.BigFontFileName = "hztxt.shx";
  988. R1.ObliquingAngle = 0;
  989. R1.XScale = 0.75;
  990. ObjectId textstyleID = styletable.Add(R1);
  991. traction.AddNewlyCreatedDBObject(R1, true);
  992. //database.Textstyle = textstyleID;
  993. }
  994. stylename = "12";
  995. if (styletable.Has(stylename) == false)
  996. {
  997. TextStyleTableRecord R1 = new TextStyleTableRecord();
  998. R1.Name = stylename;
  999. //R1.FileName = "方正细等线简体";
  1000. R1.FileName = "complex.shx";
  1001. //R1.BigFontFileName = "hztxt.shx";
  1002. R1.ObliquingAngle = 0;
  1003. R1.XScale = 0.75;
  1004. ObjectId textstyleID = styletable.Add(R1);
  1005. traction.AddNewlyCreatedDBObject(R1, true);
  1006. //database.Textstyle = textstyleID;
  1007. }
  1008. stylename = "细等线体";
  1009. if (styletable.Has(stylename) == false)
  1010. {
  1011. TextStyleTableRecord R1 = new TextStyleTableRecord();
  1012. R1.Name = stylename;
  1013. //R1.FileName = "方正细等线简体";
  1014. R1.FileName = "FZXDXJW.TTF";
  1015. //record.BigFontFileName = "hztxt.shx";
  1016. R1.ObliquingAngle = 0;
  1017. R1.XScale = 1;
  1018. ObjectId textstyleID = styletable.Add(R1);
  1019. traction.AddNewlyCreatedDBObject(R1, true);
  1020. //database.Textstyle = textstyleID;
  1021. }
  1022. stylename = "中等线体";
  1023. if (styletable.Has(stylename) == false)
  1024. {
  1025. TextStyleTableRecord R2 = new TextStyleTableRecord();
  1026. R2.Name = stylename;
  1027. //R2.FileName = "方正中等线简体";
  1028. R2.FileName = "FZZDXJW.TTF";
  1029. //record.BigFontFileName = "hztxt.shx";
  1030. R2.ObliquingAngle = 0;
  1031. R2.XScale = 1;
  1032. ObjectId textstyleID = styletable.Add(R2);
  1033. traction.AddNewlyCreatedDBObject(R2, true);
  1034. //database.Textstyle = textstyleID;
  1035. }
  1036. stylename = "宋体";
  1037. if (styletable.Has(stylename) == false)
  1038. {
  1039. TextStyleTableRecord R3 = new TextStyleTableRecord();
  1040. R3.Name = stylename;
  1041. //R3.FileName = "华文宋体";
  1042. R3.FileName = "STSONG.TTF";
  1043. //record.BigFontFileName = "hztxt.shx";
  1044. R3.ObliquingAngle = 0;
  1045. R3.XScale = 1;
  1046. ObjectId textstyleID = styletable.Add(R3);
  1047. traction.AddNewlyCreatedDBObject(R3, true);
  1048. //database.Textstyle = textstyleID;
  1049. }
  1050. traction.Commit();
  1051. documentlock.Dispose();
  1052. }
  1053. private ObjectId gettextstyleID(string Name)
  1054. {
  1055. Database database = HostApplicationServices.WorkingDatabase;
  1056. Transaction traction = database.TransactionManager.StartTransaction();
  1057. DocumentLock documentlock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  1058. TextStyleTable styletable = traction.GetObject(database.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
  1059. //BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
  1060. // OpenMode.ForWrite) as BlockTableRecord;
  1061. TextStyleTableRecord record = traction.GetObject(styletable[Name], OpenMode.ForRead) as TextStyleTableRecord;
  1062. ObjectId ID = record.ObjectId;
  1063. traction.Commit();
  1064. documentlock.Dispose();
  1065. return ID;
  1066. }
  1067. private void zoom()
  1068. {
  1069. Document document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  1070. Database database = HostApplicationServices.WorkingDatabase;
  1071. Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  1072. using (Transaction traction = database.TransactionManager.StartTransaction())
  1073. {
  1074. ViewTableRecord currview = editor.GetCurrentView();
  1075. currview.CenterPoint = new Point2d((RT.X - LT.X) / 2 + LT.X, (LT.Y - LB.Y) / 2 + LB.Y);
  1076. currview.ViewDirection = new Vector3d(0, 0, 1);
  1077. currview.Width = RT.X - LT.X + 500;
  1078. currview.Height = LT.Y - LB.Y + 500;
  1079. editor.SetCurrentView(currview);
  1080. traction.Commit();
  1081. }
  1082. }
  1083. private string GetNumber(Point3d p1, Point3d p2)
  1084. {
  1085. string TValue = "";
  1086. Document document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  1087. Database database = HostApplicationServices.WorkingDatabase;
  1088. using (Transaction traction = database.TransactionManager.StartTransaction())
  1089. {
  1090. DocumentLock documentlock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  1091. BlockTable blocktable = traction.GetObject(database.BlockTableId,
  1092. OpenMode.ForRead) as BlockTable;
  1093. Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  1094. TypedValue[] typed = new TypedValue[1];
  1095. typed.SetValue(new TypedValue((int)DxfCode.Start, "3dFace,LWPolyline,Polyline,Polyline2d"), 0);
  1096. SelectionFilter filter = new SelectionFilter(typed);
  1097. PromptSelectionResult psr = editor.SelectWindow(p1, p2, filter);
  1098. if (psr.Status == PromptStatus.OK)
  1099. {
  1100. SelectionSet selectionset = psr.Value;
  1101. ObjectId[] obj = new ObjectId[selectionset.Count];
  1102. obj = selectionset.GetObjectIds();
  1103. for (int i = 0; i < obj.Length; i++)
  1104. {
  1105. ObjectId objid = obj[i];
  1106. Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead);
  1107. if (entity is Face)
  1108. {
  1109. TypedValue[] typed_T = new TypedValue[2];
  1110. typed_T.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0);
  1111. typed_T.SetValue(new TypedValue((int)DxfCode.LayerName, "TREE_LAYER"), 1);
  1112. SelectionFilter filter_T = new SelectionFilter(typed_T);
  1113. PromptSelectionResult psr_T = editor.SelectWindow(p1, p2, filter_T);
  1114. if (psr_T.Status == PromptStatus.OK)
  1115. {
  1116. SelectionSet set_T = psr_T.Value;
  1117. ObjectId[] obj_T = new ObjectId[set_T.Count];
  1118. obj_T = set_T.GetObjectIds();
  1119. for (int j = 0; j < obj_T.Length; j++)
  1120. {
  1121. ObjectId id_T = obj_T[i];
  1122. Entity entits = (Entity)traction.GetObject(id_T, OpenMode.ForRead);
  1123. if (entits is DBText)
  1124. {
  1125. DBText text = entits as DBText;
  1126. TValue = text.TextString;
  1127. break;
  1128. }
  1129. }
  1130. }
  1131. break;
  1132. }
  1133. else if (entity is Polyline)
  1134. {
  1135. TypedValue[] typed_T = new TypedValue[2];
  1136. typed_T.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0);
  1137. typed_T.SetValue(new TypedValue((int)DxfCode.LayerName, "TREE_LAYER"), 1);
  1138. SelectionFilter filter_T = new SelectionFilter(typed_T);
  1139. PromptSelectionResult psr_T = editor.SelectWindow(p1, p2, filter_T);
  1140. if (psr_T.Status == PromptStatus.OK)
  1141. {
  1142. SelectionSet set_T = psr_T.Value;
  1143. ObjectId[] obj_T = new ObjectId[set_T.Count];
  1144. obj_T = set_T.GetObjectIds();
  1145. for (int j = 0; j < obj_T.Length; j++)
  1146. {
  1147. ObjectId id_T = obj_T[j];
  1148. Entity entits = (Entity)traction.GetObject(id_T, OpenMode.ForRead);
  1149. if (entits is DBText)
  1150. {
  1151. DBText text = entits as DBText;
  1152. TValue = text.TextString;
  1153. break;
  1154. }
  1155. }
  1156. }
  1157. break;
  1158. }
  1159. }
  1160. }
  1161. documentlock.Dispose();
  1162. traction.Commit();
  1163. }
  1164. return TValue;
  1165. }
  1166. }
  1167. }