工具箱相关
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMCgis_Basicfunction.cs 101KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using GrxCAD.Runtime;
  6. using GrxCAD.Geometry;
  7. using GrxCAD.DatabaseServices;
  8. using GrxCAD.ApplicationServices;
  9. using GrxCAD.EditorInput;
  10. using GrxCAD.Internal;
  11. using System.Windows.Forms;
  12. namespace HCTools
  13. {
  14. class BasicFunction
  15. {
  16. /// <summary>
  17. /// 根据点坐标创建圆形标记
  18. /// </summary>
  19. public void makeflag(double x, double y, double z, double radius, string layername)
  20. {
  21. Database database = HostApplicationServices.WorkingDatabase;
  22. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  23. using (Transaction traction = database.TransactionManager.StartTransaction())
  24. {
  25. BlockTable blocktable = traction.GetObject(database.BlockTableId,
  26. OpenMode.ForWrite) as BlockTable;
  27. BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
  28. OpenMode.ForWrite) as BlockTableRecord;
  29. Circle circ = new Circle();
  30. circ.Center = new Point3d(x, y, z);
  31. circ.Radius = radius;
  32. circ.Normal = new Vector3d(0, 0, 1);
  33. circ.SetDatabaseDefaults();
  34. circ.Layer = layername;
  35. blocktablerecord.AppendEntity(circ);
  36. traction.AddNewlyCreatedDBObject(circ, true);
  37. traction.Commit();
  38. doclock.Dispose();
  39. traction.Dispose();
  40. }
  41. }
  42. /// <summary>
  43. /// 获取等高线
  44. /// </summary>
  45. public static ObjectId[] getHeight(string LayerName)
  46. {
  47. ObjectId[] ids = null;
  48. Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  49. Database db = doc.Database;
  50. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  51. TypedValue[] value = new TypedValue[]
  52. {
  53. new TypedValue((int)DxfCode.LayerName,LayerName),
  54. new TypedValue((int)DxfCode.Start,"LWPOLYLINE")
  55. };//设置筛选条件
  56. SelectionFilter filter = new SelectionFilter(value);
  57. //选择区域中全部对象
  58. //PromptSelectionResult psr = ed.SelectAll(filter);
  59. // 要求在图形区域中手动选择对象
  60. PromptSelectionResult psr = ed.GetSelection(filter);
  61. if (psr.Status == PromptStatus.OK)
  62. {
  63. using (Transaction trans = db.TransactionManager.StartTransaction())
  64. {
  65. SelectionSet ss = psr.Value;
  66. ids = ss.GetObjectIds();
  67. trans.Commit();
  68. }
  69. }
  70. return ids;
  71. }
  72. /// <summary>
  73. /// 获取二维多段线和多段线
  74. /// </summary>
  75. public static ObjectId[] getPll()
  76. {
  77. ObjectId[] ids = null;
  78. Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  79. Database db = doc.Database;
  80. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  81. TypedValue[] value = new TypedValue[]
  82. {
  83. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE"),
  84. };//设置筛选条件
  85. SelectionFilter filter = new SelectionFilter(value);
  86. //选择区域中全部对象
  87. //PromptSelectionResult psr = ed.SelectAll(filter);
  88. // 要求在图形区域中手动选择对象
  89. PromptSelectionResult psr = ed.GetSelection(filter);
  90. if (psr.Status == PromptStatus.OK)
  91. {
  92. using (Transaction trans = db.TransactionManager.StartTransaction())
  93. {
  94. SelectionSet ss = psr.Value;
  95. ids = ss.GetObjectIds();
  96. trans.Commit();
  97. }
  98. }
  99. return ids;
  100. }
  101. /// <summary>
  102. /// 根据Id获取实体
  103. /// </summary>
  104. public static Entity GetDBObject(ObjectId i)
  105. {
  106. //Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  107. //Database db = doc.Database;
  108. Database db = HostApplicationServices.WorkingDatabase;
  109. Entity ent = null;
  110. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  111. using (Transaction tr = db.TransactionManager.StartTransaction())
  112. {
  113. ent = (Entity)tr.GetObject(i, OpenMode.ForRead, true);
  114. tr.Commit();
  115. }
  116. doclock.Dispose();
  117. return ent;
  118. }
  119. /// <summary>
  120. /// 根据编号判断地物类型
  121. /// </summary>
  122. //2022-7-25-qyx改
  123. public static string get_TypeName(string key)
  124. {
  125. string name = "";
  126. //switch (key)
  127. //{
  128. // case "011":
  129. // name = "水田";
  130. // break;
  131. // case "012":
  132. // name = "水浇地";
  133. // break;
  134. // case "013":
  135. // name = "旱地";
  136. // break;
  137. // case "021":
  138. // name = "果园";
  139. // break;
  140. // case "022":
  141. // name = "茶园";
  142. // break;
  143. // case "023":
  144. // name = "其他园地";
  145. // break;
  146. // case "031":
  147. // name = "有林地";
  148. // break;
  149. // case "032":
  150. // name = "灌木林地";
  151. // break;
  152. // case "033":
  153. // name = "其他林地";
  154. // break;
  155. // case "041":
  156. // name = "天然牧草地";
  157. // break;
  158. // case "042":
  159. // name = "人工牧草地";
  160. // break;
  161. // case "043":
  162. // name = "其他草地";
  163. // break;
  164. // case "051":
  165. // name = "批发零售用地";
  166. // break;
  167. // case "052":
  168. // name = "住宿餐饮用地";
  169. // break;
  170. // case "053":
  171. // name = "商务金融用地";
  172. // break;
  173. // case "054":
  174. // name = "其他商服用地";
  175. // break;
  176. // case "061":
  177. // name = "工业用地";
  178. // break;
  179. // case "062":
  180. // name = "采矿用地";
  181. // break;
  182. // case "063":
  183. // name = "仓储用地";
  184. // break;
  185. // case "071":
  186. // name = "城镇住宅用地";
  187. // break;
  188. // case "072":
  189. // name = "农村宅基地";
  190. // break;
  191. // case "081":
  192. // name = "机关团体用地";
  193. // break;
  194. // case "082":
  195. // name = "新闻出版用地";
  196. // break;
  197. // case "083":
  198. // name = "科教用地";
  199. // break;
  200. // case "084":
  201. // name = "医卫慈善用地";
  202. // break;
  203. // case "085":
  204. // name = "文体娱乐用地";
  205. // break;
  206. // case "086":
  207. // name = "公共设施用地";
  208. // break;
  209. // case "087":
  210. // name = "公园与绿地";
  211. // break;
  212. // case "088":
  213. // name = "风景名胜设施用地";
  214. // break;
  215. // case "091":
  216. // name = "军事设施用地";
  217. // break;
  218. // case "092":
  219. // name = "使领馆用地";
  220. // break;
  221. // case "093":
  222. // name = "监教场所用地";
  223. // break;
  224. // case "094":
  225. // name = "宗教用地";
  226. // break;
  227. // case "095":
  228. // name = "殡葬用地";
  229. // break;
  230. // case "101":
  231. // name = "铁路用地";
  232. // break;
  233. // case "102":
  234. // name = "公路用地";
  235. // break;
  236. // case "103":
  237. // name = "街巷用地";
  238. // break;
  239. // case "104":
  240. // name = "农村道路";
  241. // break;
  242. // case "105":
  243. // name = "机场用地";
  244. // break;
  245. // case "106":
  246. // name = "港口码头用地";
  247. // break;
  248. // case "107":
  249. // name = "管道运输用地";
  250. // break;
  251. // case "111":
  252. // name = "河流水面";
  253. // break;
  254. // case "112":
  255. // name = "湖泊水面";
  256. // break;
  257. // case "113":
  258. // name = "水库水面";
  259. // break;
  260. // case "114":
  261. // name = "坑塘水面";
  262. // break;
  263. // case "115":
  264. // name = "沿海滩涂";
  265. // break;
  266. // case "116":
  267. // name = "内陆滩涂";
  268. // break;
  269. // case "117":
  270. // name = "沟渠";
  271. // break;
  272. // case "118":
  273. // name = "水工建筑用地";
  274. // break;
  275. // case "119":
  276. // name = "冰川及永久积雪";
  277. // break;
  278. // case "121":
  279. // name = "空闲地";
  280. // break;
  281. // case "122":
  282. // name = "设施农用地";
  283. // break;
  284. // case "123":
  285. // name = "田坎";
  286. // break;
  287. // case "124":
  288. // name = "盐碱地";
  289. // break;
  290. // case "125":
  291. // name = "沼泽地";
  292. // break;
  293. // case "126":
  294. // name = "沙地";
  295. // break;
  296. // case "127":
  297. // name = "裸地";
  298. // break;
  299. // default:
  300. // break;
  301. //}
  302. // 编号不同
  303. switch (key)
  304. {
  305. case "0101":
  306. name = "水田";
  307. break;
  308. case "0102":
  309. name = "水浇地";
  310. break;
  311. case "0103":
  312. name = "旱地";
  313. break;
  314. case "0201":
  315. name = "果园";
  316. break;
  317. case "0202":
  318. name = "茶园";
  319. break;
  320. case "0203":
  321. name = "橡胶园";
  322. break;
  323. case "0204":
  324. name = "其他园地";
  325. break;
  326. case "0301":
  327. name = "乔木林地";
  328. break;
  329. case "0302":
  330. name = "竹林地";
  331. break;
  332. case "0303":
  333. name = "红树林地";
  334. break;
  335. case "0304":
  336. name = "森林沼泽";
  337. break;
  338. case "0305":
  339. name = "灌木林地";
  340. break;
  341. case "0306":
  342. name = "灌丛沼泽";
  343. break;
  344. case "0307":
  345. name = "其他林地";
  346. break;
  347. case "0401":
  348. name = "天然牧草地";
  349. break;
  350. case "0402":
  351. name = "沼泽草地";
  352. break;
  353. case "0403":
  354. name = "人工牧草地";
  355. break;
  356. case "0404":
  357. name = "其他草地";
  358. break;
  359. case "0501":
  360. name = "零售商业用地";
  361. break;
  362. case "0502":
  363. name = "批发市场用地";
  364. break;
  365. case "0503":
  366. name = "餐饮用地";
  367. break;
  368. case "0504":
  369. name = "旅馆用地";
  370. break;
  371. case "0505":
  372. name = "商业金融用地";
  373. break;
  374. case "0506":
  375. name = "娱乐用地";
  376. break;
  377. case "0507":
  378. name = "其他商服用地";
  379. break;
  380. case "0601":
  381. name = "工业用地";
  382. break;
  383. case "0602":
  384. name = "采矿用地";
  385. break;
  386. case "0603":
  387. name = "盐田";
  388. break;
  389. case "0604":
  390. name = "仓储用地";
  391. break;
  392. case "0701":
  393. name = "城镇住宅用地";
  394. break;
  395. case "0702":
  396. name = "农村宅基地";
  397. break;
  398. case "0801":
  399. name = "机关团体用地";
  400. break;
  401. case "0802":
  402. name = "新闻出版用地";
  403. break;
  404. case "0803":
  405. name = "教育用地";
  406. break;
  407. case "0804":
  408. name = "科研用地";
  409. break;
  410. case "0805":
  411. name = "医疗卫生用地";
  412. break;
  413. case "0806":
  414. name = "社会福利用地";
  415. break;
  416. case "0807":
  417. name = "文化设施用地";
  418. break;
  419. case "0808":
  420. name = "体育用地";
  421. break;
  422. case "0809":
  423. name = "公用设施用地";
  424. break;
  425. case "0810":
  426. name = "公园与绿地";
  427. break;
  428. case "0901":
  429. name = "军事设施用地";
  430. break;
  431. case "0902":
  432. name = "使领馆用地";
  433. break;
  434. case "0903":
  435. name = "监教场所用地";
  436. break;
  437. case "0904":
  438. name = "宗教用地";
  439. break;
  440. case "0905":
  441. name = "殡葬用地";
  442. break;
  443. case "0906":
  444. name = "风景名胜设施用地";
  445. break;
  446. case "1001":
  447. name = "铁路用地";
  448. break;
  449. case "1002":
  450. name = "轨道交通用地";
  451. break;
  452. case "1003":
  453. name = "公路用地";
  454. break;
  455. case "1004":
  456. name = "城镇村道路用地";
  457. break;
  458. case "1005":
  459. name = "交通服务场所用地";
  460. break;
  461. case "1006":
  462. name = "农村道路";
  463. break;
  464. case "1007":
  465. name = "机场用地";
  466. break;
  467. case "1008":
  468. name = "港口码头用地";
  469. break;
  470. case "1009":
  471. name = "管道运输用地";
  472. break;
  473. case "1101":
  474. name = "河流水面";
  475. break;
  476. case "1102":
  477. name = "湖泊水面";
  478. break;
  479. case "1103":
  480. name = "水库水面";
  481. break;
  482. case "1104":
  483. name = "坑塘水面";
  484. break;
  485. case "1105":
  486. name = "沿海滩涂";
  487. break;
  488. case "1106":
  489. name = "内陆滩涂";
  490. break;
  491. case "1107":
  492. name = "沟渠";
  493. break;
  494. case "1108":
  495. name = "沼泽地";
  496. break;
  497. case "1109":
  498. name = "水工建筑用地";
  499. break;
  500. case "1110":
  501. name = "冰川及永久积雪";
  502. break;
  503. case "1201":
  504. name = "空闲地";
  505. break;
  506. case "1202":
  507. name = "设施农用地";
  508. break;
  509. case "1203":
  510. name = "田坎";
  511. break;
  512. case "1204":
  513. name = "盐碱地";
  514. break;
  515. case "1205":
  516. name = "沙地";
  517. break;
  518. case "1206":
  519. name = "裸土地";
  520. break;
  521. case "1207":
  522. name = "裸岩石砾地";
  523. break;
  524. default:
  525. break;
  526. }
  527. return name;
  528. }
  529. public static ObjectId AddObj(Document doc,Entity ent)
  530. {
  531. ObjectId id = new ObjectId();
  532. Database database = doc.Database;
  533. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  534. using (Transaction traction = database.TransactionManager.StartTransaction())
  535. {
  536. BlockTable blocktable = traction.GetObject(database.BlockTableId,OpenMode.ForWrite) as BlockTable;
  537. BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
  538. OpenMode.ForWrite) as BlockTableRecord;
  539. blocktablerecord.AppendEntity(ent);
  540. traction.AddNewlyCreatedDBObject(ent, true);
  541. id = ent.ObjectId;
  542. traction.Commit();
  543. doclock.Dispose();
  544. }
  545. return id;
  546. }
  547. /// <summary>
  548. /// 添加命令
  549. /// </summary>
  550. //public void addCommand()
  551. //{
  552. // MainClass main = new MainClass();
  553. // Utils.AddCommand("COMMAND1", "PLError", "ТЕСТ1", CommandFlags.Modal, main.PLError);
  554. // Utils.AddCommand("COMMAND1", "PLOverlap", "ТЕСТ2", CommandFlags.Modal, main.PLOverlap);
  555. // Utils.AddCommand("COMMAND1", "Report", "ТЕСТ3", CommandFlags.Modal, main.Report);
  556. // Utils.AddCommand("COMMAND1", "Fills", "ТЕСТ4", CommandFlags.Modal, main.Fill);
  557. // Utils.AddCommand("COMMAND1", "BATChange", "ТЕСТ5", CommandFlags.Modal, main.BATChange);
  558. // Utils.AddCommand("COMMAND1", "PtCheck", "ТЕСТ6", CommandFlags.Modal, main.PointCheck);
  559. // Utils.AddCommand("COMMAND1", "Hierarchy", "ТЕСТ7", CommandFlags.Modal, main.Hierarchy);
  560. // Utils.AddCommand("COMMAND1", "CLCheck", "ТЕСТ8", CommandFlags.Modal, main.CLCheck);
  561. // //Utils.AddCommand("COMMAND1", "Connect", "ТЕСТ9", CommandFlags.Modal, main.Connect);
  562. // Utils.AddCommand("COMMAND1", "SelfIntersect", "ТЕСТ10", CommandFlags.Modal, main.SelfIntersect);
  563. // Utils.AddCommand("COMMAND1", "EachIntersect", "ТЕСТ11", CommandFlags.Modal, main.EachIntersect);
  564. // Utils.AddCommand("COMMAND1", "combFace", "ТЕСТ12", CommandFlags.Modal, main.combF);
  565. // Utils.AddCommand("COMMAND1", "splitFace", "ТЕСТ13", CommandFlags.Modal, main.splitF);
  566. // Utils.AddCommand("COMMAND1", "pickupPoint", "ТЕСТ14", CommandFlags.Modal, main.pickupP);
  567. // Utils.AddCommand("COMMAND1", "FakeCheck", "ТЕСТ15", CommandFlags.Modal, main.FFake);
  568. // Utils.AddCommand("COMMAND1", "HangCheck", "ТЕСТ16", CommandFlags.Modal, main.HFake);
  569. // Utils.AddCommand("COMMAND1", "SlopeLine", "ТЕСТ17", CommandFlags.Modal, main.SlpLine);
  570. // Utils.AddCommand("COMMAND1", "SheetMap", "ТЕСТ18", CommandFlags.Modal, main.SheetMap);
  571. //}
  572. /// <summary>
  573. /// 删除命令
  574. /// </summary>
  575. //public void deleteCommand()
  576. //{
  577. // Utils.RemoveCommand("PLError", "TEST1");
  578. // Utils.RemoveCommand("PLOverlap", "TEST2");
  579. // Utils.RemoveCommand("Report", "TEST3");
  580. // Utils.RemoveCommand("Fills", "TEST4");
  581. // Utils.RemoveCommand("BATChange", "TEST5");
  582. // Utils.RemoveCommand("PtCheck", "TEST6");
  583. // Utils.RemoveCommand("Hierarchy", "TEST7");
  584. // Utils.RemoveCommand("CLCheck", "TEST8");
  585. // //Utils.RemoveCommand("Connect", "TEST9");
  586. // Utils.RemoveCommand("SelfIntersect", "TEST10");
  587. // Utils.RemoveCommand("EachIntersect", "TEST11");
  588. // Utils.RemoveCommand("combFace", "TEST12");
  589. // Utils.RemoveCommand("splitFace", "TEST13");
  590. // Utils.RemoveCommand("pickupPoint", "TEST14");
  591. // Utils.RemoveCommand("FakeCheck", "TEST15");
  592. // Utils.RemoveCommand("HangCheck", "TEST16");
  593. // Utils.RemoveCommand("SlopeLine", "TEST17");
  594. // Utils.RemoveCommand("SheetMap", "TEST18");
  595. //}
  596. }
  597. /// <summary>
  598. /// 对图层的操作处理,包括新建图层、
  599. /// 把指定图层设置为当前图层和检查是否包含某个图层名
  600. /// </summary>
  601. class LayerControl
  602. {
  603. /// <summary>
  604. /// 创建高程点错误标记层
  605. /// </summary>
  606. /// <param name="layername">要创建的图层的名字</param>
  607. /// <param name="colo">RGB三原色</param>
  608. public void creatlayer(string layername, colorgb colo)
  609. {
  610. Database database = GrxCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
  611. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  612. Transaction traction = database.TransactionManager.StartTransaction();
  613. LayerTable lt = traction.GetObject(database.LayerTableId, OpenMode.ForWrite) as LayerTable;
  614. try
  615. {
  616. LayerTableRecord layertablerecord = new LayerTableRecord();
  617. layertablerecord.Name = layername;//设置层表记录的名字
  618. layertablerecord.Color = GrxCAD.Colors.Color.FromRgb(colo.red, colo.green, colo.blue);//为层表记录赋颜色紫色
  619. //layertablerecord.Color = GrxCAD.Colors.Color.FromColor(System.Drawing.Color.Magenta);
  620. lt.Add(layertablerecord);
  621. traction.AddNewlyCreatedDBObject(layertablerecord, true);
  622. traction.Commit();
  623. }
  624. catch (GrxCAD.Runtime.Exception)
  625. {
  626. traction.Abort();
  627. }
  628. finally
  629. {
  630. traction.Dispose();
  631. doclock.Dispose();
  632. }
  633. }
  634. /// <summary>
  635. /// 将指定图层设置为当前图层
  636. /// </summary>
  637. /// <param name="layername">要设置为当前图层的图层名字</param>
  638. public void movelayertofront(string layername)
  639. {
  640. Database database = GrxCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
  641. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  642. Transaction traction = database.TransactionManager.StartTransaction();
  643. try
  644. {
  645. LayerTable layertable = traction.GetObject(database.LayerTableId, OpenMode.ForRead) as LayerTable;
  646. database.Clayer = layertable[layername];//把图层选为当前图层
  647. traction.Commit();
  648. }
  649. catch (GrxCAD.Runtime.Exception)
  650. {
  651. traction.Abort();
  652. }
  653. finally
  654. {
  655. traction.Dispose();
  656. doclock.Dispose();
  657. }
  658. }
  659. /// <summary>
  660. /// 判断所命图层名是否已经存在
  661. /// </summary>
  662. /// <param name="layername">要判断的图层名字</param>
  663. /// <returns>返回true表示在层表中存在要判断的图层名,
  664. /// 返回false表示层表中不存在判断的图层名</returns>
  665. public bool haslayername(string layername)
  666. {
  667. Database database = GrxCAD.DatabaseServices.HostApplicationServices.WorkingDatabase;
  668. using (Transaction traction = database.TransactionManager.StartTransaction())
  669. {
  670. LayerTable lt = traction.GetObject(database.LayerTableId, OpenMode.ForRead) as LayerTable;
  671. if (lt.Has(layername))
  672. {
  673. traction.Commit();
  674. return true;
  675. }
  676. else
  677. {
  678. traction.Commit();
  679. return false;
  680. }
  681. }
  682. }
  683. public void clear(string layername)
  684. {
  685. Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  686. Database database = HostApplicationServices.WorkingDatabase;
  687. DocumentLock documentlock = null;
  688. Transaction traction = null;
  689. try
  690. {
  691. traction = database.TransactionManager.StartTransaction();
  692. documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  693. BlockTable blocktable = traction.GetObject(database.BlockTableId,
  694. OpenMode.ForWrite) as BlockTable;
  695. BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
  696. OpenMode.ForWrite) as BlockTableRecord;
  697. Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  698. TypedValue[] typedvalue = new TypedValue[2];
  699. typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "Circle"), 0);
  700. typedvalue.SetValue(new TypedValue((int)DxfCode.LayerName, "Cir"), 1);
  701. SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
  702. PromptSelectionResult select = editor.SelectAll(selectionfilter);
  703. if (select.Status == PromptStatus.OK)
  704. {
  705. SelectionSet set = select.Value;
  706. ObjectId[] obj = new ObjectId[set.Count];
  707. obj = set.GetObjectIds();
  708. for (int i = 0; i < obj.Length; i++)
  709. {
  710. ObjectId objid = obj[i];
  711. Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForWrite);
  712. entity.Erase();
  713. }
  714. }
  715. traction.Commit();
  716. }
  717. catch (GrxCAD.Runtime.Exception)
  718. {
  719. }
  720. }
  721. }
  722. /// <summary>
  723. /// RGB三原色
  724. /// </summary>
  725. public struct colorgb
  726. {
  727. public byte red;
  728. public byte green;
  729. public byte blue;
  730. public colorgb(byte r, byte g, byte b)
  731. {
  732. this.red = r;
  733. this.green = g;
  734. this.blue = b;
  735. }
  736. }
  737. /// <summary>
  738. /// 创建图廓
  739. /// </summary>
  740. class CreateSheetMap
  741. {
  742. private Point3d LB;
  743. private Point3d LT;
  744. private Point3d RB;
  745. private Point3d RT;
  746. private List<List<Point3d>> TKpts = new List<List<Point3d>>();
  747. double dist = 200; //格网间距
  748. string layername = "9800";
  749. string Number; //图幅号
  750. string Left_Number;
  751. string Right_Number;
  752. string Leftup_Number;
  753. string Leftdown_Number;
  754. string Rightup_Number;
  755. string Rightdown_Number;
  756. string Centrolup_Number;
  757. string Centroldown_Number;
  758. public void create()
  759. {
  760. int BLC = TKInfo.BLC;
  761. if (BLC == 1000)
  762. {
  763. dist = 100;
  764. }
  765. if (BLC == 500)
  766. {
  767. dist = 50;
  768. }
  769. getinfo();
  770. for (int i = 0; i < TKpts.Count; i++)
  771. {
  772. LB = TKpts[i][0];
  773. LT = TKpts[i][1];
  774. RB = TKpts[i][2];
  775. RT = TKpts[i][3];
  776. //左编号
  777. Point3d p1 = new Point3d(LB.X - dist * 5 - 100, LB.Y - 100, 0);
  778. Point3d p2 = new Point3d(LT.X + 50, LT.Y + 50, 0);
  779. Left_Number = GetNumber(p1, p2);
  780. //右编号
  781. p1 = new Point3d(RT.X + dist * 5 + 100, RT.Y + 100, 0);
  782. p2 = new Point3d(RB.X - 50, RB.Y - 50, 0);
  783. Right_Number = GetNumber(p1, p2);
  784. //左上编号
  785. p1 = new Point3d(LT.X - dist * 5 - 100, LT.Y + dist * 5 + 100, 0);
  786. p2 = new Point3d(LT.X + 50, LT.Y - 50, 0);
  787. Leftup_Number = GetNumber(p1, p2);
  788. //左下编号
  789. p1 = new Point3d(LB.X - dist * 5 - 100, LB.Y - dist * 5 - 100, 0);
  790. p2 = new Point3d(LB.X + 50, LB.Y + 50, 0);
  791. Leftdown_Number = GetNumber(p1, p2);
  792. //中上编号
  793. p1 = new Point3d(LT.X - 100, LT.Y - 100, 0);
  794. p2 = new Point3d(RT.X + 50, RT.Y + dist * 5 + 50, 0);
  795. Centrolup_Number = GetNumber(p1, p2);
  796. //中下编号
  797. p1 = new Point3d(LB.X - 100, LB.Y - dist * 5 - 100, 0);
  798. p2 = new Point3d(RB.X + 50, RB.Y + 50, 0);
  799. Centroldown_Number = GetNumber(p1, p2);
  800. //右上编号
  801. p1 = new Point3d(RT.X - 100, RT.Y - 100, 0);
  802. p2 = new Point3d(RT.X + dist * 5 + 50, RT.Y + dist * 5 + 50, 0);
  803. Rightup_Number = GetNumber(p1, p2);
  804. //右下编号
  805. p1 = new Point3d(RB.X - 100, RB.Y + 100, 0);
  806. p2 = new Point3d(RB.X + dist * 5 + 50, RB.Y - dist * 5 - 50, 0);
  807. Rightdown_Number = GetNumber(p1, p2);
  808. //图幅号
  809. p1 = new Point3d(LB.X - 100, LB.Y - 100, 0);
  810. p2 = new Point3d(RT.X + 100, RT.Y + 100, 0);
  811. Number = GetNumber(p1, p2);
  812. //新建一个dwg
  813. string templatePath = "acad.dwt";
  814. DocumentCollection documentcoll = GrxCAD.ApplicationServices.Application.DocumentManager;
  815. Document document = documentcoll.Add(templatePath);
  816. Database database = document.Database;
  817. LayerControl layerscontrol = new LayerControl();
  818. if (layerscontrol.haslayername(layername) == false)
  819. {
  820. colorgb col = new colorgb(255, 0, 0);
  821. layerscontrol.creatlayer(layername, col);
  822. layerscontrol.movelayertofront(layername);
  823. }
  824. else
  825. layerscontrol.movelayertofront(layername);
  826. createTextStyle();
  827. draw();
  828. zoom();
  829. //database.SaveAs(TKInfo.SV + "\\" + Number.ToString() + ".dwg", DwgVersion.AC1024);
  830. database.SaveAs(TKInfo.SV + "\\" + Number.ToString() + ".dwg", true, DwgVersion.AC1021, database.SecurityParameters);
  831. //document.CloseAndSave(Number.ToString() + ".dwg");
  832. document.CloseAndDiscard();
  833. }
  834. }
  835. private void getinfo()
  836. {
  837. Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  838. Database database = HostApplicationServices.WorkingDatabase;
  839. using (Transaction traction = database.TransactionManager.StartTransaction())
  840. {
  841. DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  842. BlockTable blocktable = traction.GetObject(database.BlockTableId,
  843. OpenMode.ForRead) as BlockTable;
  844. Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  845. TypedValue[] typedvalue = new TypedValue[1];
  846. typedvalue.SetValue(new TypedValue((int)DxfCode.Start, "3dFace,LWPolyline"), 0);
  847. SelectionFilter selectionfilter = new SelectionFilter(typedvalue);
  848. PromptSelectionResult psr = editor.GetSelection(selectionfilter);
  849. if (psr.Status == PromptStatus.OK)
  850. {
  851. SelectionSet selectionset = psr.Value;
  852. ObjectId[] obj = new ObjectId[selectionset.Count];
  853. obj = selectionset.GetObjectIds();
  854. for (int i = 0; i < obj.Length; i++)
  855. {
  856. ObjectId objid = obj[i];
  857. Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead);
  858. Point3dCollection coll = new Point3dCollection();
  859. if (entity is Face)
  860. {
  861. Face f = entity as Face;
  862. f.GetStretchPoints(coll);
  863. }
  864. else if (entity is Polyline)
  865. {
  866. Polyline line = entity as Polyline;
  867. line.GetStretchPoints(coll);
  868. }
  869. LB = coll[0];
  870. LT = coll[0];
  871. RB = coll[0];
  872. RT = coll[0];
  873. for (int ii = 1; ii < coll.Count; ii++)
  874. {
  875. double x = coll[ii].X;
  876. double y = coll[ii].Y;
  877. if (x <= LB.X && y <= LB.Y)
  878. {
  879. LB = coll[ii];
  880. }
  881. if (x <= LT.X && y >= LT.Y)
  882. {
  883. LT = coll[ii];
  884. }
  885. if (x >= RB.X && y <= RB.Y)
  886. {
  887. RB = coll[ii];
  888. }
  889. if (x >= RT.X && y >= RT.Y)
  890. {
  891. RT = coll[ii];
  892. }
  893. }
  894. List<Point3d> temp = new List<Point3d>();
  895. temp.Add(LB);
  896. temp.Add(LT);
  897. temp.Add(RB);
  898. temp.Add(RT);
  899. TKpts.Add(temp);
  900. }
  901. }
  902. traction.Commit();
  903. documentlock.Dispose();
  904. }
  905. }
  906. private void draw()
  907. {
  908. int BLC = TKInfo.BLC;
  909. double len = 10; //分幅框标长度
  910. double D22 = 22; //内图廓线和外图廓线距离
  911. double D1 = 1.0; //间距为1
  912. double D2 = 2.0; //间距为2
  913. double D3 = 3.0; //间距为3
  914. double D4 = 4.0; //间距为4
  915. double D4_8 = 4.8; //间距为4.8
  916. double D5 = 5.0; //间距为5
  917. double D6 = 6.0; //间距为6
  918. double D7 = 7.0; //间距为7
  919. double D8 = 8.0; //间距为8
  920. double D10 = 10.0; //间距为10
  921. double D12 = 12.0; //间距为12
  922. double D140 = 140; //右下角附注
  923. double D90 = 90;
  924. double D48 = 48;
  925. double dist1 = 1.625; //接图表第一格填充间距
  926. double dist2 = Math.Sqrt(8); //接图表填充间距
  927. if (BLC == 1000)
  928. {
  929. len = len / 2; //分幅框标长度
  930. D22 = D22 / 2; //内图廓线和外图廓线距离
  931. D1 = D1 / 2; //间距为1
  932. D2 = D2 / 2; //间距为2
  933. D3 = D3 / 2; //间距为3
  934. D4 = D4 / 2; //间距为4
  935. D4_8 = D4_8 / 2; //间距为4.8
  936. D5 = D5 / 2; //间距为5
  937. D6 = D6 / 2; //间距为6
  938. D7 = D7 / 2; //间距为7
  939. D8 = D8 / 2; //间距为8
  940. D10 = D10 / 2; //间距为10
  941. D12 = D12 / 2; //间距为12
  942. D140 = D140 / 2; //右下角附注
  943. D90 = D90 / 2;
  944. D48 = D48 / 2;
  945. dist1 = dist1 / 2; //接图表第一格填充间距
  946. dist2 = dist2 / 2; //接图表填充间距
  947. }
  948. if (BLC == 500)
  949. {
  950. len = len / 4; //分幅框标长度
  951. D22 = D22 / 4; //内图廓线和外图廓线距离
  952. D1 = D1 / 4; //间距为1
  953. D2 = D2 / 4; //间距为2
  954. D3 = D3 / 4; //间距为3
  955. D4 = D4 / 4; //间距为4
  956. D4_8 = D4_8 / 4; //间距为4.8
  957. D5 = D5 / 4; //间距为5
  958. D6 = D6 / 4; //间距为6
  959. D7 = D7 / 4; //间距为7
  960. D8 = D8 / 4; //间距为8
  961. D10 = D10 / 4; //间距为10
  962. D12 = D12 / 4; //间距为12
  963. D140 = D140 / 4; //右下角附注
  964. D90 = D90 / 4;
  965. D48 = D48 / 4;
  966. dist1 = dist1 / 4; //接图表第一格填充间距
  967. dist2 = dist2 / 4; //接图表填充间距
  968. }
  969. ObjectId HZ = gettextstyleID("HZ");
  970. ObjectId st = gettextstyleID("st");
  971. ObjectId ht = gettextstyleID("ht");
  972. ObjectId Standard = gettextstyleID("Standard");
  973. ObjectId ID12 = gettextstyleID("12");
  974. ObjectId ID123 = gettextstyleID("123");
  975. //ObjectId XDXT = gettextstyleID("细等线体");
  976. //ObjectId ZDXT = gettextstyleID("中等线体");
  977. //ObjectId ST = gettextstyleID("宋体");
  978. double xx1, yy1;
  979. double xx2, yy2;
  980. int DH;
  981. Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  982. Database database = HostApplicationServices.WorkingDatabase;
  983. Transaction traction = database.TransactionManager.StartTransaction();
  984. DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  985. BlockTable blocktable = traction.GetObject(database.BlockTableId,
  986. OpenMode.ForWrite) as BlockTable;
  987. BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
  988. OpenMode.ForWrite) as BlockTableRecord;
  989. Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  990. //try
  991. //{
  992. //内图廓
  993. //左边线
  994. Point3dCollection In1 = new Point3dCollection();
  995. In1.Add(new Point3d(LT.X, LT.Y + D22 + D1, 0));
  996. In1.Add(new Point3d(LB.X, LB.Y - D22 - D1, 0));
  997. Polyline2d LeftLine = new Polyline2d(Poly2dType.SimplePoly, In1, 0, false, 0, 0, null);
  998. //LeftLine.Color = GrxCAD.Colors.Color.FromColor(System.Drawing.Color.Red);
  999. LeftLine.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1000. LeftLine.Layer = layername;
  1001. LeftLine.SetDatabaseDefaults();
  1002. blocktablerecord.AppendEntity(LeftLine);
  1003. traction.AddNewlyCreatedDBObject(LeftLine, true);
  1004. //下边线
  1005. Point3dCollection In2 = new Point3dCollection();
  1006. In2.Add(new Point3d(LB.X - D22 - D1, LB.Y, 0));
  1007. In2.Add(new Point3d(RB.X + D22 + D1, RB.Y, 0));
  1008. Polyline2d LowLine = new Polyline2d(Poly2dType.SimplePoly, In2, 0, false, 0, 0, null);
  1009. LowLine.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1010. LowLine.SetDatabaseDefaults();
  1011. blocktablerecord.AppendEntity(LowLine);
  1012. traction.AddNewlyCreatedDBObject(LowLine, true);
  1013. //右边线
  1014. Point3dCollection In3 = new Point3dCollection();
  1015. In3.Add(new Point3d(RT.X, RT.Y + D22 + D1, 0));
  1016. In3.Add(new Point3d(RB.X, RB.Y - D22 - D1, 0));
  1017. Polyline2d RightLine = new Polyline2d(Poly2dType.SimplePoly, In3, 0, false, 0, 0, null);
  1018. RightLine.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1019. RightLine.Layer = layername;
  1020. RightLine.SetDatabaseDefaults();
  1021. blocktablerecord.AppendEntity(RightLine);
  1022. traction.AddNewlyCreatedDBObject(RightLine, true);
  1023. //上边线
  1024. Point3dCollection In4 = new Point3dCollection();
  1025. In4.Add(new Point3d(LT.X - D22 - D1, LT.Y, 0));
  1026. In4.Add(new Point3d(RT.X + D22 + D1, RT.Y, 0));
  1027. Polyline2d TOPLine = new Polyline2d(Poly2dType.SimplePoly, In4, 0, false, 0, 0, null);
  1028. TOPLine.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1029. TOPLine.Layer = layername;
  1030. TOPLine.SetDatabaseDefaults();
  1031. blocktablerecord.AppendEntity(TOPLine);
  1032. traction.AddNewlyCreatedDBObject(TOPLine, true);
  1033. //外图廓
  1034. Point3dCollection Outcoll = new Point3dCollection();
  1035. Outcoll.Add(new Point3d(LT.X - D22 - D1, LT.Y + D22 + D1, 0));
  1036. Outcoll.Add(new Point3d(LB.X - D22 - D1, LB.Y - D22 - D1, 0));
  1037. Outcoll.Add(new Point3d(RB.X + D22 + D1, RB.Y - D22 - D1, 0));
  1038. Outcoll.Add(new Point3d(RT.X + D22 + D1, RT.Y + D22 + D1, 0));
  1039. Outcoll.Add(new Point3d(LT.X - D22 - D1, LT.Y + D22 + D1, 0));
  1040. Polyline2d line = new Polyline2d(Poly2dType.SimplePoly, Outcoll, 0, true, D2, D2, null);
  1041. line.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1042. line.Layer = layername;
  1043. line.SetDatabaseDefaults();
  1044. blocktablerecord.AppendEntity(line);
  1045. traction.AddNewlyCreatedDBObject(line, true);
  1046. line.UpgradeOpen();
  1047. line.ConstantWidth = D2;
  1048. //分幅框标
  1049. for (int i = 1; i <= 4; i++)
  1050. {
  1051. for (int j = 1; j <= 4; j++)
  1052. {
  1053. //中心点
  1054. double x = LB.X + i * dist;
  1055. double y = LB.Y + j * dist;
  1056. //横线
  1057. Point3d p1 = new Point3d(x - len, y, 0);
  1058. Point3d p2 = new Point3d(x + len, y, 0);
  1059. Point3dCollection kb = new Point3dCollection();
  1060. kb.Add(p1);
  1061. kb.Add(p2);
  1062. Polyline2d kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null);
  1063. kbline.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1064. kbline.Layer = layername;
  1065. kbline.SetDatabaseDefaults();
  1066. blocktablerecord.AppendEntity(kbline);
  1067. traction.AddNewlyCreatedDBObject(kbline, true);
  1068. //竖线
  1069. p1 = new Point3d(x, y - len, 0);
  1070. p2 = new Point3d(x, y + len, 0);
  1071. kb = new Point3dCollection();
  1072. kb.Add(p1);
  1073. kb.Add(p2);
  1074. kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null);
  1075. kbline.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1076. kbline.Layer = layername;
  1077. kbline.SetDatabaseDefaults();
  1078. blocktablerecord.AppendEntity(kbline);
  1079. traction.AddNewlyCreatedDBObject(kbline, true);
  1080. }
  1081. }
  1082. for (int i = 1; i <= 4; i++)
  1083. {
  1084. double x;
  1085. double y;
  1086. Point3d p1;
  1087. Point3d p2;
  1088. //下边线
  1089. x = LB.X;
  1090. y = LB.Y;
  1091. p1 = new Point3d(x + i * dist, y + len, 0);
  1092. p2 = new Point3d(x + i * dist, y, 0);
  1093. Point3dCollection kb = new Point3dCollection();
  1094. kb.Add(p1);
  1095. kb.Add(p2);
  1096. Polyline2d kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null);
  1097. kbline.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1098. kbline.Layer = layername;
  1099. kbline.SetDatabaseDefaults();
  1100. blocktablerecord.AppendEntity(kbline);
  1101. traction.AddNewlyCreatedDBObject(kbline, true);
  1102. //上边线
  1103. x = LB.X;
  1104. y = LT.Y;
  1105. p1 = new Point3d(x + i * dist, y - len, 0);
  1106. p2 = new Point3d(x + i * dist, y, 0);
  1107. kb = new Point3dCollection();
  1108. kb.Add(p1);
  1109. kb.Add(p2);
  1110. kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null);
  1111. kbline.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1112. kbline.Layer = layername;
  1113. kbline.SetDatabaseDefaults();
  1114. blocktablerecord.AppendEntity(kbline);
  1115. traction.AddNewlyCreatedDBObject(kbline, true);
  1116. //左边线
  1117. x = LB.X;
  1118. y = LB.Y;
  1119. p1 = new Point3d(x, y + i * dist, 0);
  1120. p2 = new Point3d(x + len, y + i * dist, 0);
  1121. kb = new Point3dCollection();
  1122. kb.Add(p1);
  1123. kb.Add(p2);
  1124. kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null);
  1125. kbline.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1126. kbline.Layer = layername;
  1127. kbline.SetDatabaseDefaults();
  1128. blocktablerecord.AppendEntity(kbline);
  1129. traction.AddNewlyCreatedDBObject(kbline, true);
  1130. //右边线
  1131. x = RB.X;
  1132. y = LB.Y;
  1133. p1 = new Point3d(x, y + i * dist, 0);
  1134. p2 = new Point3d(x - len, y + i * dist, 0);
  1135. kb = new Point3dCollection();
  1136. kb.Add(p1);
  1137. kb.Add(p2);
  1138. kbline = new Polyline2d(Poly2dType.SimplePoly, kb, 0, false, 0, 0, null);
  1139. kbline.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1140. kbline.Layer = layername;
  1141. kbline.SetDatabaseDefaults();
  1142. blocktablerecord.AppendEntity(kbline);
  1143. traction.AddNewlyCreatedDBObject(kbline, true);
  1144. }
  1145. //右下角附注
  1146. double xx = RB.X;
  1147. double yy = RB.Y;
  1148. xx = xx - D140;
  1149. yy = yy - D22 - D2 - D6;
  1150. List<string> RLnote = new List<string>();
  1151. string str = "";
  1152. if (string.IsNullOrEmpty(TKInfo.CTY) == false)
  1153. {
  1154. str = TKInfo.CTY;
  1155. RLnote.Add(str);
  1156. }
  1157. if (string.IsNullOrEmpty(TKInfo.TDY) == false)
  1158. {
  1159. str = TKInfo.TDY;
  1160. RLnote.Add(str);
  1161. }
  1162. if (string.IsNullOrEmpty(TKInfo.SHY) == false)
  1163. {
  1164. str = TKInfo.SHY;
  1165. RLnote.Add(str);
  1166. }
  1167. if (string.IsNullOrEmpty(TKInfo.JCY) == false)
  1168. {
  1169. str = TKInfo.JCY;
  1170. RLnote.Add(str);
  1171. }
  1172. str = "复查员 ";
  1173. RLnote.Add(str);
  1174. //秘密等级
  1175. if (string.IsNullOrEmpty(TKInfo.Secret) == false)
  1176. {
  1177. str = TKInfo.Secret;
  1178. DBText text1_secret = new DBText();
  1179. text1_secret.TextString = str;
  1180. text1_secret.WidthFactor = 1.333;
  1181. text1_secret.HorizontalMode = TextHorizontalMode.TextLeft;
  1182. text1_secret.Height = D6;
  1183. text1_secret.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4);
  1184. text1_secret.Layer = layername;
  1185. text1_secret.TextStyleId = ht;
  1186. double s_x = RT.X - (text1_secret.Bounds.Value.MaxPoint.X - text1_secret.Bounds.Value.MinPoint.X) - D1;
  1187. double s_y = LT.Y + D22 + D2 + D10;
  1188. text1_secret.Position = new Point3d(s_x, s_y, 0);
  1189. text1_secret.SetDatabaseDefaults();
  1190. blocktablerecord.AppendEntity(text1_secret);
  1191. traction.AddNewlyCreatedDBObject(text1_secret, true);
  1192. }
  1193. for (int i = 0; i < RLnote.Count; i++)
  1194. {
  1195. yy = yy - D6;
  1196. DBText text1_fz = new DBText();
  1197. text1_fz.TextString = RLnote[i];
  1198. text1_fz.Position = new Point3d(xx, yy, 0);
  1199. text1_fz.Height = D6;
  1200. text1_fz.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4);
  1201. text1_fz.Layer = layername;
  1202. text1_fz.TextStyleId = HZ;
  1203. text1_fz.SetDatabaseDefaults();
  1204. blocktablerecord.AppendEntity(text1_fz);
  1205. traction.AddNewlyCreatedDBObject(text1_fz, true);
  1206. yy = yy - D4;
  1207. }
  1208. //比例尺
  1209. xx = (RB.X - LB.X) / 2 + LB.X;
  1210. yy = LB.Y - D22 - D2 - D10 - D8;
  1211. DBText text2_blc = new DBText();
  1212. text2_blc.TextString = "1:" + BLC;
  1213. text2_blc.Position = new Point3d(xx, yy, 0);
  1214. text2_blc.Height = D8;
  1215. text2_blc.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 2);
  1216. text2_blc.Layer = layername;
  1217. text2_blc.HorizontalMode = TextHorizontalMode.TextCenter;
  1218. text2_blc.AlignmentPoint = new Point3d(xx, yy, 0);
  1219. text2_blc.TextStyleId = st;
  1220. text2_blc.WidthFactor = 0.75;
  1221. text2_blc.SetDatabaseDefaults();
  1222. blocktablerecord.AppendEntity(text2_blc);
  1223. traction.AddNewlyCreatedDBObject(text2_blc, true);
  1224. //图幅号
  1225. xx = (RB.X - LB.X) / 2 + LB.X;
  1226. yy = LT.Y + D22 + D2 + D10;
  1227. DBText text3_tfh = new DBText();
  1228. text3_tfh.TextString = "(" + Number.ToString() + ")";
  1229. text3_tfh.Position = new Point3d(xx, yy, 0);
  1230. text3_tfh.Height = D10;
  1231. text3_tfh.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 2);
  1232. text3_tfh.Layer = layername;
  1233. text3_tfh.HorizontalMode = TextHorizontalMode.TextCenter;
  1234. text3_tfh.AlignmentPoint = new Point3d(xx, yy, 0);
  1235. text3_tfh.TextStyleId = HZ;
  1236. text3_tfh.WidthFactor = 0.8;
  1237. text3_tfh.SetDatabaseDefaults();
  1238. blocktablerecord.AppendEntity(text3_tfh);
  1239. traction.AddNewlyCreatedDBObject(text3_tfh, true);
  1240. //图名
  1241. xx = (RB.X - LB.X) / 2 + LB.X;
  1242. yy = LT.Y + D22 + D2 + D10 + D10 + D6;
  1243. DBText text4_tm = new DBText();
  1244. text4_tm.TextString = TKInfo.name;
  1245. text4_tm.Position = new Point3d(xx, yy, 0);
  1246. text4_tm.Height = D10;
  1247. text4_tm.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 6);
  1248. text4_tm.Layer = layername;
  1249. text4_tm.HorizontalMode = TextHorizontalMode.TextCenter;
  1250. text4_tm.AlignmentPoint = new Point3d(xx, yy, 0);
  1251. text4_tm.TextStyleId = ht;
  1252. text4_tm.WidthFactor = 1;
  1253. text4_tm.SetDatabaseDefaults();
  1254. blocktablerecord.AppendEntity(text4_tm);
  1255. traction.AddNewlyCreatedDBObject(text4_tm, true);
  1256. //图名后的日期
  1257. //string Time_str = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00");
  1258. ////左括号
  1259. //string tem_str = text4_tm.TextString;
  1260. //xx = (RB.X - LB.X) / 2 + LB.X + tem_str.Length / 2.0 * (D12);
  1261. //yy = LT.Y + D22 + D2 + D10 + D10 + D6;
  1262. //DBText text_F = new DBText();
  1263. //string black = "";
  1264. //for (int i = 0; i < D12; i++)
  1265. //{
  1266. // black += " ";
  1267. //}
  1268. //text_F.TextString = "(" + Time_str + ")";
  1269. //text_F.Position = new Point3d(xx, yy, 0);
  1270. //text_F.Height = D12;
  1271. //text_F.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 2);
  1272. //text_F.Layer = layername;
  1273. //text_F.HorizontalMode = TextHorizontalMode.TextLeft;
  1274. ////text_F.TextStyleId = ID12;
  1275. //text_F.TextStyleId = ht;
  1276. //text_F.SetDatabaseDefaults();
  1277. //blocktablerecord.AppendEntity(text_F);
  1278. //traction.AddNewlyCreatedDBObject(text_F, true);
  1279. //日期
  1280. //xx = xx + D1;
  1281. //yy = LT.Y + D22 + D2 + D10 + D10 + D6;
  1282. //DBText text_T = new DBText();
  1283. //text_T.TextString = Time_str;
  1284. //text_T.Position = new Point3d(xx, yy, 0);
  1285. //text_T.Height = D12;
  1286. //text_T.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 2);
  1287. //text_T.Layer = layername;
  1288. //text_T.HorizontalMode = TextHorizontalMode.TextLeft;
  1289. //text_T.TextStyleId = ht;
  1290. //text_T.SetDatabaseDefaults();
  1291. //blocktablerecord.AppendEntity(text_T);
  1292. //traction.AddNewlyCreatedDBObject(text_T, true);
  1293. //左下附注
  1294. string notes = TKInfo.note;
  1295. char[] ch = new char[] { '\r', '\n' };
  1296. string[] strs = notes.Split(ch);
  1297. xx = LB.X;
  1298. yy = LB.Y - D22 - D2 - D6;
  1299. for (int i = 0; i < strs.Length; i++)
  1300. {
  1301. xx = LB.X;
  1302. yy = yy - D6;
  1303. if (i == strs.Length - 3)
  1304. {
  1305. string[] str1 = strs[i].Split(' ');
  1306. DBText text_fz1 = new DBText();
  1307. text_fz1.TextString = str1[0];
  1308. text_fz1.Position = new Point3d(xx, yy, 0);
  1309. text_fz1.Height = D6;
  1310. text_fz1.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4);
  1311. text_fz1.Layer = layername;
  1312. text_fz1.TextStyleId = HZ;
  1313. text_fz1.WidthFactor = 0.8;
  1314. text_fz1.SetDatabaseDefaults();
  1315. blocktablerecord.AppendEntity(text_fz1);
  1316. traction.AddNewlyCreatedDBObject(text_fz1, true);
  1317. xx = xx + D140 / 2 + D2;
  1318. DBText text_fz2 = new DBText();
  1319. text_fz2.TextString = str1[1] + " " + str1[2];
  1320. text_fz2.Position = new Point3d(xx, yy, 0);
  1321. text_fz2.Height = D6;
  1322. text_fz2.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4);
  1323. text_fz2.Layer = layername;
  1324. text_fz2.TextStyleId = HZ;
  1325. text_fz2.WidthFactor = 1;
  1326. text_fz2.SetDatabaseDefaults();
  1327. blocktablerecord.AppendEntity(text_fz2);
  1328. traction.AddNewlyCreatedDBObject(text_fz2, true);
  1329. yy = yy - D4;
  1330. continue;
  1331. }
  1332. else if (i == strs.Length - 2)
  1333. {
  1334. string[] str2 = strs[i].Split(' ');
  1335. DBText text_1 = new DBText();
  1336. text_1.TextString = str2[0]+" "+ str2[1] + " "+ str2[2];
  1337. text_1.Position = new Point3d(xx, yy, 0);
  1338. text_1.Height = D6;
  1339. text_1.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4);
  1340. text_1.Layer = layername;
  1341. text_1.TextStyleId = HZ;
  1342. text_1.WidthFactor = 0.8;
  1343. text_1.SetDatabaseDefaults();
  1344. blocktablerecord.AppendEntity(text_1);
  1345. traction.AddNewlyCreatedDBObject(text_1, true);
  1346. xx = xx + D90;
  1347. DBText text_2 = new DBText();
  1348. text_2.TextString = str2[3];
  1349. text_2.Position = new Point3d(xx, yy, 0);
  1350. text_2.Height = D6;
  1351. text_2.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4);
  1352. text_2.Layer = layername;
  1353. text_2.TextStyleId = HZ;
  1354. text_2.WidthFactor = 1;
  1355. text_2.SetDatabaseDefaults();
  1356. blocktablerecord.AppendEntity(text_2);
  1357. traction.AddNewlyCreatedDBObject(text_2, true);
  1358. yy = yy - D4;
  1359. continue;
  1360. }
  1361. DBText text5 = new DBText();
  1362. text5.TextString = strs[i];
  1363. text5.Position = new Point3d(xx, yy, 0);
  1364. text5.Height = D6;
  1365. text5.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4);
  1366. text5.Layer = layername;
  1367. text5.TextStyleId = HZ;
  1368. text5.WidthFactor = 1;
  1369. text5.SetDatabaseDefaults();
  1370. blocktablerecord.AppendEntity(text5);
  1371. traction.AddNewlyCreatedDBObject(text5, true);
  1372. yy = yy - D4;
  1373. }
  1374. //公司名称
  1375. string Company = "四川中水成勘院测绘工程有限责任公司";
  1376. xx = LB.X - D22 - D2 - D6 - D8;
  1377. yy = LB.Y;
  1378. for (int i = Company.Length - 1; i >= 0; i--)
  1379. {
  1380. DBText text6_gs = new DBText();
  1381. text6_gs.TextString = Company[i].ToString();
  1382. text6_gs.Position = new Point3d(xx, yy, 0);
  1383. text6_gs.Height = D8;
  1384. text6_gs.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 2);
  1385. text6_gs.Layer = layername;
  1386. text6_gs.TextStyleId = HZ;
  1387. text6_gs.WidthFactor = 1;
  1388. text6_gs.SetDatabaseDefaults();
  1389. blocktablerecord.AppendEntity(text6_gs);
  1390. traction.AddNewlyCreatedDBObject(text6_gs, true);
  1391. yy = yy + D8 + D2;
  1392. }
  1393. //接图表
  1394. //接图表左下角坐标
  1395. xx = LT.X;
  1396. yy = LT.Y + D22 + D2 + D6;
  1397. for (int i = 0; i < 2; i++)
  1398. {
  1399. Point3dCollection Lcoll = new Point3dCollection();
  1400. Lcoll.Add(new Point3d(xx, yy + D48, 0));
  1401. Lcoll.Add(new Point3d(xx, yy, 0));
  1402. Polyline2d JTB = new Polyline2d(Poly2dType.SimplePoly, Lcoll, 0, true, 0, 0, null);
  1403. JTB.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1404. JTB.Layer = layername;
  1405. JTB.SetDatabaseDefaults();
  1406. blocktablerecord.AppendEntity(JTB);
  1407. traction.AddNewlyCreatedDBObject(JTB, true);
  1408. xx = xx + D90;
  1409. }
  1410. xx = LT.X;
  1411. yy = LT.Y + D22 + D2 + D6;
  1412. for (int i = 0; i < 4; i++)
  1413. {
  1414. Point3dCollection Lcoll = new Point3dCollection();
  1415. Lcoll.Add(new Point3d(xx, yy, 0));
  1416. Lcoll.Add(new Point3d(xx + D90, yy, 0));
  1417. Polyline2d JTB = new Polyline2d(Poly2dType.SimplePoly, Lcoll, 0, true, 0, 0, null);
  1418. JTB.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1419. JTB.Layer = layername;
  1420. JTB.SetDatabaseDefaults();
  1421. blocktablerecord.AppendEntity(JTB);
  1422. traction.AddNewlyCreatedDBObject(JTB, true);
  1423. yy = yy + D48 / 3;
  1424. }
  1425. xx = LT.X;
  1426. yy = LT.Y + D22 + D2 + D6;
  1427. for (int i = 0; i < 2; i++)
  1428. {
  1429. Point3dCollection Lcoll = new Point3dCollection();
  1430. //Lcoll.Add(new Point3d(xx + D90 / 3, yy + D48 / 3, 0));
  1431. Lcoll.Add(new Point3d(xx + D90 / 3, yy, 0));
  1432. //Lcoll.Add(new Point3d(xx + D90 / 3, yy + D48 / 3 * 2, 0));
  1433. Lcoll.Add(new Point3d(xx + D90 / 3, yy + D48, 0));
  1434. Polyline2d JTB = new Polyline2d(Poly2dType.SimplePoly, Lcoll, 0, true, 0, 0, null);
  1435. JTB.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1436. JTB.Layer = layername;
  1437. JTB.SetDatabaseDefaults();
  1438. blocktablerecord.AppendEntity(JTB);
  1439. traction.AddNewlyCreatedDBObject(JTB, true);
  1440. xx = xx + D90 / 3;
  1441. }
  1442. //接图表填充
  1443. //接图表左上角坐标
  1444. xx = LT.X + D90 / 3;
  1445. yy = LT.Y + D22 + D2 + D6 + (D48 / 3) * 2;
  1446. Point3dCollection coll = new Point3dCollection();
  1447. coll.Add(new Point3d(xx, yy, 0));
  1448. coll.Add(new Point3d(xx, yy - D48 / 3, 0));
  1449. coll.Add(new Point3d(xx + D90 / 3, yy - D48 / 3, 0));
  1450. coll.Add(new Point3d(xx + D90 / 3, yy, 0));
  1451. coll.Add(new Point3d(xx, yy, 0));
  1452. Polyline2d line2d = new Polyline2d(Poly2dType.SimplePoly, coll, 0, false, 0, 0, null);
  1453. xx = xx + dist1;
  1454. for (int i = 0; i < 30; i++)
  1455. {
  1456. Line l = new Line();
  1457. l.StartPoint = new Point3d(xx + 90, yy + 90, 0);
  1458. l.EndPoint = new Point3d(xx - 90, yy - 90, 0);
  1459. Point3dCollection IP = new Point3dCollection();
  1460. l.IntersectWith(line2d, Intersect.ExtendThis, IP, IntPtr.Zero, IntPtr.Zero);
  1461. Polyline2d FillLine = new Polyline2d(Poly2dType.SimplePoly, IP, 0, false, 0, 0, null);
  1462. FillLine.Layer = layername;
  1463. FillLine.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 1);
  1464. FillLine.SetDatabaseDefaults();
  1465. blocktablerecord.AppendEntity(FillLine);
  1466. traction.AddNewlyCreatedDBObject(FillLine, true);
  1467. xx = xx + Math.Sqrt(dist2);
  1468. }
  1469. //接图表中间行——左
  1470. if (string.IsNullOrEmpty(Left_Number) == false)
  1471. {
  1472. //接图表左下角坐标
  1473. xx1 = LT.X;
  1474. yy1 = LT.Y + D22 + D2 + D6;
  1475. xx2 = xx1 + D90 / 3 / 2;
  1476. yy2 = yy1 + D48 / 3 * 1.5;
  1477. DBText text_L = new DBText();
  1478. text_L.TextString = Left_Number;
  1479. text_L.Position = new Point3d(xx2, yy2, 0);
  1480. text_L.Height = D5;
  1481. text_L.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4);
  1482. text_L.Layer = layername;
  1483. text_L.TextStyleId = HZ;
  1484. text_L.HorizontalMode = TextHorizontalMode.TextCenter;
  1485. text_L.VerticalMode = TextVerticalMode.TextVerticalMid;
  1486. text_L.AlignmentPoint = new Point3d(xx2, yy2, 0);
  1487. text_L.SetDatabaseDefaults();
  1488. blocktablerecord.AppendEntity(text_L);
  1489. traction.AddNewlyCreatedDBObject(text_L, true);
  1490. }
  1491. //接图表中间行——右
  1492. if (string.IsNullOrEmpty(Right_Number) == false)
  1493. {
  1494. //接图表左下角坐标
  1495. xx1 = LT.X;
  1496. yy1 = LT.Y + D22 + D2 + D6;
  1497. xx2 = xx1 + D90 / 3 * 2.5;
  1498. yy2 = yy1 + D48 / 3 * 1.5;
  1499. DBText text_R = new DBText();
  1500. text_R.TextString = Right_Number;
  1501. text_R.Position = new Point3d(xx2, yy2, 0);
  1502. text_R.Height = D5;
  1503. text_R.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4);
  1504. text_R.Layer = layername;
  1505. text_R.TextStyleId = HZ;
  1506. text_R.HorizontalMode = TextHorizontalMode.TextCenter;
  1507. text_R.VerticalMode = TextVerticalMode.TextVerticalMid;
  1508. text_R.AlignmentPoint = new Point3d(xx2, yy2, 0);
  1509. text_R.SetDatabaseDefaults();
  1510. blocktablerecord.AppendEntity(text_R);
  1511. traction.AddNewlyCreatedDBObject(text_R, true);
  1512. }
  1513. //接图表首行——左
  1514. if (string.IsNullOrEmpty(Leftup_Number) == false)
  1515. {
  1516. xx1 = LT.X;
  1517. yy1 = LT.Y + D22 + D2 + D6;
  1518. xx2 = xx1 + D90 / 3 / 2;
  1519. yy2 = yy1 + D48 / 3 * 2.5;
  1520. filjtb(Leftup_Number,traction, HZ, blocktablerecord, xx2, yy2, D5);
  1521. }
  1522. //接图表首行——中
  1523. if (string.IsNullOrEmpty(Centrolup_Number) == false)
  1524. {
  1525. xx1 = LT.X;
  1526. yy1 = LT.Y + D22 + D2 + D6;
  1527. xx2 = xx1 + D90 / 3 * 1.5;
  1528. yy2 = yy1 + D48 / 3 * 2.5;
  1529. filjtb(Centrolup_Number,traction, HZ, blocktablerecord, xx2, yy2, D5);
  1530. }
  1531. //接图表首行——右
  1532. if (string.IsNullOrEmpty(Rightup_Number) == false)
  1533. {
  1534. xx1 = LT.X;
  1535. yy1 = LT.Y + D22 + D2 + D6;
  1536. xx2 = xx1 + D90 / 3 * 2.5;
  1537. yy2 = yy1 + D48 / 3 * 2.5;
  1538. filjtb(Rightup_Number,traction, HZ, blocktablerecord, xx2, yy2, D5);
  1539. }
  1540. //接图表尾行——左
  1541. if (string.IsNullOrEmpty(Leftdown_Number) == false)
  1542. {
  1543. xx1 = LT.X;
  1544. yy1 = LT.Y + D22 + D2 + D6;
  1545. xx2 = xx1 + D90 / 3 / 2;
  1546. yy2 = yy1 + D48 / 3 / 2;
  1547. filjtb(Leftdown_Number,traction, HZ, blocktablerecord, xx2, yy2, D5);
  1548. }
  1549. //接图表尾行——中
  1550. if (string.IsNullOrEmpty(Centroldown_Number) == false)
  1551. {
  1552. xx1 = LT.X;
  1553. yy1 = LT.Y + D22 + D2 + D6;
  1554. xx2 = xx1 + D90 / 3 * 1.5;
  1555. yy2 = yy1 + D48 / 3 / 2;
  1556. filjtb(Centroldown_Number,traction, HZ, blocktablerecord, xx2, yy2, D5);
  1557. }
  1558. //接图表尾行——右
  1559. if (string.IsNullOrEmpty(Rightdown_Number) == false)
  1560. {
  1561. xx1 = LT.X;
  1562. yy1 = LT.Y + D22 + D2 + D6;
  1563. xx2 = xx1 + D90 / 3 * 2.5;
  1564. yy2 = yy1 + D48 / 3 / 2;
  1565. filjtb(Rightdown_Number,traction, HZ, blocktablerecord, xx2, yy2, D5);
  1566. }
  1567. ////坐标
  1568. //左上
  1569. xx = LT.X;
  1570. yy = LT.Y;
  1571. //X坐标
  1572. xx1 = xx - D4_8 * 0.75 * 2 - D1;
  1573. yy1 = yy + D22 - D7;
  1574. DBText text7 = new DBText();
  1575. string value7 = (xx / 1000.0 % 100).ToString("F1");
  1576. if (value7.Length == 3)
  1577. {
  1578. value7 = "0" + value7;
  1579. }
  1580. text7.TextString = value7;
  1581. text7.Position = new Point3d(xx1, yy1, 0);
  1582. text7.Height = D4_8;
  1583. text7.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1584. text7.Layer = layername;
  1585. text7.TextStyleId = HZ;
  1586. text7.WidthFactor = 0.75;
  1587. text7.SetDatabaseDefaults();
  1588. blocktablerecord.AppendEntity(text7);
  1589. traction.AddNewlyCreatedDBObject(text7, true);
  1590. //带号
  1591. xx1 = xx - D4_8 * 0.75 * 2 - D3 * 0.75 * 3 - D2;
  1592. yy1 = yy + D22 - D7 + (D4_8 - D3);
  1593. if (TKInfo.DH != -1)
  1594. {
  1595. DH = TKInfo.DH * 10 + (int)xx / 1000 / 100;
  1596. }
  1597. else
  1598. {
  1599. DH = (int)xx / 1000 / 100;
  1600. }
  1601. DBText text8 = new DBText();
  1602. text8.TextString = DH.ToString();
  1603. text8.Position = new Point3d(xx1, yy1, 0);
  1604. text8.Height = D3;
  1605. text8.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1606. text8.Layer = layername;
  1607. text8.HorizontalMode = TextHorizontalMode.TextRight;
  1608. text8.VerticalMode = TextVerticalMode.TextTop;
  1609. xx2 = xx - D4_8 * 0.75 * 2 - D2;
  1610. yy2 = yy + D22 - D7 + D4_8;
  1611. text8.AlignmentPoint = new Point3d(xx2, yy2, 0);
  1612. text8.TextStyleId = HZ;
  1613. text8.WidthFactor = 0.75;
  1614. text8.SetDatabaseDefaults();
  1615. blocktablerecord.AppendEntity(text8);
  1616. traction.AddNewlyCreatedDBObject(text8, true);
  1617. //Y坐标下标
  1618. xx1 = xx - D4_8 * 0.75 * 4 - D1;
  1619. yy1 = yy + D2;
  1620. DBText text9 = new DBText();
  1621. string value9 = (yy / 1000.0 % 100).ToString("F1");
  1622. if (value9.Length == 3)
  1623. {
  1624. value9 = "0" + value9;
  1625. }
  1626. text9.TextString = value9;
  1627. text9.Position = new Point3d(xx1, yy1, 0);
  1628. text9.Height = D4_8;
  1629. text9.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1630. text9.Layer = layername;
  1631. text9.TextStyleId = HZ;
  1632. text9.WidthFactor = 0.75;
  1633. text9.SetDatabaseDefaults();
  1634. blocktablerecord.AppendEntity(text9);
  1635. traction.AddNewlyCreatedDBObject(text9, true);
  1636. //Y坐标上标
  1637. xx1 = xx - D4_8 * 0.75 * 4 - D1;
  1638. yy1 = yy + D2 + D4_8 - D3;
  1639. DBText text10 = new DBText();
  1640. int value10 = (int)(yy / 1000 / 100);
  1641. text10.TextString = value10.ToString();
  1642. text10.Position = new Point3d(xx1, yy1, 0);
  1643. text10.Height = D3;
  1644. text10.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1645. text10.Layer = layername;
  1646. text10.HorizontalMode = TextHorizontalMode.TextRight;
  1647. text10.VerticalMode = TextVerticalMode.TextTop;
  1648. xx2 = xx - D4_8 * 0.75 * 4 - D1;
  1649. yy2 = yy + D2 + D4_8;
  1650. text10.AlignmentPoint = new Point3d(xx2, yy2, 0);
  1651. text10.TextStyleId = HZ;
  1652. text10.WidthFactor = 0.75;
  1653. text10.SetDatabaseDefaults();
  1654. blocktablerecord.AppendEntity(text10);
  1655. traction.AddNewlyCreatedDBObject(text10, true);
  1656. //左下
  1657. xx = LB.X;
  1658. yy = LB.Y;
  1659. //X坐标
  1660. xx1 = xx - D4_8 * 0.75 * 2 - D1;
  1661. yy1 = yy - D22 + D2;
  1662. DBText text11 = new DBText();
  1663. string value11 = (xx / 1000.0 % 100).ToString("F1");
  1664. if (value11.Length == 3)
  1665. {
  1666. value11 = "0" + value11;
  1667. }
  1668. text11.TextString = value11;
  1669. text11.Position = new Point3d(xx1, yy1, 0);
  1670. text11.Height = D4_8;
  1671. text11.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1672. text11.Layer = layername;
  1673. text11.TextStyleId = HZ;
  1674. text11.WidthFactor = 0.75;
  1675. text11.SetDatabaseDefaults();
  1676. blocktablerecord.AppendEntity(text11);
  1677. traction.AddNewlyCreatedDBObject(text11, true);
  1678. //带号
  1679. xx1 = xx - D4_8 * 0.75 * 2 - D3 * 0.75 * 3 - D2;
  1680. yy1 = yy - D22 + D7 - (D4_8 - D3);
  1681. if (TKInfo.DH != -1)
  1682. {
  1683. DH = TKInfo.DH * 10 + (int)xx / 1000 / 100;
  1684. }
  1685. else
  1686. {
  1687. DH = (int)xx / 1000 / 100;
  1688. }
  1689. DBText text12 = new DBText();
  1690. text12.TextString = DH.ToString();
  1691. text12.Position = new Point3d(xx1, yy1, 0);
  1692. text12.Height = D3;
  1693. text12.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1694. text12.Layer = layername;
  1695. text12.HorizontalMode = TextHorizontalMode.TextRight;
  1696. text12.VerticalMode = TextVerticalMode.TextTop;
  1697. xx2 = xx - D4_8 * 0.75 * 2 - D2;
  1698. yy2 = yy - D22 + D7;
  1699. text12.AlignmentPoint = new Point3d(xx2, yy2, 0);
  1700. text12.TextStyleId = HZ;
  1701. text12.WidthFactor = 0.75;
  1702. text12.SetDatabaseDefaults();
  1703. blocktablerecord.AppendEntity(text12);
  1704. traction.AddNewlyCreatedDBObject(text12, true);
  1705. //Y坐标
  1706. xx1 = xx - D4_8 * 0.75 * 4 - D1;
  1707. yy1 = yy + D2;
  1708. DBText text13 = new DBText();
  1709. string value13 = (yy / 1000.0 % 100).ToString("F1");
  1710. if (value13.Length == 3)
  1711. {
  1712. value13 = "0" + value13;
  1713. }
  1714. text13.TextString = value13;
  1715. text13.Position = new Point3d(xx1, yy1, 0);
  1716. text13.Height = D4_8;
  1717. text13.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1718. text13.Layer = layername;
  1719. text13.TextStyleId = HZ;
  1720. text13.WidthFactor = 0.75;
  1721. text13.SetDatabaseDefaults();
  1722. blocktablerecord.AppendEntity(text13);
  1723. traction.AddNewlyCreatedDBObject(text13, true);
  1724. //Y坐标上标
  1725. xx1 = xx - D4_8 * 0.75 * 4 - D1;
  1726. yy1 = yy + D2 + D4_8 - D3;
  1727. DBText text14 = new DBText();
  1728. int value14 = (int)(LB.Y / 1000 / 100);
  1729. text14.TextString = value14.ToString();
  1730. text14.Position = new Point3d(xx1, yy1, 0);
  1731. text14.Height = D3;
  1732. text14.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1733. text14.Layer = layername;
  1734. text14.HorizontalMode = TextHorizontalMode.TextRight;
  1735. text14.VerticalMode = TextVerticalMode.TextTop;
  1736. xx2 = xx - D4_8 * 0.75 * 4 - D1;
  1737. yy2 = yy + D2 + D4_8;
  1738. text14.AlignmentPoint = new Point3d(xx2, yy2, 0);
  1739. text14.TextStyleId = HZ;
  1740. text14.WidthFactor = 0.75;
  1741. text14.SetDatabaseDefaults();
  1742. blocktablerecord.AppendEntity(text14);
  1743. traction.AddNewlyCreatedDBObject(text14, true);
  1744. //右上
  1745. xx = RT.X;
  1746. yy = RT.Y;
  1747. //X坐标
  1748. xx1 = xx - D4_8 * 0.75 * 2 - D1;
  1749. yy1 = yy + D22 - D7;
  1750. DBText text15 = new DBText();
  1751. string value15 = (RT.X / 1000.0 % 100).ToString("F1");
  1752. if (value15.Length == 3)
  1753. {
  1754. value15 = "0" + value15;
  1755. }
  1756. text15.TextString = value15;
  1757. text15.Position = new Point3d(xx1, yy1, 0);
  1758. text15.Height = D4_8;
  1759. text15.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1760. text15.Layer = layername;
  1761. text15.TextStyleId = HZ;
  1762. text15.WidthFactor = 0.75;
  1763. text15.SetDatabaseDefaults();
  1764. blocktablerecord.AppendEntity(text15);
  1765. traction.AddNewlyCreatedDBObject(text15, true);
  1766. //带号
  1767. xx1 = xx - D4_8 * 0.75 * 2 - D3 * 0.75 * 3 - D2;
  1768. yy1 = yy + D22 - D7 + (D4_8 - D3);
  1769. if (TKInfo.DH != -1)
  1770. {
  1771. DH = TKInfo.DH * 10 + (int)RT.X / 1000 / 100;
  1772. }
  1773. else
  1774. {
  1775. DH = (int)RT.X / 1000 / 100;
  1776. }
  1777. DBText text16 = new DBText();
  1778. text16.TextString = DH.ToString();
  1779. text16.Position = new Point3d(xx1, yy1, 0);
  1780. text16.Height = D3;
  1781. text16.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1782. text16.Layer = layername;
  1783. text16.HorizontalMode = TextHorizontalMode.TextRight;
  1784. text16.VerticalMode = TextVerticalMode.TextTop;
  1785. xx2 = xx - D4_8 * 0.75 * 2 - D2;
  1786. yy2 = yy + D22 - D7 + D4_8;
  1787. text16.AlignmentPoint = new Point3d(xx2, yy2, 0);
  1788. text16.TextStyleId = HZ;
  1789. text16.WidthFactor = 0.75;
  1790. text16.SetDatabaseDefaults();
  1791. blocktablerecord.AppendEntity(text16);
  1792. traction.AddNewlyCreatedDBObject(text16, true);
  1793. //Y坐标
  1794. xx1 = xx + D7;
  1795. yy1 = yy + D2;
  1796. DBText text17 = new DBText();
  1797. string value17 = (RT.Y / 1000.0 % 100).ToString("F1");
  1798. if (value17.Length == 3)
  1799. {
  1800. value17 = "0" + value17;
  1801. }
  1802. text17.TextString = value17;
  1803. text17.Position = new Point3d(xx1, yy1, 0);
  1804. text17.Height = D4_8;
  1805. text17.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1806. text17.Layer = layername;
  1807. text17.TextStyleId = HZ;
  1808. text17.WidthFactor = 0.75;
  1809. text17.SetDatabaseDefaults();
  1810. blocktablerecord.AppendEntity(text17);
  1811. traction.AddNewlyCreatedDBObject(text17, true);
  1812. //Y坐标上标
  1813. xx1 = xx + D7;
  1814. yy1 = yy + D2 + D4_8 - D3;
  1815. DBText text18 = new DBText();
  1816. int value18 = (int)(RT.Y / 1000 / 100);
  1817. text18.TextString = value18.ToString();
  1818. text18.Position = new Point3d(xx1, yy1, 0);
  1819. text18.Height = D3;
  1820. text18.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1821. text18.Layer = layername;
  1822. text18.HorizontalMode = TextHorizontalMode.TextRight;
  1823. text18.VerticalMode = TextVerticalMode.TextTop;
  1824. xx2 = xx + D7;
  1825. yy2 = yy + D2 + D4_8;
  1826. text18.AlignmentPoint = new Point3d(xx2, yy2, 0);
  1827. text18.TextStyleId = HZ;
  1828. text18.WidthFactor = 0.75;
  1829. text18.SetDatabaseDefaults();
  1830. blocktablerecord.AppendEntity(text18);
  1831. traction.AddNewlyCreatedDBObject(text18, true);
  1832. //右下
  1833. xx = RB.X;
  1834. yy = RB.Y;
  1835. //X坐标
  1836. xx1 = xx - D4_8 * 0.75 * 2 - D1;
  1837. yy1 = yy - D22 + D2;
  1838. DBText text19 = new DBText();
  1839. string value19 = (RB.X / 1000.0 % 100).ToString("F1");
  1840. if (value19.Length == 3)
  1841. {
  1842. value19 = "0" + value19;
  1843. }
  1844. text19.TextString = value19;
  1845. text19.Position = new Point3d(xx1, yy1, 0);
  1846. text19.Height = D4_8;
  1847. text19.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1848. text19.Layer = layername;
  1849. text19.TextStyleId = HZ;
  1850. text19.WidthFactor = 0.75;
  1851. text19.SetDatabaseDefaults();
  1852. blocktablerecord.AppendEntity(text19);
  1853. traction.AddNewlyCreatedDBObject(text19, true);
  1854. //带号
  1855. xx1 = xx - D4_8 * 0.75 * 2 - D3 * 0.75 * 3 - D2;
  1856. yy1 = yy - D22 + D7 - D3;
  1857. if (TKInfo.DH != -1)
  1858. {
  1859. DH = TKInfo.DH * 10 + (int)RT.X / 1000 / 100;
  1860. }
  1861. else
  1862. {
  1863. DH = (int)RT.X / 1000 / 100;
  1864. }
  1865. DBText text20 = new DBText();
  1866. text20.TextString = DH.ToString();
  1867. text20.Position = new Point3d(xx1, yy1, 0);
  1868. text20.Height = D3;
  1869. text20.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1870. text20.Layer = layername;
  1871. text20.HorizontalMode = TextHorizontalMode.TextRight;
  1872. text20.VerticalMode = TextVerticalMode.TextTop;
  1873. xx2 = xx - D4_8 * 0.75 * 2 - D2;
  1874. yy2 = yy - D22 + D7;
  1875. text20.AlignmentPoint = new Point3d(xx2, yy2, 0);
  1876. text20.TextStyleId = HZ;
  1877. text20.WidthFactor = 0.75;
  1878. text20.SetDatabaseDefaults();
  1879. blocktablerecord.AppendEntity(text20);
  1880. traction.AddNewlyCreatedDBObject(text20, true);
  1881. //Y坐标
  1882. xx1 = xx + D7;
  1883. yy1 = yy + D2;
  1884. DBText text21 = new DBText();
  1885. string value21 = (RB.Y / 1000.0 % 100).ToString("F1");
  1886. if (value21.Length == 3)
  1887. {
  1888. value21 = "0" + value21;
  1889. }
  1890. text21.TextString = value21;
  1891. text21.Position = new Point3d(xx1, yy1, 0);
  1892. text21.Height = D4_8;
  1893. text21.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1894. text21.Layer = layername;
  1895. text21.TextStyleId = HZ;
  1896. text21.WidthFactor = 0.75;
  1897. text21.SetDatabaseDefaults();
  1898. blocktablerecord.AppendEntity(text21);
  1899. traction.AddNewlyCreatedDBObject(text21, true);
  1900. //Y坐标上标
  1901. xx1 = xx + D7;
  1902. yy1 = yy + D2 + D4_8 - D3;
  1903. DBText text22 = new DBText();
  1904. int value22 = (int)(RB.Y / 1000 / 100);
  1905. text22.TextString = value18.ToString();
  1906. text22.Position = new Point3d(xx1, yy1, 0);
  1907. text22.Height = D3;
  1908. text22.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 3);
  1909. text22.Layer = layername;
  1910. text22.HorizontalMode = TextHorizontalMode.TextRight;
  1911. text22.VerticalMode = TextVerticalMode.TextTop;
  1912. xx2 = xx + D7;
  1913. yy2 = yy + D2 + D4_8;
  1914. text22.AlignmentPoint = new Point3d(xx2, yy2, 0);
  1915. text22.TextStyleId = HZ;
  1916. text22.WidthFactor = 0.75;
  1917. text22.SetDatabaseDefaults();
  1918. blocktablerecord.AppendEntity(text22);
  1919. traction.AddNewlyCreatedDBObject(text22, true);
  1920. document.Database.SaveAs(TKInfo.SV + "\\" + Number.ToString() + ".dwg", true, DwgVersion.AC1021, document.Database.SecurityParameters);
  1921. //database.SaveAs(TKInfo.SV + "\\" + Number.ToString() + ".dwg", DwgVersion.AC1024);
  1922. traction.Commit();
  1923. //}
  1924. //catch (GrxCAD.Runtime.Exception e)
  1925. //{
  1926. // MessageBox.Show (e.Message);
  1927. //}
  1928. //finally
  1929. //{
  1930. traction.Dispose();
  1931. documentlock.Dispose();
  1932. //}
  1933. }
  1934. public void createTextStyle()
  1935. {
  1936. Database database = HostApplicationServices.WorkingDatabase;
  1937. Transaction traction = database.TransactionManager.StartTransaction();
  1938. DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  1939. TextStyleTable styletable = traction.GetObject(database.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
  1940. string stylename = "ht";
  1941. if (styletable.Has(stylename) == false)
  1942. {
  1943. TextStyleTableRecord R1 = new TextStyleTableRecord();
  1944. R1.Name = stylename;
  1945. //R1.FileName = "方正细等线简体";
  1946. R1.FileName = "SIMHEI.TTF";
  1947. //record.BigFontFileName = "hztxt.shx";
  1948. R1.ObliquingAngle = 0;
  1949. R1.XScale = 1;
  1950. ObjectId textstyleID = styletable.Add(R1);
  1951. traction.AddNewlyCreatedDBObject(R1, true);
  1952. //database.TextStyleId = textstyleID;
  1953. }
  1954. stylename = "HZ";
  1955. if (styletable.Has(stylename) == false)
  1956. {
  1957. TextStyleTableRecord R1 = new TextStyleTableRecord();
  1958. R1.Name = stylename;
  1959. //R1.FileName = "方正细等线简体";
  1960. R1.FileName = "rs.shx";
  1961. R1.BigFontFileName = "hztxt.shx";
  1962. R1.ObliquingAngle = 0;
  1963. R1.XScale = 0.75;
  1964. ObjectId textstyleID = styletable.Add(R1);
  1965. traction.AddNewlyCreatedDBObject(R1, true);
  1966. //database.TextStyleId = textstyleID;
  1967. }
  1968. stylename = "st";
  1969. if (styletable.Has(stylename) == false)
  1970. {
  1971. TextStyleTableRecord R1 = new TextStyleTableRecord();
  1972. R1.Name = stylename;
  1973. //R1.FileName = "方正细等线简体";
  1974. R1.FileName = "STSONG.TTF";
  1975. //R1.BigFontFileName = "hztxt.shx";
  1976. R1.ObliquingAngle = 0;
  1977. R1.XScale = 1;
  1978. ObjectId textstyleID = styletable.Add(R1);
  1979. traction.AddNewlyCreatedDBObject(R1, true);
  1980. //database.TextStyleId = textstyleID;
  1981. }
  1982. stylename = "Standard";
  1983. if (styletable.Has(stylename) == false)
  1984. {
  1985. TextStyleTableRecord R1 = new TextStyleTableRecord();
  1986. R1.Name = stylename;
  1987. //R1.FileName = "方正细等线简体";
  1988. R1.FileName = "rs.shx";
  1989. R1.BigFontFileName = "hztxt.shx";
  1990. R1.ObliquingAngle = 0;
  1991. R1.XScale = 0.75;
  1992. ObjectId textstyleID = styletable.Add(R1);
  1993. traction.AddNewlyCreatedDBObject(R1, true);
  1994. //database.TextStyleId = textstyleID;
  1995. }
  1996. stylename = "123";
  1997. if (styletable.Has(stylename) == false)
  1998. {
  1999. TextStyleTableRecord R1 = new TextStyleTableRecord();
  2000. R1.Name = stylename;
  2001. //R1.FileName = "方正细等线简体";
  2002. R1.FileName = "SIMHEI.TTF";
  2003. //R1.BigFontFileName = "hztxt.shx";
  2004. R1.ObliquingAngle = 0;
  2005. R1.XScale = 0.75;
  2006. ObjectId textstyleID = styletable.Add(R1);
  2007. traction.AddNewlyCreatedDBObject(R1, true);
  2008. //database.TextStyleId = textstyleID;
  2009. }
  2010. stylename = "12";
  2011. if (styletable.Has(stylename) == false)
  2012. {
  2013. TextStyleTableRecord R1 = new TextStyleTableRecord();
  2014. R1.Name = stylename;
  2015. //R1.FileName = "方正细等线简体";
  2016. R1.FileName = "complex.shx";
  2017. //R1.BigFontFileName = "hztxt.shx";
  2018. R1.ObliquingAngle = 0;
  2019. R1.XScale = 0.75;
  2020. ObjectId textstyleID = styletable.Add(R1);
  2021. traction.AddNewlyCreatedDBObject(R1, true);
  2022. //database.TextStyleId = textstyleID;
  2023. }
  2024. stylename = "细等线体";
  2025. if (styletable.Has(stylename) == false)
  2026. {
  2027. TextStyleTableRecord R1 = new TextStyleTableRecord();
  2028. R1.Name = stylename;
  2029. //R1.FileName = "方正细等线简体";
  2030. R1.FileName = "FZXDXJW.TTF";
  2031. //record.BigFontFileName = "hztxt.shx";
  2032. R1.ObliquingAngle = 0;
  2033. R1.XScale = 1;
  2034. ObjectId textstyleID = styletable.Add(R1);
  2035. traction.AddNewlyCreatedDBObject(R1, true);
  2036. //database.TextStyleId = textstyleID;
  2037. }
  2038. stylename = "中等线体";
  2039. if (styletable.Has(stylename) == false)
  2040. {
  2041. TextStyleTableRecord R2 = new TextStyleTableRecord();
  2042. R2.Name = stylename;
  2043. //R2.FileName = "方正中等线简体";
  2044. R2.FileName = "FZZDXJW.TTF";
  2045. //record.BigFontFileName = "hztxt.shx";
  2046. R2.ObliquingAngle = 0;
  2047. R2.XScale = 1;
  2048. ObjectId textstyleID = styletable.Add(R2);
  2049. traction.AddNewlyCreatedDBObject(R2, true);
  2050. //database.TextStyleId = textstyleID;
  2051. }
  2052. stylename = "宋体";
  2053. if (styletable.Has(stylename) == false)
  2054. {
  2055. TextStyleTableRecord R3 = new TextStyleTableRecord();
  2056. R3.Name = stylename;
  2057. //R3.FileName = "华文宋体";
  2058. R3.FileName = "STSONG.TTF";
  2059. //record.BigFontFileName = "hztxt.shx";
  2060. R3.ObliquingAngle = 0;
  2061. R3.XScale = 1;
  2062. ObjectId textstyleID = styletable.Add(R3);
  2063. traction.AddNewlyCreatedDBObject(R3, true);
  2064. //database.TextStyleId = textstyleID;
  2065. }
  2066. traction.Commit();
  2067. documentlock.Dispose();
  2068. }
  2069. public ObjectId gettextstyleID(string Name)
  2070. {
  2071. Database database = HostApplicationServices.WorkingDatabase;
  2072. Transaction traction = database.TransactionManager.StartTransaction();
  2073. DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  2074. TextStyleTable styletable = traction.GetObject(database.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
  2075. //BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
  2076. // OpenMode.ForWrite) as BlockTableRecord;
  2077. TextStyleTableRecord record = traction.GetObject(styletable[Name], OpenMode.ForRead) as TextStyleTableRecord;
  2078. ObjectId ID = record.ObjectId;
  2079. traction.Commit();
  2080. documentlock.Dispose();
  2081. return ID;
  2082. }
  2083. private void zoom()
  2084. {
  2085. Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  2086. Database database = HostApplicationServices.WorkingDatabase;
  2087. Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  2088. using (Transaction traction = database.TransactionManager.StartTransaction())
  2089. {
  2090. //删除坐标原点多段线
  2091. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  2092. Point3d pt1 = new Point3d(-1, 1, 0);
  2093. Point3d pt2 = new Point3d(0, 0, 0);
  2094. PromptSelectionResult psr = ed.SelectCrossingWindow(pt1, pt2);
  2095. if (psr.Status == PromptStatus.OK)
  2096. {
  2097. SelectionSet sSet = psr.Value;
  2098. ObjectId[] ids = sSet.GetObjectIds();
  2099. foreach (ObjectId id in ids)
  2100. {
  2101. Entity entity1 = traction.GetObject(id, OpenMode.ForWrite) as Entity;
  2102. entity1.Erase();
  2103. }
  2104. }
  2105. ViewTableRecord currview = editor.GetCurrentView();
  2106. currview.CenterPoint = new Point2d((RT.X - LT.X) / 2 + LT.X, (LT.Y - LB.Y) / 2 + LB.Y);
  2107. currview.ViewDirection = new Vector3d(0, 0, 1);
  2108. currview.Width = RT.X - LT.X + TKInfo.BLC / 10;
  2109. currview.Height = LT.Y - LB.Y + TKInfo.BLC / 10;
  2110. editor.SetCurrentView(currview);
  2111. traction.Commit();
  2112. }
  2113. }
  2114. private string GetNumber(Point3d p1, Point3d p2)
  2115. {
  2116. string TValue = "";
  2117. Document document = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  2118. Database database = HostApplicationServices.WorkingDatabase;
  2119. using (Transaction traction = database.TransactionManager.StartTransaction())
  2120. {
  2121. DocumentLock documentlock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  2122. BlockTable blocktable = traction.GetObject(database.BlockTableId,
  2123. OpenMode.ForRead) as BlockTable;
  2124. Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  2125. TypedValue[] typed = new TypedValue[1];
  2126. typed.SetValue(new TypedValue((int)DxfCode.Start, "Polyline,LWPolyline"), 0);
  2127. SelectionFilter filter = new SelectionFilter(typed);
  2128. PromptSelectionResult psr = editor.SelectWindow(p1, p2, filter);
  2129. if (psr.Status == PromptStatus.OK)
  2130. {
  2131. SelectionSet selectionset = psr.Value;
  2132. ObjectId[] obj = new ObjectId[selectionset.Count];
  2133. obj = selectionset.GetObjectIds();
  2134. for (int i = 0; i < obj.Length; i++)
  2135. {
  2136. ObjectId objid = obj[i];
  2137. Entity entity = (Entity)traction.GetObject(objid, OpenMode.ForRead);
  2138. if (entity is Face)
  2139. {
  2140. TypedValue[] typed_T = new TypedValue[1];
  2141. typed_T.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0);
  2142. SelectionFilter filter_T = new SelectionFilter(typed_T);
  2143. PromptSelectionResult psr_T = editor.SelectWindow(p1, p2, filter_T);
  2144. if (psr_T.Status == PromptStatus.OK)
  2145. {
  2146. SelectionSet set_T = psr_T.Value;
  2147. ObjectId[] obj_T = new ObjectId[set_T.Count];
  2148. obj_T = set_T.GetObjectIds();
  2149. for (int j = 0; j < obj_T.Length; j++)
  2150. {
  2151. ObjectId id_T = obj_T[i];
  2152. Entity entits = (Entity)traction.GetObject(id_T, OpenMode.ForRead);
  2153. if (entits is DBText)
  2154. {
  2155. DBText text = entits as DBText;
  2156. TValue = text.TextString;
  2157. break;
  2158. }
  2159. }
  2160. }
  2161. break;
  2162. }
  2163. else if (entity is Polyline)
  2164. {
  2165. TypedValue[] typed_T = new TypedValue[1];
  2166. typed_T.SetValue(new TypedValue((int)DxfCode.Start, "Text"), 0);
  2167. SelectionFilter filter_T = new SelectionFilter(typed_T);
  2168. PromptSelectionResult psr_T = editor.SelectWindow(p1, p2, filter_T);
  2169. if (psr_T.Status == PromptStatus.OK)
  2170. {
  2171. SelectionSet set_T = psr_T.Value;
  2172. ObjectId[] obj_T = new ObjectId[set_T.Count];
  2173. obj_T = set_T.GetObjectIds();
  2174. for (int j = 0; j < obj_T.Length; j++)
  2175. {
  2176. ObjectId id_T = obj_T[i];
  2177. Entity entits = (Entity)traction.GetObject(id_T, OpenMode.ForRead);
  2178. if (entits is DBText)
  2179. {
  2180. DBText text = entits as DBText;
  2181. TValue = text.TextString;
  2182. break;
  2183. }
  2184. }
  2185. }
  2186. break;
  2187. }
  2188. }
  2189. }
  2190. documentlock.Dispose();
  2191. traction.Commit();
  2192. }
  2193. return TValue;
  2194. }
  2195. private void filjtb(string num,Transaction traction,ObjectId HZ,BlockTableRecord blocktablerecord,double xx2,double yy2,double height)
  2196. {
  2197. DBText text_L = new DBText();
  2198. text_L.TextString = num;
  2199. text_L.Position = new Point3d(xx2, yy2, 0);
  2200. text_L.Height = height;
  2201. text_L.Color = GrxCAD.Colors.Color.FromColorIndex(GrxCAD.Colors.ColorMethod.ByColor, 4);
  2202. text_L.Layer = layername;
  2203. text_L.TextStyleId = HZ;
  2204. text_L.HorizontalMode = TextHorizontalMode.TextCenter;
  2205. text_L.VerticalMode = TextVerticalMode.TextVerticalMid;
  2206. text_L.AlignmentPoint = new Point3d(xx2, yy2, 0);
  2207. text_L.SetDatabaseDefaults();
  2208. blocktablerecord.AppendEntity(text_L);
  2209. traction.AddNewlyCreatedDBObject(text_L, true);
  2210. }
  2211. }
  2212. }