工具箱相关
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CMCgis_Basicfunction.cs 115KB

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