工具箱相关
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

getThumbnail.cs 156KB

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