工具箱相关
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

getThumbnail.cs 145KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433
  1. using GrxCAD.ApplicationServices;
  2. using GrxCAD.DatabaseServices;
  3. using GrxCAD.EditorInput;
  4. using GrxCAD.Geometry;
  5. using GrxCAD.Runtime;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace Thumbnail
  14. {
  15. public class tkinfo
  16. {
  17. public Point3dCollection ptcoll; //图幅框节点
  18. public string tfh; //节点
  19. public ObjectId id; //图幅框id
  20. public ObjectId tfhid; //图幅号id
  21. }
  22. public class getThumbnail
  23. {
  24. public static double bl;
  25. public static string tc_tk;
  26. public static string tc_tfh;
  27. //public static int jtk;
  28. /// <summary>
  29. /// 替换接图框
  30. /// </summary>
  31. public void openDwg(String fileName, String insertpath, String savepath)
  32. {
  33. DirectoryInfo root = new DirectoryInfo(fileName);
  34. List<String> filename = new List<string>(); //文件名
  35. FileInfo[] files = root.GetFiles();
  36. foreach (FileInfo file in files)
  37. {
  38. if (!file.Name.Contains(".dwg"))
  39. continue;
  40. else
  41. filename.Add(file.Name);
  42. }
  43. for (int filenum = 0; filenum < filename.Count; filenum++)
  44. {
  45. string fileName2 = fileName + "\\" + filename[filenum];
  46. Document doc = GrxCAD.ApplicationServices.Application.DocumentManager.Add(fileName2);
  47. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  48. List<tkinfo> tf = new List<tkinfo>(); //与本图幅相交的图幅
  49. List<tkinfo> tkinfolist = new List<tkinfo>(); //存放图框坐标和图幅号
  50. //using (DocumentLock docLock = doc.LockDocument())
  51. //{
  52. Point3dCollection ptcoll = new Point3dCollection();
  53. TypedValue[] value = new TypedValue[]
  54. {
  55. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE"),
  56. new TypedValue((int)DxfCode.LayerName,"9800")
  57. };
  58. SelectionFilter filter = new SelectionFilter(value);
  59. PromptSelectionResult psr = ed.SelectAll(filter);
  60. //获取9800图层中最长的四条线,它们的交点即为内图框角点
  61. if (psr.Status == PromptStatus.OK)
  62. {
  63. ObjectIdCollection pllcoll = new ObjectIdCollection();
  64. SelectionSet ss = psr.Value;
  65. ObjectIdCollection idcoll1 = new ObjectIdCollection(ss.GetObjectIds());
  66. for (int i = 0; i < idcoll1.Count; i++)
  67. {
  68. using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
  69. {
  70. Entity ent = trans.GetObject(idcoll1[i], OpenMode.ForRead) as Entity;
  71. if (ent is Polyline)
  72. {
  73. Polyline pll = (Polyline)ent;
  74. if (pll.Length == 250 * bl + 5.75 * bl * 2 & pll.Closed == false)
  75. pllcoll.Add(idcoll1[i]);
  76. }
  77. if (ent is Polyline2d)
  78. {
  79. Polyline2d pll = (Polyline2d)ent;
  80. if (pll.Length == 250 * bl + 5.75 * bl * 2 & pll.Closed == false)
  81. pllcoll.Add(idcoll1[i]);
  82. }
  83. trans.Commit();
  84. }
  85. }
  86. getIntersectpts(pllcoll, doc, ptcoll);
  87. }
  88. sortpts(ptcoll);
  89. deletetc(doc, ptcoll);
  90. copytoCurrent(doc, insertpath, true);
  91. getTKinfo(doc, tkinfolist);//获取图框信息
  92. getIntersecttk(tkinfolist, ptcoll, tf);
  93. move(doc, tkinfolist, tf, ptcoll);
  94. deletetk(doc, tkinfolist, tf);
  95. ObjectId HZ= createTextStyle(doc);
  96. draw(doc, ptcoll, tf, HZ);
  97. if (tf.Count == 0 || tf == null)
  98. {
  99. for (int i = 0; i < tkinfolist.Count; i++)
  100. {
  101. using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
  102. {
  103. BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
  104. BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  105. Point3dCollection pts = new Point3dCollection();
  106. Entity ent1 = tran.GetObject(tkinfolist[i].id, OpenMode.ForWrite) as Entity;
  107. Entity ent2 = tran.GetObject(tkinfolist[i].tfhid, OpenMode.ForWrite) as Entity;
  108. ent1.Erase();
  109. ent2.Erase();
  110. if (i == tkinfolist.Count - 1)
  111. {
  112. LayerTable layerTable = tran.GetObject(doc.Database.LayerTableId, OpenMode.ForWrite) as LayerTable;
  113. LayerTableRecord layer = tran.GetObject(layerTable[tc_tfh], OpenMode.ForWrite) as LayerTableRecord;
  114. layer.Erase(true);
  115. if (tc_tfh != tc_tk)
  116. {
  117. layer = tran.GetObject(layerTable[tc_tk], OpenMode.ForWrite) as LayerTableRecord;
  118. layer.Erase(true); // 删除图层
  119. }
  120. }
  121. tran.Commit();
  122. }
  123. }
  124. }
  125. //}
  126. dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  127. acadApp.ZoomExtents();
  128. doc.Database.SaveAs(savepath + "\\" + filename[filenum], true, DwgVersion.AC1024, doc.Database.SecurityParameters);
  129. doc.CloseAndDiscard();
  130. }
  131. MessageBox.Show("替换完成");
  132. }
  133. /// <summary>
  134. /// 获取图框信息
  135. /// </summary>
  136. private void getTKinfo(Document doc, List<tkinfo> tkinfolist)
  137. {
  138. //获取图框和图幅号
  139. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  140. TypedValue[] value = new TypedValue[]
  141. {
  142. new TypedValue((int)DxfCode.LayerName,tc_tk),
  143. new TypedValue((int)DxfCode.Start,"LWPOLYLINE")
  144. };
  145. SelectionFilter filter = new SelectionFilter(value);
  146. PromptSelectionResult psr = ed.SelectAll(filter);
  147. TypedValue[] value_text = new TypedValue[]
  148. {
  149. new TypedValue((int)DxfCode.Start,"Text"),
  150. new TypedValue((int)DxfCode.LayerName,tc_tfh)
  151. };
  152. SelectionFilter filter_text = new SelectionFilter(value_text);
  153. PromptSelectionResult psr_text = ed.SelectAll(filter_text);
  154. if (psr.Status == PromptStatus.OK && psr_text.Status == PromptStatus.OK)
  155. {
  156. SelectionSet ss = psr.Value;
  157. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  158. SelectionSet ss_text = psr_text.Value;
  159. ObjectIdCollection idcoll_text = new ObjectIdCollection(ss_text.GetObjectIds());
  160. for (int i = 0; i < idcoll.Count; i++)
  161. {
  162. int j = 0;
  163. int flag = 0;
  164. while (idcoll_text.Count != 0)
  165. {
  166. using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
  167. {
  168. Point3dCollection ptcoll = new Point3dCollection();
  169. Entity ent = tran.GetObject(idcoll[i], OpenMode.ForRead) as Entity;
  170. if (ent is Polyline)
  171. {
  172. Polyline pll = tran.GetObject(idcoll[i], OpenMode.ForRead) as Polyline;
  173. pll.GetStretchPoints(ptcoll);
  174. }
  175. if (ent is Polyline2d)
  176. {
  177. Polyline2d pll = tran.GetObject(idcoll[i], OpenMode.ForRead) as Polyline2d;
  178. pll.GetStretchPoints(ptcoll);
  179. }
  180. DBText text = tran.GetObject(idcoll_text[j], OpenMode.ForRead) as DBText;
  181. //获取框线角点并将其按特定顺序排列
  182. List<double> X = new List<double>();
  183. List<double> Y = new List<double>();
  184. for (int ii = 0; ii < 4; ii++)
  185. {
  186. if (!X.Contains(ptcoll[ii].X))
  187. X.Add(ptcoll[ii].X);
  188. if (!Y.Contains(ptcoll[ii].Y))
  189. Y.Add(ptcoll[ii].Y);
  190. }
  191. if (X[1] < X[0])
  192. {
  193. Double temp = X[0];
  194. X[0] = X[1];
  195. X[1] = temp;
  196. }
  197. if (Y[1] < Y[0])
  198. {
  199. Double temp = Y[0];
  200. Y[0] = Y[1];
  201. Y[1] = temp;
  202. }
  203. tkinfo pt = new tkinfo();
  204. pt.ptcoll = ptcoll;
  205. pt.id = idcoll[i];
  206. pt.tfhid = idcoll_text[j];
  207. //获取图幅号坐标
  208. double x = text.Position.X;
  209. double y = text.Position.Y;
  210. //判断图框对应图幅号
  211. if (x > X[0] && y > Y[0] && x < X[1] && y > Y[0] &&
  212. x < X[1] && y < Y[1] && x > X[0] && y < Y[1])
  213. {
  214. String tfh = text.TextString;
  215. pt.tfh = tfh;
  216. idcoll_text.RemoveAt(j);
  217. tkinfolist.Add(pt);
  218. flag = 1;
  219. }
  220. tran.Commit();
  221. if (flag == 1)
  222. break;
  223. }
  224. j = j + 1;
  225. }
  226. }
  227. }
  228. }
  229. /// <summary>
  230. /// 将分幅图加入当前视图
  231. /// </summary>
  232. private void copytoCurrent(Document doc, String insertpath, bool explode)
  233. {
  234. ObjectIdCollection idsToClone = new ObjectIdCollection();
  235. ObjectId btrId;
  236. //using (DocumentLock docTargetLock = doc.LockDocument())
  237. //{
  238. using (Transaction trTarget = doc.TransactionManager.StartTransaction())
  239. {
  240. LayerTable layerTable = trTarget.GetObject(doc.Database.LayerTableId, OpenMode.ForRead) as LayerTable;
  241. ObjectId layerId = layerTable["0"];
  242. doc.Database.Clayer = layerId;
  243. var targetBlockTable = trTarget.GetObject(doc.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
  244. var targetModelSpace = trTarget.GetObject(targetBlockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  245. btrId = targetModelSpace.ObjectId;
  246. trTarget.Commit();
  247. }
  248. using (var sourceDb = new Database(false, true))
  249. {
  250. sourceDb.ReadDwgFile(insertpath, FileOpenMode.OpenForReadAndAllShare, false, null);
  251. using (Transaction trSource = sourceDb.TransactionManager.StartTransaction())
  252. {
  253. var modelSpaceSource = trSource.GetObject(
  254. SymbolUtilityServices.GetBlockModelSpaceId(sourceDb),
  255. OpenMode.ForRead) as BlockTableRecord;
  256. foreach (ObjectId objId in modelSpaceSource)
  257. {
  258. var entity = trSource.GetObject(objId, OpenMode.ForRead) as Entity;
  259. if (entity != null && (entity.Layer == tc_tk || entity.Layer == tc_tfh))
  260. idsToClone.Add(objId);
  261. }
  262. using (var mapping = new IdMapping())
  263. sourceDb.WblockCloneObjects(idsToClone, btrId, mapping, DuplicateRecordCloning.Replace, false);
  264. trSource.Commit();
  265. }
  266. }
  267. //}
  268. }
  269. /// <summary>
  270. /// 获取内图框四个角点
  271. /// </summary>
  272. private void getIntersectpts(ObjectIdCollection pllcoll, Document doc, Point3dCollection ptcoll)
  273. {
  274. using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
  275. {
  276. for (int k = 0; k < pllcoll.Count - 1; k++)
  277. {
  278. Point3dCollection intersectpt = new Point3dCollection();
  279. for (int kk = k + 1; kk < pllcoll.Count; kk++)
  280. {
  281. Entity ent1 = trans.GetObject(pllcoll[k], OpenMode.ForRead) as Entity;
  282. Entity ent2 = trans.GetObject(pllcoll[kk], OpenMode.ForRead) as Entity;
  283. if (ent1 is Polyline && ent2 is Polyline)
  284. {
  285. Polyline pll1 = (Polyline)ent1;
  286. Polyline pll2 = (Polyline)ent2;
  287. pll1.IntersectWith(pll2, Intersect.OnBothOperands, intersectpt, IntPtr.Zero, IntPtr.Zero);
  288. //foreach (Point3d pt in intersectpt)
  289. //{
  290. // if (pt == pll1.StartPoint || pt == pll1.EndPoint ||pt = pll2.StartPoint || pt == pll2.EndPoint)
  291. // intersectpt.Remove(pt);
  292. //}
  293. }
  294. if (ent1 is Polyline2d && ent2 is Polyline2d)
  295. {
  296. Polyline2d pll1 = (Polyline2d)ent1;
  297. Polyline2d pll2 = (Polyline2d)ent2;
  298. pll1.IntersectWith(pll2, Intersect.OnBothOperands, intersectpt, IntPtr.Zero, IntPtr.Zero);
  299. }
  300. if (intersectpt.Count != 0)
  301. {
  302. for (int kkk = 0; kkk < intersectpt.Count; kkk++)
  303. {
  304. if (ptcoll.Contains(intersectpt[kkk]))
  305. continue;
  306. else
  307. ptcoll.Add(intersectpt[kkk]);
  308. }
  309. }
  310. }
  311. }
  312. trans.Commit();
  313. }
  314. }
  315. /// <summary>
  316. /// 获取与当前图幅相交的图框
  317. /// </summary>
  318. private void getIntersecttk(List<tkinfo> tkinfolist, Point3dCollection ptcoll, List<tkinfo> tf)
  319. {
  320. //ObjectIdCollection ids= new ObjectIdCollection();
  321. for (int j = 0; j < tkinfolist.Count; j++)
  322. {
  323. //找出tkinfolist中的此图幅
  324. if (tkinfolist[j].ptcoll.Contains(ptcoll[0]) && tkinfolist[j].ptcoll.Contains(ptcoll[1]) &&
  325. tkinfolist[j].ptcoll.Contains(ptcoll[2]) && tkinfolist[j].ptcoll.Contains(ptcoll[3]))
  326. {
  327. sortpts(tkinfolist[j].ptcoll);
  328. double plusnum = Math.Abs(tkinfolist[j].ptcoll[0].X - tkinfolist[j].ptcoll[2].X);
  329. //创建扩大一倍的窗口搜索相交图幅
  330. Point3d pt1 = new Point3d(tkinfolist[j].ptcoll[0].X - plusnum, tkinfolist[j].ptcoll[0].Y - plusnum, 0);
  331. Point3d pt2 = new Point3d(tkinfolist[j].ptcoll[2].X + plusnum, tkinfolist[j].ptcoll[2].Y + plusnum, 0);
  332. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  333. TypedValue[] value = new TypedValue[]
  334. {
  335. new TypedValue((int)DxfCode.LayerName,tc_tk)
  336. };
  337. SelectionFilter filter = new SelectionFilter(value);
  338. dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  339. acadApp.ZoomExtents();
  340. //使用找出的图幅号内框线交点进行相交选择以选出与此图幅相交的其他图幅
  341. //PromptSelectionResult psr = ed.SelectCrossingPolygon(tkinfolist[j].ptcoll, filter);
  342. //ViewTableRecord view = ed.GetCurrentView();
  343. //view.Width = Math.Abs(3* (ptcoll[0].X - ptcoll[1].X));
  344. //view.Height = Math.Abs(3 * (ptcoll[0].Y - ptcoll[2].Y));
  345. //view.CenterPoint = new Point2d(
  346. // ptcoll[0].X + Math.Abs((ptcoll[0].X - ptcoll[1].X)) / 2,
  347. // ptcoll[0].Y + Math.Abs((ptcoll[0].Y - ptcoll[2].Y)) / 2
  348. //);
  349. //ed.SetCurrentView(view);
  350. PromptSelectionResult psr = ed.SelectCrossingWindow(pt1, pt2, filter);
  351. acadApp.ZoomPrevious();
  352. if (psr.Status == PromptStatus.OK)
  353. {
  354. SelectionSet ss = psr.Value;
  355. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  356. for (int i = 0; i < idcoll.Count; i++)
  357. {
  358. if (idcoll[i] != tkinfolist[j].id)
  359. {
  360. //ids.Add(idcoll[i]);
  361. for (int ii = 0; ii < tkinfolist.Count; ii++)
  362. {
  363. if (idcoll[i] == tkinfolist[ii].id)
  364. {
  365. //获取相交图幅的相应信息
  366. foreach (Point3d temppt in tkinfolist[ii].ptcoll)
  367. {
  368. //筛选窗口内图幅
  369. if (temppt.X > pt1.X && temppt.X < pt2.X &&
  370. temppt.Y > pt1.Y && temppt.Y < pt2.Y)
  371. {
  372. tkinfo pt = new tkinfo();
  373. pt.id = tkinfolist[ii].id;
  374. pt.ptcoll = tkinfolist[ii].ptcoll;
  375. pt.tfh = tkinfolist[ii].tfh;
  376. pt.tfhid = tkinfolist[ii].tfhid;
  377. tf.Add(pt);
  378. break;
  379. }
  380. }
  381. }
  382. }
  383. }
  384. }
  385. }
  386. break;
  387. }
  388. }
  389. }
  390. /// <summary>
  391. /// 将图框移动到接图框位置
  392. /// </summary>
  393. private void move(Document doc, List<tkinfo> tkinfolist, List<tkinfo> tf, Point3dCollection ptcoll)
  394. {
  395. Point3d Frompt = new Point3d(ptcoll[0].X - (261.5 * bl - 5.75 * bl * 2), ptcoll[0].Y - (261.5 * bl - 5.75 * bl * 2), 0);//基点
  396. Point3d Topt = new Point3d(ptcoll[3].X, ptcoll[3].Y + 5.75 * bl + 1.75 * bl, 0);//目标点
  397. for (int i = 0; i < tf.Count; i++)
  398. {
  399. for (int j = 0; j < tkinfolist.Count; j++)
  400. {
  401. if (tf[i].id == tkinfolist[j].id)
  402. {
  403. using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
  404. {
  405. Entity ent = trans.GetObject(tkinfolist[j].id, OpenMode.ForWrite) as Entity;
  406. DBText text = trans.GetObject(tkinfolist[j].tfhid, OpenMode.ForWrite) as DBText;
  407. String txt = text.TextString;
  408. //使输出图幅号为三位数
  409. if (txt[0].ToString() == "0")
  410. {
  411. if (txt[1].ToString() == "0")
  412. {
  413. text.TextString = txt[2].ToString();
  414. }
  415. else
  416. {
  417. text.TextString = txt[1].ToString() + txt[2].ToString();
  418. }
  419. }
  420. Double scalenum = (22.5 * bl / 3) / (261.5 * bl - 5.75 * bl * 2);//缩放比
  421. Vector3d acVec3d = Frompt.GetVectorTo(Topt);
  422. Matrix3d mt = Matrix3d.Scaling(scalenum, Topt);
  423. if (ent is Polyline)
  424. {
  425. Polyline pll = (Polyline)ent;
  426. pll.TransformBy(Matrix3d.Displacement(acVec3d));
  427. pll.TransformBy(mt);
  428. }
  429. if (ent is Polyline2d)
  430. {
  431. Polyline2d pll = (Polyline2d)ent;
  432. pll.TransformBy(Matrix3d.Displacement(acVec3d));
  433. pll.TransformBy(mt);
  434. }
  435. text.TransformBy(Matrix3d.Displacement(acVec3d));
  436. text.TransformBy(mt);
  437. Matrix3d mt1 = Matrix3d.Scaling(3, new Point3d(text.AlignmentPoint.X, text.AlignmentPoint.Y, 0));
  438. text.TransformBy(mt1);
  439. trans.Commit();
  440. }
  441. }
  442. }
  443. }
  444. }
  445. /// <summary>
  446. /// 删除9800图层
  447. /// </summary>
  448. private void deletetc(Document doc, Point3dCollection ptcoll)
  449. {
  450. Editor ed = doc.Editor;
  451. TypedValue[] value_tfk = new TypedValue[]
  452. {
  453. new TypedValue((int)DxfCode.LayerName,"9800")
  454. };
  455. SelectionFilter filter_tfk = new SelectionFilter(value_tfk);
  456. Point3d pt1 = new Point3d(ptcoll[3].X, ptcoll[3].Y + 5.75 * bl + 1.75 * bl, 0);
  457. Point3d pt2 = new Point3d(ptcoll[3].X + 22.5 * bl, ptcoll[3].Y + (5.5 + 0.5 + 1.5) * bl + 12 * bl + 10, 0);
  458. //dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  459. //acadApp.ZoomExtents();
  460. //using (DocumentLock docTargetLock = doc.LockDocument())
  461. //{
  462. using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
  463. {
  464. ViewTableRecord view = ed.GetCurrentView();
  465. view.Width = 22.5 * bl + 1;
  466. view.Height = 12 * bl + 1;
  467. view.CenterPoint = new Point2d(
  468. pt1.X + Math.Abs((pt1.X - pt2.X)) / 2,
  469. pt1.Y + Math.Abs((pt2.Y - 10 - pt1.Y)) / 2
  470. );
  471. ed.SetCurrentView(view);
  472. tr.Commit();
  473. }
  474. //}
  475. PromptSelectionResult psr_tfk = ed.SelectCrossingWindow(pt1, pt2, filter_tfk);
  476. //acadApp.ZoomPrevious();
  477. if (psr_tfk.Status == PromptStatus.OK)
  478. {
  479. SelectionSet ss = psr_tfk.Value;
  480. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  481. for (int i = 0; i < idcoll.Count; i++)
  482. {
  483. //using (DocumentLock docTargetLock = doc.LockDocument())
  484. //{
  485. using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
  486. {
  487. Entity ent = trans.GetObject(idcoll[i], OpenMode.ForWrite) as Entity;
  488. ent.Erase();
  489. trans.Commit();
  490. }
  491. }
  492. }
  493. //}
  494. }
  495. /// <summary>
  496. /// 删除除了相交图框以外的图框和相应图幅号
  497. /// </summary>
  498. private void deletetk(Document doc, List<tkinfo> tkinfolist, List<tkinfo> tf)
  499. {
  500. ObjectIdCollection deleteid = new ObjectIdCollection();
  501. ObjectIdCollection deletetfhid = new ObjectIdCollection();
  502. ObjectIdCollection tfid = new ObjectIdCollection();
  503. for (int i = 0; i < tf.Count; i++)
  504. {
  505. tfid.Add(tf[i].id);
  506. }
  507. for (int i = 0; i < tf.Count; i++)
  508. {
  509. for (int j = 0; j < tkinfolist.Count; j++)
  510. {
  511. if (tf[i].id != tkinfolist[j].id)
  512. {
  513. if (!deleteid.Contains(tkinfolist[j].id) && !tfid.Contains(tkinfolist[j].id))
  514. {
  515. deleteid.Add(tkinfolist[j].id);
  516. deletetfhid.Add(tkinfolist[j].tfhid);
  517. }
  518. }
  519. }
  520. }
  521. for (int k = 0; k < deleteid.Count; k++)
  522. {
  523. using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
  524. {
  525. Entity ent = trans.GetObject(deleteid[k], OpenMode.ForWrite) as Entity;
  526. DBText text = trans.GetObject(deletetfhid[k], OpenMode.ForWrite) as DBText;
  527. ent.Erase();
  528. text.Erase();
  529. trans.Commit();
  530. }
  531. }
  532. }
  533. /// <summary>
  534. /// 点排序
  535. /// </summary>
  536. private void sortpts(Point3dCollection ptcoll)
  537. {
  538. List<double> x = new List<double>();
  539. List<double> y = new List<double>();
  540. for (int i = 0; i < 4; i++)
  541. {
  542. if (!x.Contains(ptcoll[i].X))
  543. x.Add(ptcoll[i].X);
  544. if (!y.Contains(ptcoll[i].Y))
  545. y.Add(ptcoll[i].Y);
  546. }
  547. if (x[0] > x[1])
  548. {
  549. double temp = x[0];
  550. x[0] = x[1];
  551. x[1] = temp;
  552. }
  553. if (y[0] > y[1])
  554. {
  555. double temp = y[0];
  556. y[0] = y[1];
  557. y[1] = temp;
  558. }
  559. ptcoll[0] = new Point3d(x[0], y[0], 0); //左下
  560. ptcoll[1] = new Point3d(x[1], y[0], 0); //右下
  561. ptcoll[2] = new Point3d(x[1], y[1], 0); //右上
  562. ptcoll[3] = new Point3d(x[0], y[1], 0); //左上
  563. }
  564. /// <summary>
  565. /// 绘制接图表
  566. /// </summary>
  567. private void draw(Document doc, Point3dCollection ptcoll, List<tkinfo> tf,ObjectId HZ)
  568. {
  569. Point2d p1 = new Point2d();
  570. Point2d p2 = new Point2d();
  571. double x = ptcoll[3].X;
  572. double y = ptcoll[3].Y;
  573. double dist_l = 22.5 * bl / 3; //长
  574. double dist_w = 12 * bl / 3; //宽
  575. double dist_nw = 5.75 * bl; //内外框距离
  576. double dist_w2jt = 1.75 * bl; //外框到接图表距离
  577. double dist_tc = Math.Sqrt((0.5 * bl) * (0.5 * bl) * 2);
  578. double dist_tc1 = 0.404 * bl;
  579. List<tkinfo> zj_x = new List<tkinfo>();//只有x方向中间错位的图框
  580. List<tkinfo> zj_y = new List<tkinfo>();//只有y方向中间错位的图框
  581. //double cw_x = -9999;//错位图框左下角x坐标
  582. //double cw_y = -9999;//错位图框左下角y坐标
  583. Point3dCollection cw_x = new Point3dCollection();//x方向错位图框左下角点
  584. Point3dCollection cw_y = new Point3dCollection();//y方向错位图框左下角点
  585. using (Transaction trans = doc.Database.TransactionManager.StartTransaction())
  586. {
  587. BlockTable bt = (BlockTable)trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
  588. BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  589. //长
  590. Polyline pll1 = new Polyline();
  591. p1 = new Point2d(x, y + dist_nw + dist_w2jt);
  592. p2 = new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt);
  593. pll1.AddVertexAt(0, p1, 0, 0, 0);
  594. pll1.AddVertexAt(1, p2, 0, 0, 0);
  595. pll1.Layer = "9800";
  596. pll1.Linetype = "Bylayer";
  597. pll1.SetDatabaseDefaults();
  598. btr.AppendEntity(pll1);
  599. trans.AddNewlyCreatedDBObject(pll1, true);
  600. for (int i = 1; i < 4; i++)
  601. {
  602. Point3d targetPt = new Point3d(x, y + dist_nw + dist_w2jt + dist_w * i, 0);
  603. Point3d FromPt = new Point3d(x, y + dist_nw + dist_w2jt, 0);
  604. Vector3d acVec3d = FromPt.GetVectorTo(targetPt);
  605. Matrix3d mt = Matrix3d.Displacement(acVec3d);
  606. Entity entCopy = pll1.GetTransformedCopy(mt);
  607. btr.AppendEntity(entCopy);
  608. trans.AddNewlyCreatedDBObject(entCopy, true);
  609. }
  610. //宽
  611. Polyline pll2 = new Polyline();
  612. p1 = new Point2d(x, y + dist_nw + dist_w2jt);
  613. p2 = new Point2d(x, y + dist_nw + dist_w2jt + dist_w * 3);
  614. pll2.AddVertexAt(0, p1, 0, 0, 0);
  615. pll2.AddVertexAt(1, p2, 0, 0, 0);
  616. pll2.Layer = "9800";
  617. pll2.Linetype = "Bylayer";
  618. pll2.SetDatabaseDefaults();
  619. btr.AppendEntity(pll2);
  620. trans.AddNewlyCreatedDBObject(pll2, true);
  621. for (int i = 1; i < 4; i++)
  622. {
  623. Point3d targetPt = new Point3d(x + dist_l * i, y + dist_nw + dist_w2jt, 0);
  624. Point3d FromPt = new Point3d(x, y + dist_nw + dist_w2jt, 0);
  625. Vector3d acVec3d = FromPt.GetVectorTo(targetPt);
  626. Matrix3d mt = Matrix3d.Displacement(acVec3d);
  627. Entity entCopy = pll2.GetTransformedCopy(mt);
  628. btr.AppendEntity(entCopy);
  629. trans.AddNewlyCreatedDBObject(entCopy, true);
  630. }
  631. //中间
  632. double xx = x + dist_l;
  633. double yy = y + dist_nw + dist_w2jt + dist_w * 2;
  634. Point3dCollection coll = new Point3dCollection();
  635. coll.Add(new Point3d(xx, yy, 0));
  636. coll.Add(new Point3d(xx, yy - dist_w, 0));
  637. coll.Add(new Point3d(xx + dist_l, yy - dist_w, 0));
  638. coll.Add(new Point3d(xx + dist_l, yy, 0));
  639. coll.Add(new Point3d(xx, yy, 0));
  640. Polyline2d line2d = new Polyline2d(Poly2dType.SimplePoly, coll, 0, false, 0, 0, null);
  641. line2d.SetDatabaseDefaults();
  642. btr.AppendEntity(line2d);
  643. trans.AddNewlyCreatedDBObject(line2d, true);
  644. xx = xx + dist_tc1;
  645. for (int i = 0; i < 16; i++)
  646. {
  647. Line l = new Line();
  648. l.StartPoint = new Point3d(xx + 22.5 * bl, yy + 22.5 * bl, 0);
  649. l.EndPoint = new Point3d(xx - 22.5 * bl, yy - 22.5 * bl, 0);
  650. l.SetDatabaseDefaults();
  651. btr.AppendEntity(l);
  652. trans.AddNewlyCreatedDBObject(l, true);
  653. Point3dCollection IP = new Point3dCollection();
  654. l.IntersectWith(line2d, Intersect.ExtendThis, IP, IntPtr.Zero, IntPtr.Zero);
  655. Polyline pll3 = new Polyline();
  656. pll3.AddVertexAt(0, new Point2d(IP[0].X, IP[0].Y), 0, 0, 0);
  657. pll3.AddVertexAt(1, new Point2d(IP[1].X, IP[1].Y), 0, 0, 0);
  658. pll3.Layer = "9800";
  659. pll3.Linetype = "Bylayer";
  660. pll3.SetDatabaseDefaults();
  661. btr.AppendEntity(pll3);
  662. trans.AddNewlyCreatedDBObject(pll3, true);
  663. xx = xx + dist_tc;
  664. l.Erase();
  665. }
  666. line2d.Erase();
  667. //using (ViewTableRecord view = doc.Editor.GetCurrentView())
  668. //{
  669. // view.Width = Math.Abs(ptcoll[1].X - ptcoll[0].X);
  670. // view.Height = Math.Abs(ptcoll[1].X - ptcoll[0].X) + 60 * bl;
  671. // view.CenterPoint = new Point2d(
  672. // ptcoll[0].X + Math.Abs(ptcoll[1].X - ptcoll[0].X) / 2,
  673. // ptcoll[0].Y + Math.Abs(ptcoll[2].Y - ptcoll[0].Y) / 2
  674. // );
  675. // doc.Editor.SetCurrentView(view);
  676. //}
  677. //doc.Editor.Regen();
  678. trans.Commit();
  679. }
  680. //相交图幅
  681. for (int i = 0; i < tf.Count; i++)
  682. {
  683. using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
  684. {
  685. BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
  686. BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  687. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  688. Point3dCollection pts = new Point3dCollection();
  689. Polyline pll = tran.GetObject(tf[i].id, OpenMode.ForWrite) as Polyline;
  690. double bc = pll.Length / 4.0; //边长
  691. pll.GetStretchPoints(pts);
  692. sortpts(pts);
  693. double x_check = Math.Abs(Math.Round(pts[0].X - ptcoll[3].X, 5));
  694. double y_check = Math.Abs(Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5));
  695. double num_x = Math.Round(Math.Floor(x_check / bc), 3);
  696. double num_y = Math.Round(Math.Floor(y_check / bc), 3);
  697. double y_plus = (y_check % bc) * (dist_w / bc);
  698. //x、y方向都错位
  699. if (x_check % bc != 0 && y_check % bc != 0)
  700. {
  701. double y_plus_up = (Math.Abs(Math.Round(pts[1].Y - y - dist_nw - dist_w2jt, 5)) % bc) * (dist_w / bc);
  702. double y_plus_down = (Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5)) / bc * dist_w;
  703. //左上上
  704. if (pts[0].X < x && y_check / bc > 2)
  705. {
  706. Polyline pll_ad = new Polyline();
  707. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 3), 0, 0, 0);
  708. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  709. pll_ad.Layer = "9800";
  710. pll_ad.Linetype = "Bylayer";
  711. pll_ad.SetDatabaseDefaults();
  712. btr.AppendEntity(pll_ad);
  713. tran.AddNewlyCreatedDBObject(pll_ad, true);
  714. Polyline pll_ad1 = new Polyline();
  715. pll_ad1.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  716. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  717. pll_ad1.Layer = "9800";
  718. pll_ad1.Linetype = "Bylayer";
  719. pll_ad1.SetDatabaseDefaults();
  720. btr.AppendEntity(pll_ad1);
  721. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  722. //判断宽度和高度能否放下文字
  723. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  724. tfh_temp.TextStyleId = HZ;
  725. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  726. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  727. tfh_temp.AlignmentPoint = tfh_temp.Position;
  728. //计算图幅号位数
  729. int ws = tfh_temp.TextString.Length;
  730. double tfh_width = Math.Abs(pts[1].X - x);
  731. double tfh_height = Math.Abs((dist_w * (3 - num_y) - y_plus));
  732. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl) &&
  733. tfh_height > 1.25 * bl)
  734. {
  735. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  736. //图幅号y坐标计算
  737. double tfh_y = y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
  738. Point3d Topt_temp = new Point3d(x + (pts[1].X - x) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  739. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  740. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  741. tfh_temp.Layer = "9800";
  742. tfh_temp.ColorIndex = 4;
  743. tfh_temp.Height = 1.25 * bl;
  744. }
  745. else
  746. tfh_temp.Erase();
  747. }
  748. //左上下
  749. else if (pts[0].X < x && Math.Round(y_check / bc, 2) < 2 && Math.Round(y_check / bc, 2) > 1)
  750. {
  751. Polyline pll_ad = new Polyline();
  752. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  753. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
  754. pll_ad.Layer = "9800";
  755. pll_ad.Linetype = "Bylayer";
  756. pll_ad.SetDatabaseDefaults();
  757. btr.AppendEntity(pll_ad);
  758. tran.AddNewlyCreatedDBObject(pll_ad, true);
  759. Polyline pll_ad1 = new Polyline();
  760. pll_ad1.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
  761. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
  762. pll_ad1.Layer = "9800";
  763. pll_ad1.Linetype = "Bylayer";
  764. pll_ad1.SetDatabaseDefaults();
  765. btr.AppendEntity(pll_ad1);
  766. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  767. Polyline pll_ad2 = new Polyline();
  768. pll_ad2.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  769. pll_ad2.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  770. pll_ad2.Layer = "9800";
  771. pll_ad2.Linetype = "Bylayer";
  772. pll_ad2.SetDatabaseDefaults();
  773. btr.AppendEntity(pll_ad2);
  774. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  775. //判断宽度能否放下文字
  776. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  777. tfh_temp.TextStyleId = HZ;
  778. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  779. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  780. tfh_temp.AlignmentPoint = tfh_temp.Position;
  781. //计算图幅号位数
  782. int ws = tfh_temp.TextString.Length;
  783. double tfh_width = Math.Abs(pts[1].X - x);
  784. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl))
  785. {
  786. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  787. //图幅号y坐标计算
  788. double tfh_y = y + dist_nw + dist_w2jt + dist_w * 1.5 + y_plus;
  789. Point3d Topt_temp = new Point3d(x + (pts[1].X - x) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  790. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  791. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  792. tfh_temp.Layer = "9800";
  793. tfh_temp.ColorIndex = 4;
  794. tfh_temp.Height = 1.25 * bl;
  795. }
  796. else
  797. tfh_temp.Erase();
  798. Point3dCollection ptscoll = new Point3dCollection();
  799. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w * 2 + 0.01, 0));
  800. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w * 2, 0));
  801. Point3d bk = new Point3d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 2, 0);
  802. sele_dele(ptscoll, ed, tran, x, bk, btr);
  803. }
  804. //左下下
  805. if (pts[0].X < x && y_plus_down < 0)
  806. {
  807. Polyline pll_ad = new Polyline();
  808. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt), 0, 0, 0);
  809. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  810. pll_ad.Layer = "9800";
  811. pll_ad.Linetype = "Bylayer";
  812. pll_ad.SetDatabaseDefaults();
  813. btr.AppendEntity(pll_ad);
  814. tran.AddNewlyCreatedDBObject(pll_ad, true);
  815. Polyline pll_ad1 = new Polyline();
  816. pll_ad1.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  817. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  818. pll_ad1.Layer = "9800";
  819. pll_ad1.Linetype = "Bylayer";
  820. pll_ad1.SetDatabaseDefaults();
  821. btr.AppendEntity(pll_ad1);
  822. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  823. //判断宽度和高度能否放下文字
  824. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  825. tfh_temp.TextStyleId = HZ;
  826. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  827. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  828. tfh_temp.AlignmentPoint = tfh_temp.Position;
  829. //计算图幅号位数
  830. int ws = tfh_temp.TextString.Length;
  831. double tfh_width = Math.Abs(pts[1].X - x);
  832. double tfh_height = (dist_w - y_plus);
  833. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl) &&
  834. tfh_height > 1.25 * bl)
  835. {
  836. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  837. //图幅号y坐标计算
  838. double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
  839. Point3d Topt_temp = new Point3d(x + (pts[1].X - x) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  840. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  841. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  842. tfh_temp.Layer = "9800";
  843. tfh_temp.ColorIndex = 4;
  844. tfh_temp.Height = 1.25 * bl;
  845. }
  846. else
  847. tfh_temp.Erase();
  848. }
  849. //左下上
  850. else if (pts[0].X < x && y_plus_down < dist_w && y_plus_down > 0)
  851. {
  852. Polyline pll_ad = new Polyline();
  853. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  854. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
  855. pll_ad.Layer = "9800";
  856. pll_ad.Linetype = "Bylayer";
  857. pll_ad.SetDatabaseDefaults();
  858. btr.AppendEntity(pll_ad);
  859. tran.AddNewlyCreatedDBObject(pll_ad, true);
  860. Polyline pll_ad1 = new Polyline();
  861. pll_ad1.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
  862. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
  863. pll_ad1.Layer = "9800";
  864. pll_ad1.Linetype = "Bylayer";
  865. pll_ad1.SetDatabaseDefaults();
  866. btr.AppendEntity(pll_ad1);
  867. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  868. Polyline pll_ad2 = new Polyline();
  869. pll_ad2.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  870. pll_ad2.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  871. pll_ad2.Layer = "9800";
  872. pll_ad2.Linetype = "Bylayer";
  873. pll_ad2.SetDatabaseDefaults();
  874. btr.AppendEntity(pll_ad2);
  875. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  876. //判断宽度能否放下文字
  877. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  878. tfh_temp.TextStyleId = HZ;
  879. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  880. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  881. tfh_temp.AlignmentPoint = tfh_temp.Position;
  882. //计算图幅号位数
  883. int ws = tfh_temp.TextString.Length;
  884. double tfh_width = Math.Abs(pts[1].X - x);
  885. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl))
  886. {
  887. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  888. //图幅号y坐标计算
  889. double tfh_y = y + dist_nw + dist_w2jt + y_plus + dist_w / 2;
  890. Point3d Topt_temp = new Point3d(x + (pts[1].X - x) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  891. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  892. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  893. tfh_temp.Layer = "9800";
  894. tfh_temp.ColorIndex = 4;
  895. tfh_temp.Height = 1.25 * bl;
  896. }
  897. else
  898. tfh_temp.Erase();
  899. Point3dCollection ptscoll = new Point3dCollection();
  900. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w + 0.01, 0));
  901. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w, 0));
  902. Point3d bk = new Point3d(pts[1].X, y + dist_nw + dist_w2jt + dist_w, 0);
  903. sele_dele(ptscoll, ed, tran, x, bk, btr);
  904. }
  905. //右上上
  906. if (pts[0].X > x + dist_l * 2 && y_check / bc > 2)
  907. {
  908. Polyline pll_ad = new Polyline();
  909. pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * 3), 0, 0, 0);
  910. pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  911. pll_ad.Layer = "9800";
  912. pll_ad.Linetype = "Bylayer";
  913. pll_ad.SetDatabaseDefaults();
  914. btr.AppendEntity(pll_ad);
  915. tran.AddNewlyCreatedDBObject(pll_ad, true);
  916. Polyline pll_ad1 = new Polyline();
  917. pll_ad1.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  918. pll_ad1.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  919. pll_ad1.Layer = "9800";
  920. pll_ad1.Linetype = "Bylayer";
  921. pll_ad1.SetDatabaseDefaults();
  922. btr.AppendEntity(pll_ad1);
  923. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  924. //判断宽度和高度能否放下文字
  925. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  926. tfh_temp.TextStyleId = HZ;
  927. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  928. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  929. tfh_temp.AlignmentPoint = tfh_temp.Position;
  930. //计算图幅号位数
  931. int ws = tfh_temp.TextString.Length;
  932. double tfh_width = Math.Abs(x + dist_l * 3 - pts[0].X);
  933. double tfh_height = Math.Abs((dist_w * (3 - num_y) - y_plus));
  934. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl) &&
  935. tfh_height > 1.25 * bl)
  936. {
  937. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  938. //图幅号y坐标计算
  939. double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
  940. double tfh_y = y + dist_nw + dist_w2jt + dist_w * 2 + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
  941. Point3d Topt_temp = new Point3d(tfh_x, tfh_y, tfh_temp.AlignmentPoint.Z);
  942. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  943. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  944. tfh_temp.Layer = "9800";
  945. tfh_temp.ColorIndex = 4;
  946. tfh_temp.Height = 1.25 * bl;
  947. }
  948. else
  949. tfh_temp.Erase();
  950. }
  951. //右上下
  952. else if (pts[0].X > x + dist_l * 2 && Math.Round(y_check / bc, 2) < 2 && Math.Round(y_check / bc, 2) > 1)
  953. {
  954. Polyline pll_ad = new Polyline();
  955. pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  956. pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
  957. pll_ad.Layer = "9800";
  958. pll_ad.Linetype = "Bylayer";
  959. pll_ad.SetDatabaseDefaults();
  960. btr.AppendEntity(pll_ad);
  961. tran.AddNewlyCreatedDBObject(pll_ad, true);
  962. Polyline pll_ad1 = new Polyline();
  963. pll_ad1.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
  964. pll_ad1.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
  965. pll_ad1.Layer = "9800";
  966. pll_ad1.Linetype = "Bylayer";
  967. pll_ad1.SetDatabaseDefaults();
  968. btr.AppendEntity(pll_ad1);
  969. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  970. Polyline pll_ad2 = new Polyline();
  971. pll_ad2.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  972. pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  973. pll_ad2.Layer = "9800";
  974. pll_ad2.Linetype = "Bylayer";
  975. pll_ad2.SetDatabaseDefaults();
  976. btr.AppendEntity(pll_ad2);
  977. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  978. //判断宽度能否放下文字
  979. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  980. tfh_temp.TextStyleId = HZ;
  981. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  982. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  983. tfh_temp.AlignmentPoint = tfh_temp.Position;
  984. //计算图幅号位数
  985. int ws = tfh_temp.TextString.Length;
  986. double tfh_width = Math.Abs(x + dist_l * 3 - pts[0].X);
  987. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl))
  988. {
  989. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  990. //图幅号y坐标计算
  991. double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
  992. double tfh_y = y + dist_nw + dist_w2jt + dist_w * 1.5 + y_plus;
  993. Point3d Topt_temp = new Point3d(tfh_x, tfh_y, tfh_temp.AlignmentPoint.Z);
  994. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  995. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  996. tfh_temp.Layer = "9800";
  997. tfh_temp.ColorIndex = 4;
  998. tfh_temp.Height = 1.25 * bl;
  999. }
  1000. else
  1001. tfh_temp.Erase();
  1002. Point3dCollection ptscoll = new Point3dCollection();
  1003. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w * 2 + 0.01, 0));
  1004. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w * 2, 0));
  1005. Point3d bk = new Point3d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * 2, 0);
  1006. sele_dele(ptscoll, ed, tran, x + dist_l * 3, bk, btr);
  1007. }
  1008. //右下下
  1009. if (pts[0].X > x + dist_l * 2 && y_plus_down < 0)
  1010. {
  1011. Polyline pll_ad = new Polyline();
  1012. pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt), 0, 0, 0);
  1013. pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1014. pll_ad.Layer = "9800";
  1015. pll_ad.Linetype = "Bylayer";
  1016. pll_ad.SetDatabaseDefaults();
  1017. btr.AppendEntity(pll_ad);
  1018. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1019. Polyline pll_ad1 = new Polyline();
  1020. pll_ad1.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1021. pll_ad1.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1022. pll_ad1.Layer = "9800";
  1023. pll_ad1.Linetype = "Bylayer";
  1024. pll_ad1.SetDatabaseDefaults();
  1025. btr.AppendEntity(pll_ad1);
  1026. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  1027. //判断宽度能否放下文字
  1028. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1029. tfh_temp.TextStyleId = HZ;
  1030. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1031. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1032. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1033. //计算图幅号位数
  1034. int ws = tfh_temp.TextString.Length;
  1035. double tfh_width = Math.Abs(x + dist_l * 3 - pts[0].X);
  1036. double tfh_height = (dist_w - y_plus);
  1037. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl) &&
  1038. tfh_height > 1.25 * bl)
  1039. {
  1040. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1041. //图幅号y坐标计算
  1042. double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
  1043. double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
  1044. Point3d Topt_temp = new Point3d(tfh_x, tfh_y, tfh_temp.AlignmentPoint.Z);
  1045. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1046. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1047. tfh_temp.Layer = "9800";
  1048. tfh_temp.ColorIndex = 4;
  1049. tfh_temp.Height = 1.25 * bl;
  1050. }
  1051. else
  1052. tfh_temp.Erase();
  1053. }
  1054. //右下上
  1055. else if (pts[0].X > x + dist_l * 2 && y_plus_down < dist_w && y_plus_down > 0)
  1056. {
  1057. Polyline pll_ad = new Polyline();
  1058. pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  1059. pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
  1060. pll_ad.Layer = "9800";
  1061. pll_ad.Linetype = "Bylayer";
  1062. pll_ad.SetDatabaseDefaults();
  1063. btr.AppendEntity(pll_ad);
  1064. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1065. Polyline pll_ad1 = new Polyline();
  1066. pll_ad1.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
  1067. pll_ad1.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
  1068. pll_ad1.Layer = "9800";
  1069. pll_ad1.Linetype = "Bylayer";
  1070. pll_ad1.SetDatabaseDefaults();
  1071. btr.AppendEntity(pll_ad1);
  1072. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  1073. Polyline pll_ad2 = new Polyline();
  1074. pll_ad2.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  1075. pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  1076. pll_ad2.Layer = "9800";
  1077. pll_ad2.Linetype = "Bylayer";
  1078. pll_ad2.SetDatabaseDefaults();
  1079. btr.AppendEntity(pll_ad2);
  1080. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  1081. //判断宽度能否放下文字
  1082. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1083. tfh_temp.TextStyleId = HZ;
  1084. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1085. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1086. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1087. //计算图幅号位数
  1088. int ws = tfh_temp.TextString.Length;
  1089. double tfh_width = Math.Abs(x + dist_l * 3 - pts[0].X);
  1090. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl))
  1091. {
  1092. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1093. //图幅号y坐标计算
  1094. double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
  1095. double tfh_y = y + dist_nw + dist_w2jt + y_plus + dist_w / 2;
  1096. Point3d Topt_temp = new Point3d(tfh_x, tfh_y, tfh_temp.AlignmentPoint.Z);
  1097. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1098. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1099. tfh_temp.Layer = "9800";
  1100. tfh_temp.ColorIndex = 4;
  1101. tfh_temp.Height = 1.25 * bl;
  1102. }
  1103. else
  1104. tfh_temp.Erase();
  1105. Point3dCollection ptscoll = new Point3dCollection();
  1106. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w + 0.01, 0));
  1107. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w, 0));
  1108. Point3d bk = new Point3d(pts[0].X, y + dist_nw + dist_w2jt + dist_w, 0);
  1109. sele_dele(ptscoll, ed, tran, x + dist_l * 3, bk, btr);
  1110. }
  1111. //中上左
  1112. if (pts[0].X > x && pts[1].X < x + dist_l * 2 && y_check / bc > 2)
  1113. {
  1114. Polyline pll_ad = new Polyline();
  1115. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 3), 0, 0, 0);
  1116. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1117. pll_ad.Layer = "9800";
  1118. pll_ad.Linetype = "Bylayer";
  1119. pll_ad.SetDatabaseDefaults();
  1120. btr.AppendEntity(pll_ad);
  1121. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1122. Polyline pll_ad1 = new Polyline();
  1123. pll_ad1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1124. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1125. pll_ad1.Layer = "9800";
  1126. pll_ad1.Linetype = "Bylayer";
  1127. pll_ad1.SetDatabaseDefaults();
  1128. btr.AppendEntity(pll_ad1);
  1129. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  1130. Polyline pll_ad2 = new Polyline();
  1131. pll_ad2.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1132. pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1133. pll_ad2.Layer = "9800";
  1134. pll_ad2.Linetype = "Bylayer";
  1135. pll_ad2.SetDatabaseDefaults();
  1136. btr.AppendEntity(pll_ad2);
  1137. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  1138. //判断宽度和高度能否放下文字
  1139. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1140. tfh_temp.TextStyleId = HZ;
  1141. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1142. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1143. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1144. //计算图幅号位数
  1145. int ws = tfh_temp.TextString.Length;
  1146. double tfh_height = Math.Abs((dist_w * (3 - num_y) - y_plus));
  1147. if (tfh_height > 1.25 * bl)
  1148. {
  1149. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1150. //图幅号y坐标计算
  1151. double tfh_y = y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
  1152. Point3d Topt_temp = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  1153. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1154. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1155. tfh_temp.Layer = "9800";
  1156. tfh_temp.ColorIndex = 4;
  1157. tfh_temp.Height = 1.25 * bl;
  1158. }
  1159. else
  1160. tfh_temp.Erase();
  1161. }
  1162. //中上右
  1163. if (pts[0].X > x + dist_l && pts[1].X < x + dist_l * 3 && y_check / bc > 2)
  1164. {
  1165. Polyline pll_ad = new Polyline();
  1166. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 3), 0, 0, 0);
  1167. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1168. pll_ad.Layer = "9800";
  1169. pll_ad.Linetype = "Bylayer";
  1170. pll_ad.SetDatabaseDefaults();
  1171. btr.AppendEntity(pll_ad);
  1172. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1173. Polyline pll_ad1 = new Polyline();
  1174. pll_ad1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1175. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1176. pll_ad1.Layer = "9800";
  1177. pll_ad1.Linetype = "Bylayer";
  1178. pll_ad1.SetDatabaseDefaults();
  1179. btr.AppendEntity(pll_ad1);
  1180. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  1181. Polyline pll_ad2 = new Polyline();
  1182. pll_ad2.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1183. pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1184. pll_ad2.Layer = "9800";
  1185. pll_ad2.Linetype = "Bylayer";
  1186. pll_ad2.SetDatabaseDefaults();
  1187. btr.AppendEntity(pll_ad2);
  1188. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  1189. //判断宽度和高度能否放下文字
  1190. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1191. tfh_temp.TextStyleId = HZ;
  1192. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1193. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1194. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1195. //计算图幅号位数
  1196. int ws = tfh_temp.TextString.Length;
  1197. double tfh_height = Math.Abs((dist_w * (3 - num_y) - y_plus));
  1198. if (tfh_height > 1.25 * bl)
  1199. {
  1200. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1201. //图幅号y坐标计算
  1202. double tfh_y = y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
  1203. Point3d Topt_temp = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  1204. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1205. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1206. tfh_temp.Layer = "9800";
  1207. tfh_temp.ColorIndex = 4;
  1208. tfh_temp.Height = 1.25 * bl;
  1209. }
  1210. else
  1211. tfh_temp.Erase();
  1212. }
  1213. //中下左
  1214. if (pts[0].X > x && pts[1].X < x + dist_l * 2 && y_plus_down < 0)
  1215. {
  1216. Polyline pll_ad = new Polyline();
  1217. pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt), 0, 0, 0);
  1218. pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1219. pll_ad.Layer = "9800";
  1220. pll_ad.Linetype = "Bylayer";
  1221. pll_ad.SetDatabaseDefaults();
  1222. btr.AppendEntity(pll_ad);
  1223. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1224. Polyline pll_ad1 = new Polyline();
  1225. pll_ad1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1226. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1227. pll_ad1.Layer = "9800";
  1228. pll_ad1.Linetype = "Bylayer";
  1229. pll_ad1.SetDatabaseDefaults();
  1230. btr.AppendEntity(pll_ad1);
  1231. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  1232. Polyline pll_ad2 = new Polyline();
  1233. pll_ad2.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt), 0, 0, 0);
  1234. pll_ad2.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1235. pll_ad2.Layer = "9800";
  1236. pll_ad2.Linetype = "Bylayer";
  1237. pll_ad2.SetDatabaseDefaults();
  1238. btr.AppendEntity(pll_ad2);
  1239. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  1240. //判断宽度和高度能否放下文字
  1241. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1242. tfh_temp.TextStyleId = HZ;
  1243. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1244. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1245. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1246. //计算图幅号位数
  1247. int ws = tfh_temp.TextString.Length;
  1248. double tfh_height = (dist_w - y_plus);
  1249. if (tfh_height > 1.25 * bl)
  1250. {
  1251. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1252. //图幅号y坐标计算
  1253. double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
  1254. Point3d Topt_temp = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  1255. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1256. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1257. tfh_temp.Layer = "9800";
  1258. tfh_temp.ColorIndex = 4;
  1259. tfh_temp.Height = 1.25 * bl;
  1260. }
  1261. else
  1262. tfh_temp.Erase();
  1263. }
  1264. //中下右
  1265. if (pts[0].X > x + dist_l && pts[1].X < x + dist_l * 3 && y_plus_down < 0)
  1266. {
  1267. Polyline pll_ad = new Polyline();
  1268. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt), 0, 0, 0);
  1269. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1270. pll_ad.Layer = "9800";
  1271. pll_ad.Linetype = "Bylayer";
  1272. pll_ad.SetDatabaseDefaults();
  1273. btr.AppendEntity(pll_ad);
  1274. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1275. Polyline pll_ad1 = new Polyline();
  1276. pll_ad1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1277. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1278. pll_ad1.Layer = "9800";
  1279. pll_ad1.Linetype = "Bylayer";
  1280. pll_ad1.SetDatabaseDefaults();
  1281. btr.AppendEntity(pll_ad1);
  1282. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  1283. Polyline pll_ad2 = new Polyline();
  1284. pll_ad2.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt), 0, 0, 0);
  1285. pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1286. pll_ad2.Layer = "9800";
  1287. pll_ad2.Linetype = "Bylayer";
  1288. pll_ad2.SetDatabaseDefaults();
  1289. btr.AppendEntity(pll_ad2);
  1290. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  1291. //判断宽度和高度能否放下文字
  1292. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1293. tfh_temp.TextStyleId = HZ;
  1294. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1295. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1296. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1297. //计算图幅号位数
  1298. int ws = tfh_temp.TextString.Length;
  1299. double tfh_height = (dist_w - y_plus);
  1300. if (tfh_height > 1.25 * bl)
  1301. {
  1302. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1303. //图幅号y坐标计算
  1304. double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
  1305. Point3d Topt_temp = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  1306. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1307. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1308. tfh_temp.Layer = "9800";
  1309. tfh_temp.ColorIndex = 4;
  1310. tfh_temp.Height = 1.25 * bl;
  1311. }
  1312. else
  1313. tfh_temp.Erase();
  1314. }
  1315. }
  1316. //x方向错位
  1317. else if (x_check % bc != 0)
  1318. {
  1319. //选择y方向竖线删除
  1320. Point3dCollection ptscoll = new Point3dCollection();
  1321. ptscoll.Add(new Point3d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
  1322. ptscoll.Add(new Point3d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
  1323. TypedValue[] value = new TypedValue[]
  1324. {
  1325. new TypedValue((int)DxfCode.LayerName,"9800"),
  1326. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  1327. };
  1328. SelectionFilter filter = new SelectionFilter(value);
  1329. //dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  1330. //acadApp.ZoomExtents();
  1331. PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
  1332. if (psr.Status == PromptStatus.OK)
  1333. {
  1334. SelectionSet ss = psr.Value;
  1335. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  1336. Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  1337. //判断选中多条线段后情况
  1338. if (idcoll.Count > 1)
  1339. {
  1340. Polyline temp1 = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  1341. Polyline temp2 = tran.GetObject(idcoll[1], OpenMode.ForWrite) as Polyline;
  1342. if (temp1.Length > temp2.Length)
  1343. {
  1344. pll_delete = temp1;
  1345. }
  1346. else
  1347. {
  1348. pll_delete = temp2;
  1349. }
  1350. }
  1351. //有相交但超出左范围
  1352. if (pll_delete.StartPoint.X == x)
  1353. {
  1354. Polyline pll_ad = new Polyline();
  1355. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
  1356. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
  1357. pll_ad.Layer = "9800";
  1358. pll_ad.Linetype = "Bylayer";
  1359. pll_ad.SetDatabaseDefaults();
  1360. btr.AppendEntity(pll_ad);
  1361. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1362. //判断宽度能否放下文字
  1363. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1364. tfh_temp.TextStyleId = HZ;
  1365. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1366. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1367. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1368. //计算图幅号位数判断是否需要保留
  1369. int ws = tfh_temp.TextString.Length;
  1370. if (Math.Abs(pts[1].X - x) > ws * bl + (ws - 1) * (0.25 * bl))
  1371. {
  1372. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1373. //图幅号x坐标计算
  1374. //double tfh_x = Math.Round(x + (pts[1].X - x) / 2);
  1375. double tfh_x = x + (pts[1].X - x) / 2;
  1376. Point3d Topt_temp = new Point3d(tfh_x, y + dist_nw + dist_w2jt + dist_w * (num_y) + dist_w / 2, tfh_temp.AlignmentPoint.Z);
  1377. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1378. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1379. tfh_temp.Layer = "9800";
  1380. tfh_temp.ColorIndex = 4;
  1381. tfh_temp.Height = 1.25 * bl;
  1382. }
  1383. else
  1384. {
  1385. tfh_temp.Erase();
  1386. }
  1387. //删除接图表内左竖线
  1388. Point3dCollection deleteptscoll = new Point3dCollection();
  1389. deleteptscoll.Add(new Point3d(x + dist_l, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
  1390. deleteptscoll.Add(new Point3d(x + dist_l + 0.01, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
  1391. TypedValue[] deletevalue = new TypedValue[]
  1392. {
  1393. new TypedValue((int)DxfCode.LayerName,"9800"),
  1394. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  1395. };
  1396. SelectionFilter deletefilter = new SelectionFilter(deletevalue);
  1397. //acadApp.ZoomExtents();
  1398. PromptSelectionResult deletepsr = ed.SelectFence(deleteptscoll, deletefilter);
  1399. //acadApp.ZoomPrevious();
  1400. if (deletepsr.Status == PromptStatus.OK)
  1401. {
  1402. SelectionSet deletess = deletepsr.Value;
  1403. ObjectIdCollection deleteidcoll = new ObjectIdCollection(deletess.GetObjectIds());
  1404. Polyline deletepll = tran.GetObject(deleteidcoll[0], OpenMode.ForWrite) as Polyline;
  1405. Point3dCollection pt_break = new Point3dCollection();
  1406. DBObjectCollection obj = new DBObjectCollection();
  1407. if (num_y == 0)
  1408. {
  1409. pt_break.Add(new Point3d(deletepll.StartPoint.X, y + dist_nw + dist_w2jt + dist_w, 0));
  1410. obj = deletepll.GetSplitCurves(pt_break);
  1411. Polyline pll_delete1 = obj[0] as Polyline;
  1412. Polyline pll_delete2 = obj[1] as Polyline;
  1413. if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt ||
  1414. pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt)
  1415. {
  1416. pll_delete2.SetDatabaseDefaults();
  1417. btr.AppendEntity(pll_delete2);
  1418. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1419. }
  1420. else
  1421. {
  1422. pll_delete1.SetDatabaseDefaults();
  1423. btr.AppendEntity(pll_delete1);
  1424. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1425. }
  1426. deletepll.Erase();
  1427. }
  1428. else
  1429. {
  1430. pt_break.Add(new Point3d(deletepll.StartPoint.X, y + dist_nw + dist_w2jt + dist_w * num_y, 0));
  1431. obj = deletepll.GetSplitCurves(pt_break);
  1432. Polyline pll_delete1 = obj[0] as Polyline;
  1433. Polyline pll_delete2 = obj[1] as Polyline;
  1434. if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3 ||
  1435. pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3)
  1436. {
  1437. pll_delete2.SetDatabaseDefaults();
  1438. btr.AppendEntity(pll_delete2);
  1439. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1440. }
  1441. else
  1442. {
  1443. pll_delete1.SetDatabaseDefaults();
  1444. btr.AppendEntity(pll_delete1);
  1445. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1446. }
  1447. deletepll.Erase();
  1448. }
  1449. }
  1450. }
  1451. //有相交但超出右范围
  1452. else if (pll_delete.StartPoint.X == x + dist_l * 3)
  1453. {
  1454. Polyline pll_ad = new Polyline();
  1455. pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
  1456. pll_ad.AddVertexAt(1, new Point2d(pts[3].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
  1457. pll_ad.Layer = "9800";
  1458. pll_ad.Linetype = "Bylayer";
  1459. pll_ad.SetDatabaseDefaults();
  1460. btr.AppendEntity(pll_ad);
  1461. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1462. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1463. tfh_temp.TextStyleId = HZ;
  1464. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1465. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1466. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1467. int ws = tfh_temp.TextString.Length;//计算图幅号位数判断是否需要保留
  1468. if (Math.Abs(x + dist_l * 3 - pts[0].X) > ws * bl + (ws - 1) * (0.25 * bl))
  1469. {
  1470. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1471. //图幅号x坐标计算
  1472. //double tfh_x = Math.Round(x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2);
  1473. double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
  1474. Point3d Topt_temp = new Point3d(tfh_x, y + dist_nw + dist_w2jt + dist_w * (num_y) + dist_w / 2, tfh_temp.AlignmentPoint.Z);
  1475. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1476. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1477. tfh_temp.Layer = "9800";
  1478. tfh_temp.ColorIndex = 4;
  1479. tfh_temp.Height = 1.25 * bl;
  1480. }
  1481. else
  1482. {
  1483. tfh_temp.Erase();
  1484. }
  1485. //删除接图表内右竖线
  1486. Point3dCollection deleteptscoll = new Point3dCollection();
  1487. deleteptscoll.Add(new Point3d(x + dist_l * 2, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
  1488. deleteptscoll.Add(new Point3d(x + dist_l * 2 + 0.01, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
  1489. TypedValue[] deletevalue = new TypedValue[]
  1490. {
  1491. new TypedValue((int)DxfCode.LayerName,"9800"),
  1492. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  1493. };
  1494. SelectionFilter deletefilter = new SelectionFilter(deletevalue);
  1495. //acadApp.ZoomExtents();
  1496. PromptSelectionResult deletepsr = ed.SelectFence(deleteptscoll, deletefilter);
  1497. //acadApp.ZoomPrevious();
  1498. if (deletepsr.Status == PromptStatus.OK)
  1499. {
  1500. SelectionSet deletess = deletepsr.Value;
  1501. ObjectIdCollection deleteidcoll = new ObjectIdCollection(deletess.GetObjectIds());
  1502. Polyline deletepll = tran.GetObject(deleteidcoll[0], OpenMode.ForWrite) as Polyline;
  1503. Point3dCollection pt_break = new Point3dCollection();
  1504. DBObjectCollection obj = new DBObjectCollection();
  1505. if (num_y == 0)
  1506. {
  1507. pt_break.Add(new Point3d(deletepll.StartPoint.X, y + dist_nw + dist_w2jt + dist_w, 0));
  1508. obj = deletepll.GetSplitCurves(pt_break);
  1509. Polyline pll_delete1 = obj[0] as Polyline;
  1510. Polyline pll_delete2 = obj[1] as Polyline;
  1511. if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt ||
  1512. pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt)
  1513. {
  1514. pll_delete2.SetDatabaseDefaults();
  1515. btr.AppendEntity(pll_delete2);
  1516. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1517. }
  1518. else
  1519. {
  1520. pll_delete1.SetDatabaseDefaults();
  1521. btr.AppendEntity(pll_delete1);
  1522. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1523. }
  1524. deletepll.Erase();
  1525. }
  1526. else
  1527. {
  1528. pt_break.Add(new Point3d(deletepll.StartPoint.X, y + dist_nw + dist_w2jt + dist_w * num_y, 0));
  1529. obj = deletepll.GetSplitCurves(pt_break);
  1530. Polyline pll_delete1 = obj[0] as Polyline;
  1531. Polyline pll_delete2 = obj[1] as Polyline;
  1532. if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3 ||
  1533. pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3)
  1534. {
  1535. pll_delete2.SetDatabaseDefaults();
  1536. btr.AppendEntity(pll_delete2);
  1537. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1538. }
  1539. else
  1540. {
  1541. pll_delete1.SetDatabaseDefaults();
  1542. btr.AppendEntity(pll_delete1);
  1543. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1544. }
  1545. deletepll.Erase();
  1546. }
  1547. }
  1548. }
  1549. else
  1550. {
  1551. //if (cw_x != pts[0].Y)
  1552. //{
  1553. // zj_x.Add(tf[i]);
  1554. // flag_x = 1;
  1555. // cw_x = pts[0].Y;
  1556. //}
  1557. //else if (cw_x == pts[0].Y && flag_x == 1)
  1558. //{
  1559. // zj_x.RemoveAt(zj_x.Count - 1);
  1560. // flag_x = 0;
  1561. //}
  1562. //if (cw_x.Count != 0)
  1563. //{
  1564. // int flag = 0;
  1565. // int cf = 0;
  1566. // for (int ii = 0; ii < cw_x.Count; ii++)
  1567. // {
  1568. // if (cw_x[ii].Y != pts[0].Y)
  1569. // flag = 1;
  1570. // else
  1571. // {
  1572. // flag = 0;
  1573. // cf = ii;
  1574. // }
  1575. // }
  1576. // if(flag == 1)
  1577. // {
  1578. // zj_x.Add(tf[i]);
  1579. // cw_x.Add(pts[0]);
  1580. // }
  1581. // else
  1582. // {
  1583. // zj_x.RemoveAt(cf);
  1584. // cw_x.RemoveAt(cf);
  1585. // }
  1586. //}
  1587. //else
  1588. //{
  1589. // zj_x.Add(tf[i]);
  1590. // cw_x.Add(pts[0]);
  1591. //}
  1592. cw_x.Add(pts[0]);
  1593. zj_x.Add(tf[i]);
  1594. Point3dCollection pt_break = new Point3dCollection();
  1595. DBObjectCollection obj = new DBObjectCollection();
  1596. if (pll_delete.Length != 12 * bl / 3)
  1597. {
  1598. pt_break.Add(new Point3d(pll_delete.StartPoint.X, y + dist_nw
  1599. + dist_w2jt + ((num_y + 2) / 2) * dist_w, 0));
  1600. obj = pll_delete.GetSplitCurves(pt_break);
  1601. Polyline pll_delete1 = obj[0] as Polyline;
  1602. Polyline pll_delete2 = obj[1] as Polyline;
  1603. if (pll_delete1.Length < pll_delete2.Length)
  1604. {
  1605. pll_delete2.SetDatabaseDefaults();
  1606. btr.AppendEntity(pll_delete2);
  1607. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1608. }
  1609. else if (pll_delete1.Length == pll_delete2.Length)
  1610. {
  1611. if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt ||
  1612. pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt ||
  1613. pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3 ||
  1614. pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3)
  1615. {
  1616. pll_delete2.SetDatabaseDefaults();
  1617. btr.AppendEntity(pll_delete2);
  1618. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1619. }
  1620. else
  1621. {
  1622. pll_delete1.SetDatabaseDefaults();
  1623. btr.AppendEntity(pll_delete1);
  1624. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1625. }
  1626. }
  1627. else
  1628. {
  1629. pll_delete1.SetDatabaseDefaults();
  1630. btr.AppendEntity(pll_delete1);
  1631. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1632. }
  1633. }
  1634. pll_delete.Erase();
  1635. Polyline pll_cg = new Polyline();
  1636. pll_cg.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
  1637. //pll_cg.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
  1638. //pll_cg.AddVertexAt(2, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
  1639. pll_cg.AddVertexAt(1, new Point2d(pts[3].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
  1640. //pll_cg.AddVertexAt(4, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
  1641. Polyline pll_cg_1 = new Polyline();
  1642. pll_cg_1.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
  1643. pll_cg_1.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
  1644. pll_cg.Layer = "9800";
  1645. pll_cg.Linetype = "Bylayer";
  1646. pll_cg.SetDatabaseDefaults();
  1647. btr.AppendEntity(pll_cg);
  1648. tran.AddNewlyCreatedDBObject(pll_cg, true);
  1649. pll_cg_1.Layer = "9800";
  1650. pll_cg_1.Linetype = "Bylayer";
  1651. pll_cg_1.SetDatabaseDefaults();
  1652. btr.AppendEntity(pll_cg_1);
  1653. tran.AddNewlyCreatedDBObject(pll_cg_1, true);
  1654. DBText tfh = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1655. tfh.HorizontalMode = TextHorizontalMode.TextCenter;
  1656. tfh.VerticalMode = TextVerticalMode.TextVerticalMid;
  1657. tfh.AlignmentPoint = tfh.Position;
  1658. Point3d Frompt = new Point3d(tfh.AlignmentPoint.X, tfh.AlignmentPoint.Y, tfh.AlignmentPoint.Z);
  1659. Point3d Topt = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, y + dist_nw + dist_w2jt + dist_w * (num_y) + dist_w / 2, tfh.AlignmentPoint.Z);
  1660. Vector3d acVec3d = Frompt.GetVectorTo(Topt);
  1661. tfh.TransformBy(Matrix3d.Displacement(acVec3d));
  1662. tfh.Layer = "9800";
  1663. tfh.ColorIndex = 4;
  1664. tfh.Height = 1.25 * bl;
  1665. tfh.TextStyleId = HZ;
  1666. }
  1667. }
  1668. }
  1669. //y方向错位
  1670. else if (y_check % bc != 0)
  1671. {
  1672. double y_plus1 = (Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5) / bc) * dist_w;
  1673. double y_plus2 = (Math.Round(pts[2].Y - y - dist_nw - dist_w2jt, 5) / bc) * dist_w;
  1674. if (y_plus1 < 0)
  1675. y_plus1 = 0;
  1676. Point3dCollection ptscoll = new Point3dCollection();
  1677. ptscoll.Add(new Point3d(x + dist_l * num_x + 0.01, y + dist_nw + dist_w2jt + y_plus1, 0));
  1678. ptscoll.Add(new Point3d(x + dist_l * num_x + 0.01, y + dist_nw + dist_w2jt + y_plus2, 0));
  1679. TypedValue[] value = new TypedValue[]
  1680. {
  1681. new TypedValue((int)DxfCode.LayerName,"9800"),
  1682. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  1683. };
  1684. SelectionFilter filter = new SelectionFilter(value);
  1685. //dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  1686. //acadApp.ZoomExtents();
  1687. PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
  1688. //acadApp.ZoomPrevious();
  1689. if (psr.Status == PromptStatus.OK)
  1690. {
  1691. SelectionSet ss = psr.Value;
  1692. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  1693. Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  1694. if (idcoll.Count > 1)
  1695. {
  1696. Polyline temp1 = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  1697. Polyline temp2 = tran.GetObject(idcoll[1], OpenMode.ForWrite) as Polyline;
  1698. if (temp1.Length > temp2.Length)
  1699. {
  1700. pll_delete = temp1;
  1701. }
  1702. else
  1703. {
  1704. pll_delete = temp2;
  1705. }
  1706. }
  1707. //有相交但超出上方
  1708. if (pll_delete.StartPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3)
  1709. {
  1710. Polyline pll_ad = new Polyline();
  1711. pll_ad.AddVertexAt(0, new Point2d(x + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1712. pll_ad.AddVertexAt(1, new Point2d(x + dist_l * (num_x + 1), y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1713. pll_ad.Layer = "9800";
  1714. pll_ad.Linetype = "Bylayer";
  1715. pll_ad.SetDatabaseDefaults();
  1716. btr.AppendEntity(pll_ad);
  1717. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1718. //判断高度能否放下文字
  1719. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1720. tfh_temp.TextStyleId = HZ;
  1721. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1722. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1723. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1724. //计算图幅号位数判断是否需要保留
  1725. int ws = tfh_temp.TextString.Length;
  1726. if (Math.Abs((dist_w * (3 - num_y) - y_plus)) > 1.25 * bl)
  1727. {
  1728. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1729. //图幅号y坐标计算
  1730. double tfh_y = y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
  1731. Point3d Topt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_y, tfh_temp.AlignmentPoint.Z);
  1732. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1733. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1734. tfh_temp.Layer = "9800";
  1735. tfh_temp.ColorIndex = 4;
  1736. tfh_temp.Height = 1.25 * bl;
  1737. }
  1738. else
  1739. {
  1740. tfh_temp.Erase();
  1741. }
  1742. //删除接图表内上横线
  1743. Point3dCollection deleteptscoll = new Point3dCollection();
  1744. deleteptscoll.Add(new Point3d(x + dist_l / 2 + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w * 2, 0));
  1745. deleteptscoll.Add(new Point3d(x + dist_l / 2 + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w * 2 + 0.01, 0));
  1746. TypedValue[] deletevalue = new TypedValue[]
  1747. {
  1748. new TypedValue((int)DxfCode.LayerName,"9800"),
  1749. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  1750. };
  1751. SelectionFilter deletefilter = new SelectionFilter(deletevalue);
  1752. //acadApp.ZoomExtents();
  1753. PromptSelectionResult deletepsr = ed.SelectFence(deleteptscoll, deletefilter);
  1754. //acadApp.ZoomPrevious();
  1755. if (deletepsr.Status == PromptStatus.OK)
  1756. {
  1757. SelectionSet deletess = deletepsr.Value;
  1758. ObjectIdCollection deleteidcoll = new ObjectIdCollection(deletess.GetObjectIds());
  1759. Polyline deletepll = tran.GetObject(deleteidcoll[0], OpenMode.ForWrite) as Polyline;
  1760. Point3dCollection pt_break = new Point3dCollection();
  1761. DBObjectCollection obj = new DBObjectCollection();
  1762. if (num_x == 0)
  1763. {
  1764. pt_break.Add(new Point3d(x + dist_l, deletepll.StartPoint.Y, 0));
  1765. obj = deletepll.GetSplitCurves(pt_break);
  1766. Polyline pll_delete1 = obj[0] as Polyline;
  1767. Polyline pll_delete2 = obj[1] as Polyline;
  1768. if (pll_delete1.StartPoint.X == x ||
  1769. pll_delete1.EndPoint.Y == x)
  1770. {
  1771. pll_delete2.SetDatabaseDefaults();
  1772. btr.AppendEntity(pll_delete2);
  1773. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1774. }
  1775. else
  1776. {
  1777. pll_delete1.SetDatabaseDefaults();
  1778. btr.AppendEntity(pll_delete1);
  1779. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1780. }
  1781. deletepll.Erase();
  1782. }
  1783. else
  1784. {
  1785. pt_break.Add(new Point3d(x + dist_l * 2, deletepll.StartPoint.Y, 0));
  1786. obj = deletepll.GetSplitCurves(pt_break);
  1787. Polyline pll_delete1 = obj[0] as Polyline;
  1788. Polyline pll_delete2 = obj[1] as Polyline;
  1789. if (pll_delete1.StartPoint.Y == x + dist_l * 3 ||
  1790. pll_delete1.EndPoint.Y == x + dist_l * 3)
  1791. {
  1792. pll_delete2.SetDatabaseDefaults();
  1793. btr.AppendEntity(pll_delete2);
  1794. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1795. }
  1796. else
  1797. {
  1798. pll_delete1.SetDatabaseDefaults();
  1799. btr.AppendEntity(pll_delete1);
  1800. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1801. }
  1802. deletepll.Erase();
  1803. }
  1804. }
  1805. }
  1806. //有相交但超出下方
  1807. else if (pll_delete.StartPoint.Y == y + dist_nw + dist_w2jt)
  1808. {
  1809. Polyline pll_ad = new Polyline();
  1810. pll_ad.AddVertexAt(0, new Point2d(x + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w - y_plus)), 0, 0, 0);
  1811. pll_ad.AddVertexAt(1, new Point2d(x + dist_l * (num_x + 1), y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w - y_plus)), 0, 0, 0);
  1812. pll_ad.Layer = "9800";
  1813. pll_ad.Linetype = "Bylayer";
  1814. pll_ad.SetDatabaseDefaults();
  1815. btr.AppendEntity(pll_ad);
  1816. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1817. //判断高度能否放下文字
  1818. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1819. tfh_temp.TextStyleId = HZ;
  1820. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1821. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1822. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1823. //计算图幅号位数判断是否需要保留
  1824. int ws = tfh_temp.TextString.Length;
  1825. if (dist_w - y_plus > 1.25 * bl)
  1826. {
  1827. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1828. //图幅号y坐标计算
  1829. double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
  1830. Point3d Topt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_y, tfh_temp.AlignmentPoint.Z);
  1831. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1832. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1833. tfh_temp.Layer = "9800";
  1834. tfh_temp.ColorIndex = 4;
  1835. tfh_temp.Height = 1.25 * bl;
  1836. }
  1837. else
  1838. {
  1839. tfh_temp.Erase();
  1840. }
  1841. //删除接图表内下横线
  1842. Point3dCollection deleteptscoll = new Point3dCollection();
  1843. deleteptscoll.Add(new Point3d(x + dist_l / 2 + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w, 0));
  1844. deleteptscoll.Add(new Point3d(x + dist_l / 2 + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w + 0.01, 0));
  1845. TypedValue[] deletevalue = new TypedValue[]
  1846. {
  1847. new TypedValue((int)DxfCode.LayerName,"9800"),
  1848. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  1849. };
  1850. SelectionFilter deletefilter = new SelectionFilter(deletevalue);
  1851. //acadApp.ZoomExtents();
  1852. PromptSelectionResult deletepsr = ed.SelectFence(deleteptscoll, deletefilter);
  1853. //acadApp.ZoomPrevious();
  1854. if (deletepsr.Status == PromptStatus.OK)
  1855. {
  1856. SelectionSet deletess = deletepsr.Value;
  1857. ObjectIdCollection deleteidcoll = new ObjectIdCollection(deletess.GetObjectIds());
  1858. Polyline deletepll = tran.GetObject(deleteidcoll[0], OpenMode.ForWrite) as Polyline;
  1859. Point3dCollection pt_break = new Point3dCollection();
  1860. DBObjectCollection obj = new DBObjectCollection();
  1861. if (num_x == 0)
  1862. {
  1863. pt_break.Add(new Point3d(x + dist_l, deletepll.StartPoint.Y, 0));
  1864. obj = deletepll.GetSplitCurves(pt_break);
  1865. Polyline pll_delete1 = obj[0] as Polyline;
  1866. Polyline pll_delete2 = obj[1] as Polyline;
  1867. if (pll_delete1.StartPoint.X == x ||
  1868. pll_delete1.EndPoint.Y == x)
  1869. {
  1870. pll_delete2.SetDatabaseDefaults();
  1871. btr.AppendEntity(pll_delete2);
  1872. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1873. }
  1874. else
  1875. {
  1876. pll_delete1.SetDatabaseDefaults();
  1877. btr.AppendEntity(pll_delete1);
  1878. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1879. }
  1880. deletepll.Erase();
  1881. }
  1882. else
  1883. {
  1884. pt_break.Add(new Point3d(x + dist_l * 2, deletepll.StartPoint.Y, 0));
  1885. obj = deletepll.GetSplitCurves(pt_break);
  1886. Polyline pll_delete1 = obj[0] as Polyline;
  1887. Polyline pll_delete2 = obj[1] as Polyline;
  1888. if (pll_delete1.StartPoint.Y == x + dist_l * 3 ||
  1889. pll_delete1.EndPoint.Y == x + dist_l * 3)
  1890. {
  1891. pll_delete2.SetDatabaseDefaults();
  1892. btr.AppendEntity(pll_delete2);
  1893. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1894. }
  1895. else
  1896. {
  1897. pll_delete1.SetDatabaseDefaults();
  1898. btr.AppendEntity(pll_delete1);
  1899. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1900. }
  1901. deletepll.Erase();
  1902. }
  1903. }
  1904. }
  1905. else
  1906. {
  1907. //if (cw_y != pts[0].X)
  1908. //{
  1909. // zj_y.Add(tf[i]);
  1910. // flag_y = 1;
  1911. // cw_y = pts[0].X;
  1912. //}
  1913. //else if (cw_y == pts[0].X && flag_y == 1)
  1914. //{
  1915. // zj_y.RemoveAt(zj_y.Count - 1);
  1916. // flag_y = 0;
  1917. //}
  1918. //if (cw_y.Count != 0)
  1919. //{
  1920. // int flag = 0;
  1921. // int cf = 0;
  1922. // for (int ii = 0; ii < cw_y.Count; ii++)
  1923. // {
  1924. // if (cw_y[ii].X != pts[0].X)
  1925. // flag = 1;
  1926. // else
  1927. // {
  1928. // flag = 0;
  1929. // cf = ii;
  1930. // }
  1931. // }
  1932. // if (flag == 1)
  1933. // {
  1934. // zj_y.Add(tf[i]);
  1935. // cw_y.Add(pts[0]);
  1936. // }
  1937. // else
  1938. // {
  1939. // zj_y.RemoveAt(cf);
  1940. // cw_y.RemoveAt(cf);
  1941. // }
  1942. //}
  1943. //else
  1944. //{
  1945. // zj_y.Add(tf[i]);
  1946. // cw_y.Add(pts[0]);
  1947. //}
  1948. cw_y.Add(pts[0]);
  1949. zj_y.Add(tf[i]);
  1950. if (pll_delete.Length != 22.5 * bl / 3)
  1951. {
  1952. Point3dCollection pt_break = new Point3dCollection();
  1953. DBObjectCollection obj = new DBObjectCollection();
  1954. pt_break.Add(new Point3d(x + (((num_x + 2) / 2) * dist_l), y + dist_nw
  1955. + dist_w2jt + (num_y + 1) * dist_w, 0));
  1956. obj = pll_delete.GetSplitCurves(pt_break);
  1957. Polyline pll_delete1 = obj[0] as Polyline;
  1958. Polyline pll_delete2 = obj[1] as Polyline;
  1959. if (pll_delete1.Length < pll_delete2.Length)
  1960. {
  1961. pll_delete2.SetDatabaseDefaults();
  1962. btr.AppendEntity(pll_delete2);
  1963. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1964. }
  1965. else if (pll_delete1.Length == pll_delete2.Length)
  1966. {
  1967. if (pll_delete1.StartPoint.X == x || pll_delete1.EndPoint.X == x ||
  1968. pll_delete1.EndPoint.X == x + dist_l * 3 || pll_delete1.StartPoint.X == x + dist_l * 3)
  1969. {
  1970. pll_delete2.SetDatabaseDefaults();
  1971. btr.AppendEntity(pll_delete2);
  1972. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1973. }
  1974. else
  1975. {
  1976. pll_delete1.SetDatabaseDefaults();
  1977. btr.AppendEntity(pll_delete1);
  1978. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1979. }
  1980. }
  1981. else
  1982. {
  1983. pll_delete1.SetDatabaseDefaults();
  1984. btr.AppendEntity(pll_delete1);
  1985. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1986. }
  1987. }
  1988. pll_delete.Erase();
  1989. Polyline pll_cg_1 = new Polyline();
  1990. pll_cg_1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1991. pll_cg_1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1992. Polyline pll_cg_2 = new Polyline();
  1993. pll_cg_2.AddVertexAt(0, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1) + y_plus), 0, 0, 0);
  1994. pll_cg_2.AddVertexAt(1, new Point2d(pts[3].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1) + y_plus), 0, 0, 0);
  1995. //pll_cg.AddVertexAt(2, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1) + y_plus), 0, 0, 0);
  1996. //pll_cg_1.AddVertexAt(3, new Point2d(pts[3].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1) + y_plus), 0, 0, 0);
  1997. //pll_cg.AddVertexAt(4, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1998. pll_cg_1.Layer = "9800";
  1999. pll_cg_1.Linetype = "Bylayer";
  2000. pll_cg_1.SetDatabaseDefaults();
  2001. btr.AppendEntity(pll_cg_1);
  2002. tran.AddNewlyCreatedDBObject(pll_cg_1, true);
  2003. pll_cg_2.Layer = "9800";
  2004. pll_cg_2.Linetype = "Bylayer";
  2005. pll_cg_2.SetDatabaseDefaults();
  2006. btr.AppendEntity(pll_cg_2);
  2007. tran.AddNewlyCreatedDBObject(pll_cg_2, true);
  2008. DBText tfh = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  2009. tfh.HorizontalMode = TextHorizontalMode.TextCenter;
  2010. tfh.VerticalMode = TextVerticalMode.TextVerticalMid;
  2011. tfh.AlignmentPoint = tfh.Position;
  2012. Point3d Frompt = new Point3d(tfh.AlignmentPoint.X, tfh.AlignmentPoint.Y, tfh.AlignmentPoint.Z);
  2013. Point3d Topt = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + dist_w / 2, tfh.AlignmentPoint.Z);
  2014. Vector3d acVec3d = Frompt.GetVectorTo(Topt);
  2015. tfh.TransformBy(Matrix3d.Displacement(acVec3d));
  2016. tfh.Layer = "9800";
  2017. tfh.ColorIndex = 4;
  2018. tfh.Height = 1.25 * bl;
  2019. tfh.TextStyleId = HZ;
  2020. }
  2021. }
  2022. }
  2023. else
  2024. {
  2025. DBText tfh1 = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  2026. tfh1.HorizontalMode = TextHorizontalMode.TextCenter;
  2027. tfh1.VerticalMode = TextVerticalMode.TextVerticalMid;
  2028. tfh1.AlignmentPoint = tfh1.Position;
  2029. Point3d Frompt1 = new Point3d(tfh1.AlignmentPoint.X, tfh1.AlignmentPoint.Y, tfh1.AlignmentPoint.Z);
  2030. Point3d Topt1 = new Point3d(x + dist_l * num_x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w * (num_y) + dist_w / 2, tfh1.AlignmentPoint.Z);
  2031. Vector3d acVec3d1 = Frompt1.GetVectorTo(Topt1);
  2032. tfh1.TransformBy(Matrix3d.Displacement(acVec3d1));
  2033. tfh1.Layer = "9800";
  2034. tfh1.ColorIndex = 4;
  2035. tfh1.Height = 1.25 * bl;
  2036. tfh1.TextStyleId = HZ;
  2037. }
  2038. //pll.Erase();
  2039. tran.Commit();
  2040. }
  2041. }
  2042. List<int> delex = new List<int>();//不需要删除对应竖线的x方向错位框
  2043. List<int> deley = new List<int>();//不需要删除对应横线的y方向错位框
  2044. //如果同一列中有两个y方向错位图框,由于在y方向错位时已经进行了对应横线的
  2045. //删除,所以将序号加入列表中,不需要再删除。
  2046. for (int i = 0; i < zj_y.Count - 1; i++)
  2047. {
  2048. for (int ii = i + 1; ii < zj_y.Count; ii++)
  2049. {
  2050. if (cw_y[i].X == cw_y[ii].X)
  2051. {
  2052. deley.Add(i);
  2053. deley.Add(ii);
  2054. }
  2055. }
  2056. }
  2057. //如果同一行中有两个x方向错位图框,由于在x方向错位时已经进行了对应竖线的
  2058. //删除,所以将序号加入列表中,不需要再删除。
  2059. for (int i = 0; i < zj_x.Count - 1; i++)
  2060. {
  2061. for (int ii = i + 1; ii < zj_x.Count; ii++)
  2062. {
  2063. if (cw_x[i].Y == cw_x[ii].Y)
  2064. {
  2065. delex.Add(i);
  2066. delex.Add(ii);
  2067. }
  2068. }
  2069. }
  2070. //如果同时有x方向错位和y方向错位且在同一个角,不需要再删除
  2071. for (int i = 0; i < zj_x.Count; i++)
  2072. {
  2073. for (int ii = 0; ii < zj_y.Count; ii++)
  2074. {
  2075. if (Math.Abs(cw_x[i].X - cw_y[ii].X) > dist_l &&
  2076. Math.Abs(cw_x[i].Y - cw_y[ii].Y) > dist_l &&
  2077. !delex.Contains(i))
  2078. delex.Add(i);
  2079. else if (Math.Abs(cw_x[i].X - cw_y[ii].X) < dist_l &&
  2080. !deley.Contains(ii))
  2081. deley.Add(ii);
  2082. else if (Math.Abs(cw_x[i].Y - cw_y[ii].Y) < dist_l &&
  2083. !delex.Contains(i))
  2084. delex.Add(i);
  2085. }
  2086. }
  2087. if (zj_x.Count != 0)
  2088. {
  2089. delecentrol(doc, x, y, dist_l, dist_w, dist_nw, dist_w2jt, zj_x, delex, ptcoll, 0);
  2090. }
  2091. if (zj_y.Count != 0)
  2092. {
  2093. delecentrol(doc, x, y, dist_l, dist_w, dist_nw, dist_w2jt, zj_y, deley, ptcoll, 1);
  2094. }
  2095. //删除图框
  2096. for (int i = 0; i < tf.Count; i++)
  2097. {
  2098. using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
  2099. {
  2100. BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
  2101. BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  2102. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  2103. Point3dCollection pts = new Point3dCollection();
  2104. Polyline pll = tran.GetObject(tf[i].id, OpenMode.ForWrite) as Polyline;
  2105. pll.Erase();
  2106. if (i == tf.Count - 1)
  2107. {
  2108. LayerTable layerTable = tran.GetObject(doc.Database.LayerTableId, OpenMode.ForWrite) as LayerTable;
  2109. LayerTableRecord layer = tran.GetObject(layerTable[tc_tfh], OpenMode.ForWrite) as LayerTableRecord;
  2110. layer.Erase(true);
  2111. if (tc_tfh != tc_tk)
  2112. {
  2113. layer = tran.GetObject(layerTable[tc_tk], OpenMode.ForWrite) as LayerTableRecord;
  2114. layer.Erase(true); // 删除图层
  2115. }
  2116. }
  2117. tran.Commit();
  2118. }
  2119. }
  2120. }
  2121. /// <summary>
  2122. /// x、y方向错位竖\横线删除
  2123. /// </summary>
  2124. private void delecentrol(Document doc, double x, double y, double dist_l, double dist_w,
  2125. double dist_nw, double dist_w2jt, List<tkinfo> tk, List<int> deleindex, Point3dCollection ptcoll, int index)
  2126. {
  2127. //x方向错位竖线删除
  2128. if (index == 0)
  2129. {
  2130. for (int i = 0; i < tk.Count; i++)
  2131. {
  2132. if (deleindex.Contains(i))
  2133. continue;
  2134. using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
  2135. {
  2136. BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
  2137. BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  2138. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  2139. Point3dCollection pts = new Point3dCollection();
  2140. Polyline pll = tran.GetObject(tk[i].id, OpenMode.ForWrite) as Polyline;
  2141. double bc = pll.Length / 4.0; //边长
  2142. pll.GetStretchPoints(pts);
  2143. sortpts(pts);
  2144. double x_check = Math.Round(pts[0].X - ptcoll[3].X, 5);
  2145. double y_check = Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5);
  2146. double num_x = Math.Round(Math.Floor(x_check / bc), 3);
  2147. double num_y = Math.Round(Math.Floor(y_check / bc), 3);
  2148. Point3dCollection ptscoll = new Point3dCollection();
  2149. //右错位
  2150. if (pts[0].X > x + dist_l)
  2151. {
  2152. ptscoll.Add(new Point3d(x + dist_l, y + dist_nw + dist_w2jt + dist_w * num_y + dist_w / 2, 0));
  2153. ptscoll.Add(new Point3d(x + dist_l + 0.01, y + dist_nw + dist_w2jt + dist_w * num_y + dist_w / 2, 0));
  2154. }
  2155. //左错位
  2156. else
  2157. {
  2158. ptscoll.Add(new Point3d(x + dist_l * 2, y + dist_nw + dist_w2jt + dist_w * num_y + dist_w / 2, 0));
  2159. ptscoll.Add(new Point3d(x + dist_l * 2 + 0.01, y + dist_nw + dist_w2jt + dist_w * num_y + dist_w / 2, 0));
  2160. }
  2161. TypedValue[] value = new TypedValue[]
  2162. {
  2163. new TypedValue((int)DxfCode.LayerName,"9800"),
  2164. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  2165. };
  2166. SelectionFilter filter = new SelectionFilter(value);
  2167. dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  2168. acadApp.ZoomExtents();
  2169. PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
  2170. acadApp.ZoomPrevious();
  2171. if (psr.Status == PromptStatus.OK)
  2172. {
  2173. SelectionSet ss = psr.Value;
  2174. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  2175. Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  2176. Point3dCollection pt_break = new Point3dCollection();
  2177. DBObjectCollection obj = new DBObjectCollection();
  2178. int num = 0;
  2179. if (num_y / 2 == 0)
  2180. num = 1;
  2181. else if (num_y / 2 == 1)
  2182. num = 2;
  2183. pt_break.Add(new Point3d(pll_delete.StartPoint.X, y + dist_nw + dist_w2jt + dist_w * num, 0));
  2184. obj = pll_delete.GetSplitCurves(pt_break);
  2185. Polyline pll_delete1 = obj[0] as Polyline;
  2186. Polyline pll_delete2 = obj[1] as Polyline;
  2187. if (num == 1 && pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt ||
  2188. num == 1 && pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt)
  2189. {
  2190. pll_delete2.SetDatabaseDefaults();
  2191. btr.AppendEntity(pll_delete2);
  2192. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  2193. }
  2194. else
  2195. {
  2196. pll_delete1.SetDatabaseDefaults();
  2197. btr.AppendEntity(pll_delete1);
  2198. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  2199. }
  2200. pll_delete.Erase();
  2201. }
  2202. tran.Commit();
  2203. }
  2204. }
  2205. }
  2206. //y方向错位横线删除
  2207. if (index == 1)
  2208. {
  2209. for (int i = 0; i < tk.Count; i++)
  2210. {
  2211. if (deleindex.Contains(i))
  2212. continue;
  2213. using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
  2214. {
  2215. BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
  2216. BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  2217. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  2218. Point3dCollection pts = new Point3dCollection();
  2219. Polyline pll = tran.GetObject(tk[i].id, OpenMode.ForWrite) as Polyline;
  2220. double bc = pll.Length / 4.0; //边长
  2221. pll.GetStretchPoints(pts);
  2222. sortpts(pts);
  2223. double x_check = Math.Round(pts[0].X - ptcoll[3].X, 5);
  2224. double y_check = Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5);
  2225. double num_x = Math.Round(Math.Floor(x_check / bc), 3);
  2226. double num_y = Math.Round(Math.Floor(y_check / bc), 3);
  2227. double y_plus = (y_check % bc) * (dist_w / bc);
  2228. Point3dCollection ptscoll = new Point3dCollection();
  2229. //下错位
  2230. if (y + dist_nw + dist_w2jt + dist_w * num_y + y_plus < y + dist_nw + dist_w2jt + dist_w)
  2231. {
  2232. ptscoll.Add(new Point3d(x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w * 2, 0));
  2233. ptscoll.Add(new Point3d(x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w * 2 + 0.01, 0));
  2234. }
  2235. //上错位
  2236. else
  2237. {
  2238. ptscoll.Add(new Point3d(x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w, 0));
  2239. ptscoll.Add(new Point3d(x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w + 0.01, 0));
  2240. }
  2241. TypedValue[] value = new TypedValue[]
  2242. {
  2243. new TypedValue((int)DxfCode.LayerName,"9800"),
  2244. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  2245. };
  2246. SelectionFilter filter = new SelectionFilter(value);
  2247. dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  2248. acadApp.ZoomExtents();
  2249. PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
  2250. acadApp.ZoomPrevious();
  2251. if (psr.Status == PromptStatus.OK)
  2252. {
  2253. SelectionSet ss = psr.Value;
  2254. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  2255. Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  2256. Point3dCollection pt_break = new Point3dCollection();
  2257. DBObjectCollection obj = new DBObjectCollection();
  2258. int num = 0;
  2259. if (num_x / 2 == 0)
  2260. num = 1;
  2261. else if (num_x / 2 == 1)
  2262. num = 2;
  2263. pt_break.Add(new Point3d(x + dist_l * num, pll_delete.StartPoint.Y, 0));
  2264. obj = pll_delete.GetSplitCurves(pt_break);
  2265. Polyline pll_delete1 = obj[0] as Polyline;
  2266. Polyline pll_delete2 = obj[1] as Polyline;
  2267. if (num == 1 && pll_delete1.StartPoint.X == x ||
  2268. num == 1 && pll_delete1.EndPoint.X == x)
  2269. {
  2270. pll_delete2.SetDatabaseDefaults();
  2271. btr.AppendEntity(pll_delete2);
  2272. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  2273. }
  2274. else
  2275. {
  2276. pll_delete1.SetDatabaseDefaults();
  2277. btr.AppendEntity(pll_delete1);
  2278. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  2279. }
  2280. pll_delete.Erase();
  2281. }
  2282. tran.Commit();
  2283. }
  2284. }
  2285. }
  2286. }
  2287. /// <summary>
  2288. /// x、y方向都错位时删除对应方向的竖\横线
  2289. /// </summary>
  2290. private void sele_dele(Point3dCollection ptscoll, Editor ed, Transaction tran, double by, Point3d bk, BlockTableRecord btr)
  2291. {
  2292. TypedValue[] value = new TypedValue[]
  2293. {
  2294. new TypedValue((int)DxfCode.LayerName,"9800"),
  2295. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  2296. };
  2297. SelectionFilter filter = new SelectionFilter(value);
  2298. dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  2299. acadApp.ZoomExtents();
  2300. PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
  2301. acadApp.ZoomPrevious();
  2302. if (psr.Status == PromptStatus.OK)
  2303. {
  2304. SelectionSet ss = psr.Value;
  2305. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  2306. Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  2307. Point3dCollection pt_break = new Point3dCollection();
  2308. DBObjectCollection obj = new DBObjectCollection();
  2309. pt_break.Add(bk);
  2310. obj = pll_delete.GetSplitCurves(pt_break);
  2311. Polyline pll_delete1 = obj[0] as Polyline;
  2312. Polyline pll_delete2 = obj[1] as Polyline;
  2313. if (pll_delete1.StartPoint.X == by ||
  2314. pll_delete1.EndPoint.X == by)
  2315. {
  2316. pll_delete2.SetDatabaseDefaults();
  2317. btr.AppendEntity(pll_delete2);
  2318. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  2319. }
  2320. else
  2321. {
  2322. pll_delete1.SetDatabaseDefaults();
  2323. btr.AppendEntity(pll_delete1);
  2324. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  2325. }
  2326. pll_delete.Erase();
  2327. }
  2328. }
  2329. public ObjectId createTextStyle(Document doc)
  2330. {
  2331. Database database = doc.Database;
  2332. ObjectId textstyleID = new ObjectId();
  2333. string stylename = "HZ";
  2334. using (Transaction traction = database.TransactionManager.StartTransaction())
  2335. {
  2336. TextStyleTable styletable = traction.GetObject(database.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
  2337. if (styletable.Has(stylename) == false)
  2338. {
  2339. TextStyleTableRecord R1 = new TextStyleTableRecord();
  2340. R1.Name = stylename;
  2341. //R1.FileName = "方正细等线简体";
  2342. R1.FileName = "rs.shx";
  2343. R1.BigFontFileName = "hztxt.shx";
  2344. R1.ObliquingAngle = 0;
  2345. R1.XScale = 0.75;
  2346. //textstyleID = styletable.Add(R1);
  2347. traction.AddNewlyCreatedDBObject(R1, true);
  2348. //database.TextStyleId = textstyleID;
  2349. }
  2350. traction.Commit();
  2351. }
  2352. using (Transaction traction = database.TransactionManager.StartTransaction())
  2353. {
  2354. TextStyleTable styletable = traction.GetObject(database.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
  2355. TextStyleTableRecord record = traction.GetObject(styletable[stylename], OpenMode.ForRead) as TextStyleTableRecord;
  2356. textstyleID = record.ObjectId;
  2357. traction.Commit();
  2358. }
  2359. return textstyleID;
  2360. }
  2361. }
  2362. }