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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659
  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. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  749. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  750. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  751. tfh_temp.AlignmentPoint = tfh_temp.Position;
  752. //计算图幅号位数
  753. int ws = tfh_temp.TextString.Length;
  754. double tfh_width = Math.Abs(pts[1].X - x);
  755. double tfh_height = Math.Abs((dist_w * (3 - num_y) - y_plus));
  756. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl) &&
  757. tfh_height > 1.25 * bl)
  758. {
  759. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  760. //图幅号y坐标计算
  761. double tfh_y = y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
  762. Point3d Topt_temp = new Point3d(x + (pts[1].X - x) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  763. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  764. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  765. tfh_temp.Layer = "9800";
  766. tfh_temp.ColorIndex = 4;
  767. tfh_temp.Height = 1.25 * bl;
  768. }
  769. else
  770. tfh_temp.Erase();
  771. }
  772. //左上下
  773. else if (pts[0].X < x && Math.Round(y_check / bc, 2) < 2 && Math.Round(y_check / bc, 2) > 1)
  774. {
  775. Polyline pll_ad = new Polyline();
  776. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  777. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
  778. pll_ad.Layer = "9800";
  779. pll_ad.Linetype = "Bylayer";
  780. pll_ad.SetDatabaseDefaults();
  781. btr.AppendEntity(pll_ad);
  782. tran.AddNewlyCreatedDBObject(pll_ad, true);
  783. Polyline pll_ad1 = new Polyline();
  784. pll_ad1.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
  785. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
  786. pll_ad1.Layer = "9800";
  787. pll_ad1.Linetype = "Bylayer";
  788. pll_ad1.SetDatabaseDefaults();
  789. btr.AppendEntity(pll_ad1);
  790. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  791. Polyline pll_ad2 = new Polyline();
  792. pll_ad2.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  793. pll_ad2.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  794. pll_ad2.Layer = "9800";
  795. pll_ad2.Linetype = "Bylayer";
  796. pll_ad2.SetDatabaseDefaults();
  797. btr.AppendEntity(pll_ad2);
  798. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  799. //判断宽度能否放下文字
  800. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  801. tfh_temp.TextStyleId = HZ;
  802. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  803. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  804. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  805. tfh_temp.AlignmentPoint = tfh_temp.Position;
  806. //计算图幅号位数
  807. int ws = tfh_temp.TextString.Length;
  808. double tfh_width = Math.Abs(pts[1].X - x);
  809. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl))
  810. {
  811. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  812. //图幅号y坐标计算
  813. double tfh_y = y + dist_nw + dist_w2jt + dist_w * 1.5 + y_plus;
  814. Point3d Topt_temp = new Point3d(x + (pts[1].X - x) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  815. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  816. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  817. tfh_temp.Layer = "9800";
  818. tfh_temp.ColorIndex = 4;
  819. tfh_temp.Height = 1.25 * bl;
  820. }
  821. else
  822. tfh_temp.Erase();
  823. Point3dCollection ptscoll = new Point3dCollection();
  824. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w * 2 + 0.01, 0));
  825. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w * 2, 0));
  826. Point3d bk = new Point3d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 2, 0);
  827. sele_dele(ptscoll, ed, tran, x, bk, btr);
  828. }
  829. //左下下
  830. if (pts[0].X < x && y_plus_down < 0)
  831. {
  832. Polyline pll_ad = new Polyline();
  833. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt), 0, 0, 0);
  834. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  835. pll_ad.Layer = "9800";
  836. pll_ad.Linetype = "Bylayer";
  837. pll_ad.SetDatabaseDefaults();
  838. btr.AppendEntity(pll_ad);
  839. tran.AddNewlyCreatedDBObject(pll_ad, true);
  840. Polyline pll_ad1 = new Polyline();
  841. pll_ad1.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  842. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  843. pll_ad1.Layer = "9800";
  844. pll_ad1.Linetype = "Bylayer";
  845. pll_ad1.SetDatabaseDefaults();
  846. btr.AppendEntity(pll_ad1);
  847. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  848. //判断宽度和高度能否放下文字
  849. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  850. tfh_temp.TextStyleId = HZ;
  851. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  852. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  853. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  854. tfh_temp.AlignmentPoint = tfh_temp.Position;
  855. //计算图幅号位数
  856. int ws = tfh_temp.TextString.Length;
  857. double tfh_width = Math.Abs(pts[1].X - x);
  858. double tfh_height = (dist_w - y_plus);
  859. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl) &&
  860. tfh_height > 1.25 * bl)
  861. {
  862. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  863. //图幅号y坐标计算
  864. double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
  865. Point3d Topt_temp = new Point3d(x + (pts[1].X - x) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  866. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  867. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  868. tfh_temp.Layer = "9800";
  869. tfh_temp.ColorIndex = 4;
  870. tfh_temp.Height = 1.25 * bl;
  871. }
  872. else
  873. tfh_temp.Erase();
  874. }
  875. //左下上
  876. else if (pts[0].X < x && y_plus_down < dist_w && y_plus_down > 0)
  877. {
  878. Polyline pll_ad = new Polyline();
  879. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  880. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
  881. pll_ad.Layer = "9800";
  882. pll_ad.Linetype = "Bylayer";
  883. pll_ad.SetDatabaseDefaults();
  884. btr.AppendEntity(pll_ad);
  885. tran.AddNewlyCreatedDBObject(pll_ad, true);
  886. Polyline pll_ad1 = new Polyline();
  887. pll_ad1.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
  888. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
  889. pll_ad1.Layer = "9800";
  890. pll_ad1.Linetype = "Bylayer";
  891. pll_ad1.SetDatabaseDefaults();
  892. btr.AppendEntity(pll_ad1);
  893. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  894. Polyline pll_ad2 = new Polyline();
  895. pll_ad2.AddVertexAt(0, new Point2d(x, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  896. pll_ad2.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  897. pll_ad2.Layer = "9800";
  898. pll_ad2.Linetype = "Bylayer";
  899. pll_ad2.SetDatabaseDefaults();
  900. btr.AppendEntity(pll_ad2);
  901. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  902. //判断宽度能否放下文字
  903. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  904. tfh_temp.TextStyleId = HZ;
  905. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  906. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  907. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  908. tfh_temp.AlignmentPoint = tfh_temp.Position;
  909. //计算图幅号位数
  910. int ws = tfh_temp.TextString.Length;
  911. double tfh_width = Math.Abs(pts[1].X - x);
  912. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl))
  913. {
  914. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  915. //图幅号y坐标计算
  916. double tfh_y = y + dist_nw + dist_w2jt + y_plus + dist_w / 2;
  917. Point3d Topt_temp = new Point3d(x + (pts[1].X - x) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  918. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  919. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  920. tfh_temp.Layer = "9800";
  921. tfh_temp.ColorIndex = 4;
  922. tfh_temp.Height = 1.25 * bl;
  923. }
  924. else
  925. tfh_temp.Erase();
  926. Point3dCollection ptscoll = new Point3dCollection();
  927. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w + 0.01, 0));
  928. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w, 0));
  929. Point3d bk = new Point3d(pts[1].X, y + dist_nw + dist_w2jt + dist_w, 0);
  930. sele_dele(ptscoll, ed, tran, x, bk, btr);
  931. }
  932. //右上上
  933. if (pts[0].X > x + dist_l * 2 && y_check / bc > 2)
  934. {
  935. Polyline pll_ad = new Polyline();
  936. pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * 3), 0, 0, 0);
  937. pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  938. pll_ad.Layer = "9800";
  939. pll_ad.Linetype = "Bylayer";
  940. pll_ad.SetDatabaseDefaults();
  941. btr.AppendEntity(pll_ad);
  942. tran.AddNewlyCreatedDBObject(pll_ad, true);
  943. Polyline pll_ad1 = new Polyline();
  944. pll_ad1.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  945. pll_ad1.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  946. pll_ad1.Layer = "9800";
  947. pll_ad1.Linetype = "Bylayer";
  948. pll_ad1.SetDatabaseDefaults();
  949. btr.AppendEntity(pll_ad1);
  950. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  951. //判断宽度和高度能否放下文字
  952. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  953. tfh_temp.TextStyleId = HZ;
  954. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  955. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  956. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  957. tfh_temp.AlignmentPoint = tfh_temp.Position;
  958. //计算图幅号位数
  959. int ws = tfh_temp.TextString.Length;
  960. double tfh_width = Math.Abs(x + dist_l * 3 - pts[0].X);
  961. double tfh_height = Math.Abs((dist_w * (3 - num_y) - y_plus));
  962. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl) &&
  963. tfh_height > 1.25 * bl)
  964. {
  965. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  966. //图幅号y坐标计算
  967. double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
  968. double tfh_y = y + dist_nw + dist_w2jt + dist_w * 2 + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
  969. Point3d Topt_temp = new Point3d(tfh_x, tfh_y, tfh_temp.AlignmentPoint.Z);
  970. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  971. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  972. tfh_temp.Layer = "9800";
  973. tfh_temp.ColorIndex = 4;
  974. tfh_temp.Height = 1.25 * bl;
  975. }
  976. else
  977. tfh_temp.Erase();
  978. }
  979. //右上下
  980. else if (pts[0].X > x + dist_l * 2 && Math.Round(y_check / bc, 2) < 2 && Math.Round(y_check / bc, 2) > 1)
  981. {
  982. Polyline pll_ad = new Polyline();
  983. pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  984. pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
  985. pll_ad.Layer = "9800";
  986. pll_ad.Linetype = "Bylayer";
  987. pll_ad.SetDatabaseDefaults();
  988. btr.AppendEntity(pll_ad);
  989. tran.AddNewlyCreatedDBObject(pll_ad, true);
  990. Polyline pll_ad1 = new Polyline();
  991. pll_ad1.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
  992. pll_ad1.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * 2 + y_plus), 0, 0, 0);
  993. pll_ad1.Layer = "9800";
  994. pll_ad1.Linetype = "Bylayer";
  995. pll_ad1.SetDatabaseDefaults();
  996. btr.AppendEntity(pll_ad1);
  997. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  998. Polyline pll_ad2 = new Polyline();
  999. pll_ad2.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  1000. pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  1001. pll_ad2.Layer = "9800";
  1002. pll_ad2.Linetype = "Bylayer";
  1003. pll_ad2.SetDatabaseDefaults();
  1004. btr.AppendEntity(pll_ad2);
  1005. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  1006. //判断宽度能否放下文字
  1007. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1008. tfh_temp.TextStyleId = HZ;
  1009. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  1010. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1011. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1012. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1013. //计算图幅号位数
  1014. int ws = tfh_temp.TextString.Length;
  1015. double tfh_width = Math.Abs(x + dist_l * 3 - pts[0].X);
  1016. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl))
  1017. {
  1018. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1019. //图幅号y坐标计算
  1020. double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
  1021. double tfh_y = y + dist_nw + dist_w2jt + dist_w * 1.5 + y_plus;
  1022. Point3d Topt_temp = new Point3d(tfh_x, tfh_y, tfh_temp.AlignmentPoint.Z);
  1023. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1024. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1025. tfh_temp.Layer = "9800";
  1026. tfh_temp.ColorIndex = 4;
  1027. tfh_temp.Height = 1.25 * bl;
  1028. }
  1029. else
  1030. tfh_temp.Erase();
  1031. Point3dCollection ptscoll = new Point3dCollection();
  1032. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w * 2 + 0.01, 0));
  1033. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w * 2, 0));
  1034. Point3d bk = new Point3d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * 2, 0);
  1035. sele_dele(ptscoll, ed, tran, x + dist_l * 3, bk, btr);
  1036. }
  1037. //右下下
  1038. if (pts[0].X > x + dist_l * 2 && y_plus_down < 0)
  1039. {
  1040. Polyline pll_ad = new Polyline();
  1041. pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt), 0, 0, 0);
  1042. pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1043. pll_ad.Layer = "9800";
  1044. pll_ad.Linetype = "Bylayer";
  1045. pll_ad.SetDatabaseDefaults();
  1046. btr.AppendEntity(pll_ad);
  1047. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1048. Polyline pll_ad1 = new Polyline();
  1049. pll_ad1.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1050. pll_ad1.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1051. pll_ad1.Layer = "9800";
  1052. pll_ad1.Linetype = "Bylayer";
  1053. pll_ad1.SetDatabaseDefaults();
  1054. btr.AppendEntity(pll_ad1);
  1055. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  1056. //判断宽度能否放下文字
  1057. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1058. tfh_temp.TextStyleId = HZ;
  1059. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  1060. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1061. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1062. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1063. //计算图幅号位数
  1064. int ws = tfh_temp.TextString.Length;
  1065. double tfh_width = Math.Abs(x + dist_l * 3 - pts[0].X);
  1066. double tfh_height = (dist_w - y_plus);
  1067. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl) &&
  1068. tfh_height > 1.25 * bl)
  1069. {
  1070. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1071. //图幅号y坐标计算
  1072. double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
  1073. double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
  1074. Point3d Topt_temp = new Point3d(tfh_x, tfh_y, tfh_temp.AlignmentPoint.Z);
  1075. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1076. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1077. tfh_temp.Layer = "9800";
  1078. tfh_temp.ColorIndex = 4;
  1079. tfh_temp.Height = 1.25 * bl;
  1080. }
  1081. else
  1082. tfh_temp.Erase();
  1083. }
  1084. //右下上
  1085. else if (pts[0].X > x + dist_l * 2 && y_plus_down < dist_w && y_plus_down > 0)
  1086. {
  1087. Polyline pll_ad = new Polyline();
  1088. pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  1089. pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
  1090. pll_ad.Layer = "9800";
  1091. pll_ad.Linetype = "Bylayer";
  1092. pll_ad.SetDatabaseDefaults();
  1093. btr.AppendEntity(pll_ad);
  1094. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1095. Polyline pll_ad1 = new Polyline();
  1096. pll_ad1.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
  1097. pll_ad1.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + y_plus), 0, 0, 0);
  1098. pll_ad1.Layer = "9800";
  1099. pll_ad1.Linetype = "Bylayer";
  1100. pll_ad1.SetDatabaseDefaults();
  1101. btr.AppendEntity(pll_ad1);
  1102. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  1103. Polyline pll_ad2 = new Polyline();
  1104. pll_ad2.AddVertexAt(0, new Point2d(x + dist_l * 3, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  1105. pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w + y_plus), 0, 0, 0);
  1106. pll_ad2.Layer = "9800";
  1107. pll_ad2.Linetype = "Bylayer";
  1108. pll_ad2.SetDatabaseDefaults();
  1109. btr.AppendEntity(pll_ad2);
  1110. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  1111. //判断宽度能否放下文字
  1112. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1113. tfh_temp.TextStyleId = HZ;
  1114. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  1115. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1116. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1117. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1118. //计算图幅号位数
  1119. int ws = tfh_temp.TextString.Length;
  1120. double tfh_width = Math.Abs(x + dist_l * 3 - pts[0].X);
  1121. if (tfh_width > ws * bl + (ws - 1) * (0.25 * bl))
  1122. {
  1123. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1124. //图幅号y坐标计算
  1125. double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
  1126. double tfh_y = y + dist_nw + dist_w2jt + y_plus + dist_w / 2;
  1127. Point3d Topt_temp = new Point3d(tfh_x, tfh_y, tfh_temp.AlignmentPoint.Z);
  1128. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1129. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1130. tfh_temp.Layer = "9800";
  1131. tfh_temp.ColorIndex = 4;
  1132. tfh_temp.Height = 1.25 * bl;
  1133. }
  1134. else
  1135. tfh_temp.Erase();
  1136. Point3dCollection ptscoll = new Point3dCollection();
  1137. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w + 0.01, 0));
  1138. ptscoll.Add(new Point3d(x + 0.01, y + dist_nw + dist_w2jt + dist_w, 0));
  1139. Point3d bk = new Point3d(pts[0].X, y + dist_nw + dist_w2jt + dist_w, 0);
  1140. sele_dele(ptscoll, ed, tran, x + dist_l * 3, bk, btr);
  1141. }
  1142. //中上左
  1143. if (pts[0].X > x && pts[1].X < x + dist_l * 2 && y_check / bc > 2)
  1144. {
  1145. Polyline pll_ad = new Polyline();
  1146. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 3), 0, 0, 0);
  1147. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1148. pll_ad.Layer = "9800";
  1149. pll_ad.Linetype = "Bylayer";
  1150. pll_ad.SetDatabaseDefaults();
  1151. btr.AppendEntity(pll_ad);
  1152. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1153. Polyline pll_ad1 = new Polyline();
  1154. pll_ad1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1155. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1156. pll_ad1.Layer = "9800";
  1157. pll_ad1.Linetype = "Bylayer";
  1158. pll_ad1.SetDatabaseDefaults();
  1159. btr.AppendEntity(pll_ad1);
  1160. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  1161. Polyline pll_ad2 = new Polyline();
  1162. pll_ad2.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1163. pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1164. pll_ad2.Layer = "9800";
  1165. pll_ad2.Linetype = "Bylayer";
  1166. pll_ad2.SetDatabaseDefaults();
  1167. btr.AppendEntity(pll_ad2);
  1168. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  1169. //判断宽度和高度能否放下文字
  1170. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1171. tfh_temp.TextStyleId = HZ;
  1172. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  1173. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1174. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1175. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1176. //计算图幅号位数
  1177. int ws = tfh_temp.TextString.Length;
  1178. double tfh_height = Math.Abs((dist_w * (3 - num_y) - y_plus));
  1179. if (tfh_height > 1.25 * bl)
  1180. {
  1181. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1182. //图幅号y坐标计算
  1183. double tfh_y = y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
  1184. Point3d Topt_temp = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  1185. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1186. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1187. tfh_temp.Layer = "9800";
  1188. tfh_temp.ColorIndex = 4;
  1189. tfh_temp.Height = 1.25 * bl;
  1190. }
  1191. else
  1192. tfh_temp.Erase();
  1193. }
  1194. //中上右
  1195. if (pts[0].X > x + dist_l && pts[1].X < x + dist_l * 3 && y_check / bc > 2)
  1196. {
  1197. Polyline pll_ad = new Polyline();
  1198. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * 3), 0, 0, 0);
  1199. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1200. pll_ad.Layer = "9800";
  1201. pll_ad.Linetype = "Bylayer";
  1202. pll_ad.SetDatabaseDefaults();
  1203. btr.AppendEntity(pll_ad);
  1204. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1205. Polyline pll_ad1 = new Polyline();
  1206. pll_ad1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1207. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1208. pll_ad1.Layer = "9800";
  1209. pll_ad1.Linetype = "Bylayer";
  1210. pll_ad1.SetDatabaseDefaults();
  1211. btr.AppendEntity(pll_ad1);
  1212. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  1213. Polyline pll_ad2 = new Polyline();
  1214. pll_ad2.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1215. pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  1216. pll_ad2.Layer = "9800";
  1217. pll_ad2.Linetype = "Bylayer";
  1218. pll_ad2.SetDatabaseDefaults();
  1219. btr.AppendEntity(pll_ad2);
  1220. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  1221. //判断宽度和高度能否放下文字
  1222. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1223. tfh_temp.TextStyleId = HZ;
  1224. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  1225. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1226. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1227. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1228. //计算图幅号位数
  1229. int ws = tfh_temp.TextString.Length;
  1230. double tfh_height = Math.Abs((dist_w * (3 - num_y) - y_plus));
  1231. if (tfh_height > 1.25 * bl)
  1232. {
  1233. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1234. //图幅号y坐标计算
  1235. double tfh_y = y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
  1236. Point3d Topt_temp = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  1237. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1238. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1239. tfh_temp.Layer = "9800";
  1240. tfh_temp.ColorIndex = 4;
  1241. tfh_temp.Height = 1.25 * bl;
  1242. }
  1243. else
  1244. tfh_temp.Erase();
  1245. }
  1246. //中下左
  1247. if (pts[0].X > x && pts[1].X < x + dist_l * 2 && y_plus_down < 0)
  1248. {
  1249. Polyline pll_ad = new Polyline();
  1250. pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt), 0, 0, 0);
  1251. pll_ad.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1252. pll_ad.Layer = "9800";
  1253. pll_ad.Linetype = "Bylayer";
  1254. pll_ad.SetDatabaseDefaults();
  1255. btr.AppendEntity(pll_ad);
  1256. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1257. Polyline pll_ad1 = new Polyline();
  1258. pll_ad1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1259. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1260. pll_ad1.Layer = "9800";
  1261. pll_ad1.Linetype = "Bylayer";
  1262. pll_ad1.SetDatabaseDefaults();
  1263. btr.AppendEntity(pll_ad1);
  1264. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  1265. Polyline pll_ad2 = new Polyline();
  1266. pll_ad2.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt), 0, 0, 0);
  1267. pll_ad2.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1268. pll_ad2.Layer = "9800";
  1269. pll_ad2.Linetype = "Bylayer";
  1270. pll_ad2.SetDatabaseDefaults();
  1271. btr.AppendEntity(pll_ad2);
  1272. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  1273. //判断宽度和高度能否放下文字
  1274. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1275. tfh_temp.TextStyleId = HZ;
  1276. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  1277. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1278. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1279. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1280. //计算图幅号位数
  1281. int ws = tfh_temp.TextString.Length;
  1282. double tfh_height = (dist_w - y_plus);
  1283. if (tfh_height > 1.25 * bl)
  1284. {
  1285. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1286. //图幅号y坐标计算
  1287. double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
  1288. Point3d Topt_temp = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  1289. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1290. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1291. tfh_temp.Layer = "9800";
  1292. tfh_temp.ColorIndex = 4;
  1293. tfh_temp.Height = 1.25 * bl;
  1294. }
  1295. else
  1296. tfh_temp.Erase();
  1297. }
  1298. //中下右
  1299. if (pts[0].X > x + dist_l && pts[1].X < x + dist_l * 3 && y_plus_down < 0)
  1300. {
  1301. Polyline pll_ad = new Polyline();
  1302. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt), 0, 0, 0);
  1303. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1304. pll_ad.Layer = "9800";
  1305. pll_ad.Linetype = "Bylayer";
  1306. pll_ad.SetDatabaseDefaults();
  1307. btr.AppendEntity(pll_ad);
  1308. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1309. Polyline pll_ad1 = new Polyline();
  1310. pll_ad1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1311. pll_ad1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1312. pll_ad1.Layer = "9800";
  1313. pll_ad1.Linetype = "Bylayer";
  1314. pll_ad1.SetDatabaseDefaults();
  1315. btr.AppendEntity(pll_ad1);
  1316. tran.AddNewlyCreatedDBObject(pll_ad1, true);
  1317. Polyline pll_ad2 = new Polyline();
  1318. pll_ad2.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt), 0, 0, 0);
  1319. pll_ad2.AddVertexAt(1, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + (dist_w - y_plus)), 0, 0, 0);
  1320. pll_ad2.Layer = "9800";
  1321. pll_ad2.Linetype = "Bylayer";
  1322. pll_ad2.SetDatabaseDefaults();
  1323. btr.AppendEntity(pll_ad2);
  1324. tran.AddNewlyCreatedDBObject(pll_ad2, true);
  1325. //判断宽度和高度能否放下文字
  1326. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1327. tfh_temp.TextStyleId = HZ;
  1328. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  1329. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1330. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1331. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1332. //计算图幅号位数
  1333. int ws = tfh_temp.TextString.Length;
  1334. double tfh_height = (dist_w - y_plus);
  1335. if (tfh_height > 1.25 * bl)
  1336. {
  1337. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1338. //图幅号y坐标计算
  1339. double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
  1340. Point3d Topt_temp = new Point3d(pts[0].X + (pts[1].X - pts[0].X) / 2, tfh_y, tfh_temp.AlignmentPoint.Z);
  1341. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1342. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1343. tfh_temp.Layer = "9800";
  1344. tfh_temp.ColorIndex = 4;
  1345. tfh_temp.Height = 1.25 * bl;
  1346. }
  1347. else
  1348. tfh_temp.Erase();
  1349. }
  1350. }
  1351. //x方向错位
  1352. else if (x_check % bc != 0)
  1353. {
  1354. //选择y方向竖线删除
  1355. Point3dCollection ptscoll = new Point3dCollection();
  1356. ptscoll.Add(new Point3d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
  1357. ptscoll.Add(new Point3d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
  1358. TypedValue[] value = new TypedValue[]
  1359. {
  1360. new TypedValue((int)DxfCode.LayerName,"9800"),
  1361. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  1362. };
  1363. SelectionFilter filter = new SelectionFilter(value);
  1364. //dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  1365. //acadApp.ZoomExtents();
  1366. PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
  1367. if (psr.Status == PromptStatus.OK)
  1368. {
  1369. SelectionSet ss = psr.Value;
  1370. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  1371. Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  1372. //判断选中多条线段后情况
  1373. if (idcoll.Count > 1)
  1374. {
  1375. Polyline temp1 = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  1376. Polyline temp2 = tran.GetObject(idcoll[1], OpenMode.ForWrite) as Polyline;
  1377. if (temp1.Length > temp2.Length)
  1378. {
  1379. pll_delete = temp1;
  1380. }
  1381. else
  1382. {
  1383. pll_delete = temp2;
  1384. }
  1385. }
  1386. //有相交但超出左范围
  1387. if (pll_delete.StartPoint.X == x)
  1388. {
  1389. Polyline pll_ad = new Polyline();
  1390. pll_ad.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
  1391. pll_ad.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
  1392. pll_ad.Layer = "9800";
  1393. pll_ad.Linetype = "Bylayer";
  1394. pll_ad.SetDatabaseDefaults();
  1395. btr.AppendEntity(pll_ad);
  1396. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1397. x_addline.Add(pll_ad);
  1398. //判断宽度能否放下文字
  1399. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1400. tfh_temp.TextStyleId = HZ;
  1401. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  1402. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1403. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1404. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1405. //计算图幅号位数判断是否需要保留
  1406. int ws = tfh_temp.TextString.Length;
  1407. if (Math.Abs(pts[1].X - x) > ws * bl + (ws - 1) * (0.25 * bl))
  1408. {
  1409. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1410. //图幅号x坐标计算
  1411. //double tfh_x = Math.Round(x + (pts[1].X - x) / 2);
  1412. double tfh_x = x + (pts[1].X - x) / 2;
  1413. Point3d Topt_temp = new Point3d(tfh_x, y + dist_nw + dist_w2jt + dist_w * (num_y) + dist_w / 2, tfh_temp.AlignmentPoint.Z);
  1414. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1415. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1416. tfh_temp.Layer = "9800";
  1417. tfh_temp.ColorIndex = 4;
  1418. tfh_temp.Height = 1.25 * bl;
  1419. }
  1420. else
  1421. {
  1422. tfh_temp.Erase();
  1423. }
  1424. //删除接图表内左竖线
  1425. Point3dCollection deleteptscoll = new Point3dCollection();
  1426. deleteptscoll.Add(new Point3d(x + dist_l, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
  1427. deleteptscoll.Add(new Point3d(x + dist_l + 0.01, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
  1428. TypedValue[] deletevalue = new TypedValue[]
  1429. {
  1430. new TypedValue((int)DxfCode.LayerName,"9800"),
  1431. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  1432. };
  1433. SelectionFilter deletefilter = new SelectionFilter(deletevalue);
  1434. //acadApp.ZoomExtents();
  1435. PromptSelectionResult deletepsr = ed.SelectFence(deleteptscoll, deletefilter);
  1436. //acadApp.ZoomPrevious();
  1437. if (deletepsr.Status == PromptStatus.OK)
  1438. {
  1439. SelectionSet deletess = deletepsr.Value;
  1440. ObjectIdCollection deleteidcoll = new ObjectIdCollection(deletess.GetObjectIds());
  1441. Polyline deletepll = tran.GetObject(deleteidcoll[0], OpenMode.ForWrite) as Polyline;
  1442. Point3dCollection pt_break = new Point3dCollection();
  1443. DBObjectCollection obj = new DBObjectCollection();
  1444. if (num_y == 0)
  1445. {
  1446. pt_break.Add(new Point3d(deletepll.StartPoint.X, y + dist_nw + dist_w2jt + dist_w, 0));
  1447. obj = deletepll.GetSplitCurves(pt_break);
  1448. Polyline pll_delete1 = obj[0] as Polyline;
  1449. Polyline pll_delete2 = obj[1] as Polyline;
  1450. if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt ||
  1451. pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt)
  1452. {
  1453. pll_delete2.SetDatabaseDefaults();
  1454. btr.AppendEntity(pll_delete2);
  1455. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1456. }
  1457. else
  1458. {
  1459. pll_delete1.SetDatabaseDefaults();
  1460. btr.AppendEntity(pll_delete1);
  1461. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1462. }
  1463. deletepll.Erase();
  1464. }
  1465. else
  1466. {
  1467. pt_break.Add(new Point3d(deletepll.StartPoint.X, y + dist_nw + dist_w2jt + dist_w * num_y, 0));
  1468. obj = deletepll.GetSplitCurves(pt_break);
  1469. Polyline pll_delete1 = obj[0] as Polyline;
  1470. Polyline pll_delete2 = obj[1] as Polyline;
  1471. if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3 ||
  1472. pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3)
  1473. {
  1474. pll_delete2.SetDatabaseDefaults();
  1475. btr.AppendEntity(pll_delete2);
  1476. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1477. }
  1478. else
  1479. {
  1480. pll_delete1.SetDatabaseDefaults();
  1481. btr.AppendEntity(pll_delete1);
  1482. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1483. }
  1484. deletepll.Erase();
  1485. }
  1486. }
  1487. }
  1488. //有相交但超出右范围
  1489. else if (pll_delete.StartPoint.X == x + dist_l * 3)
  1490. {
  1491. Polyline pll_ad = new Polyline();
  1492. pll_ad.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
  1493. pll_ad.AddVertexAt(1, new Point2d(pts[3].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
  1494. pll_ad.Layer = "9800";
  1495. pll_ad.Linetype = "Bylayer";
  1496. pll_ad.SetDatabaseDefaults();
  1497. btr.AppendEntity(pll_ad);
  1498. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1499. x_addline.Add(pll_ad);
  1500. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1501. tfh_temp.TextStyleId = HZ;
  1502. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  1503. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1504. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1505. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1506. int ws = tfh_temp.TextString.Length;//计算图幅号位数判断是否需要保留
  1507. if (Math.Abs(x + dist_l * 3 - pts[0].X) > ws * bl + (ws - 1) * (0.25 * bl))
  1508. {
  1509. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1510. //图幅号x坐标计算
  1511. //double tfh_x = Math.Round(x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2);
  1512. double tfh_x = x + dist_l * 3 - Math.Abs(x + dist_l * 3 - pts[0].X) / 2;
  1513. Point3d Topt_temp = new Point3d(tfh_x, y + dist_nw + dist_w2jt + dist_w * (num_y) + dist_w / 2, tfh_temp.AlignmentPoint.Z);
  1514. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1515. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1516. tfh_temp.Layer = "9800";
  1517. tfh_temp.ColorIndex = 4;
  1518. tfh_temp.Height = 1.25 * bl;
  1519. }
  1520. else
  1521. {
  1522. tfh_temp.Erase();
  1523. }
  1524. //删除接图表内右竖线
  1525. Point3dCollection deleteptscoll = new Point3dCollection();
  1526. deleteptscoll.Add(new Point3d(x + dist_l * 2, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
  1527. deleteptscoll.Add(new Point3d(x + dist_l * 2 + 0.01, y + dist_nw + dist_w2jt + dist_w * num_y + (dist_w / 2), 0));
  1528. TypedValue[] deletevalue = new TypedValue[]
  1529. {
  1530. new TypedValue((int)DxfCode.LayerName,"9800"),
  1531. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  1532. };
  1533. SelectionFilter deletefilter = new SelectionFilter(deletevalue);
  1534. //acadApp.ZoomExtents();
  1535. PromptSelectionResult deletepsr = ed.SelectFence(deleteptscoll, deletefilter);
  1536. //acadApp.ZoomPrevious();
  1537. if (deletepsr.Status == PromptStatus.OK)
  1538. {
  1539. SelectionSet deletess = deletepsr.Value;
  1540. ObjectIdCollection deleteidcoll = new ObjectIdCollection(deletess.GetObjectIds());
  1541. Polyline deletepll = tran.GetObject(deleteidcoll[0], OpenMode.ForWrite) as Polyline;
  1542. Point3dCollection pt_break = new Point3dCollection();
  1543. DBObjectCollection obj = new DBObjectCollection();
  1544. if (num_y == 0)
  1545. {
  1546. pt_break.Add(new Point3d(deletepll.StartPoint.X, y + dist_nw + dist_w2jt + dist_w, 0));
  1547. obj = deletepll.GetSplitCurves(pt_break);
  1548. Polyline pll_delete1 = obj[0] as Polyline;
  1549. Polyline pll_delete2 = obj[1] as Polyline;
  1550. if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt ||
  1551. pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt)
  1552. {
  1553. pll_delete2.SetDatabaseDefaults();
  1554. btr.AppendEntity(pll_delete2);
  1555. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1556. }
  1557. else
  1558. {
  1559. pll_delete1.SetDatabaseDefaults();
  1560. btr.AppendEntity(pll_delete1);
  1561. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1562. }
  1563. deletepll.Erase();
  1564. }
  1565. else
  1566. {
  1567. pt_break.Add(new Point3d(deletepll.StartPoint.X, y + dist_nw + dist_w2jt + dist_w * num_y, 0));
  1568. obj = deletepll.GetSplitCurves(pt_break);
  1569. Polyline pll_delete1 = obj[0] as Polyline;
  1570. Polyline pll_delete2 = obj[1] as Polyline;
  1571. if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3 ||
  1572. pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3)
  1573. {
  1574. pll_delete2.SetDatabaseDefaults();
  1575. btr.AppendEntity(pll_delete2);
  1576. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1577. }
  1578. else
  1579. {
  1580. pll_delete1.SetDatabaseDefaults();
  1581. btr.AppendEntity(pll_delete1);
  1582. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1583. }
  1584. deletepll.Erase();
  1585. }
  1586. }
  1587. }
  1588. else
  1589. {
  1590. //if (cw_x != pts[0].Y)
  1591. //{
  1592. // zj_x.Add(tf[i]);
  1593. // flag_x = 1;
  1594. // cw_x = pts[0].Y;
  1595. //}
  1596. //else if (cw_x == pts[0].Y && flag_x == 1)
  1597. //{
  1598. // zj_x.RemoveAt(zj_x.Count - 1);
  1599. // flag_x = 0;
  1600. //}
  1601. //if (cw_x.Count != 0)
  1602. //{
  1603. // int flag = 0;
  1604. // int cf = 0;
  1605. // for (int ii = 0; ii < cw_x.Count; ii++)
  1606. // {
  1607. // if (cw_x[ii].Y != pts[0].Y)
  1608. // flag = 1;
  1609. // else
  1610. // {
  1611. // flag = 0;
  1612. // cf = ii;
  1613. // }
  1614. // }
  1615. // if(flag == 1)
  1616. // {
  1617. // zj_x.Add(tf[i]);
  1618. // cw_x.Add(pts[0]);
  1619. // }
  1620. // else
  1621. // {
  1622. // zj_x.RemoveAt(cf);
  1623. // cw_x.RemoveAt(cf);
  1624. // }
  1625. //}
  1626. //else
  1627. //{
  1628. // zj_x.Add(tf[i]);
  1629. // cw_x.Add(pts[0]);
  1630. //}
  1631. cw_x.Add(pts[0]);
  1632. zj_x.Add(tf[i]);
  1633. Point3dCollection pt_break = new Point3dCollection();
  1634. DBObjectCollection obj = new DBObjectCollection();
  1635. if (pll_delete.Length != 12 * bl / 3)
  1636. {
  1637. pt_break.Add(new Point3d(pll_delete.StartPoint.X, y + dist_nw
  1638. + dist_w2jt + ((num_y + 2) / 2) * dist_w, 0));
  1639. obj = pll_delete.GetSplitCurves(pt_break);
  1640. Polyline pll_delete1 = obj[0] as Polyline;
  1641. Polyline pll_delete2 = obj[1] as Polyline;
  1642. if (pll_delete1.Length < pll_delete2.Length)
  1643. {
  1644. pll_delete2.SetDatabaseDefaults();
  1645. btr.AppendEntity(pll_delete2);
  1646. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1647. }
  1648. else if (pll_delete1.Length == pll_delete2.Length)
  1649. {
  1650. if (pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt ||
  1651. pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt ||
  1652. pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3 ||
  1653. pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3)
  1654. {
  1655. pll_delete2.SetDatabaseDefaults();
  1656. btr.AppendEntity(pll_delete2);
  1657. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1658. }
  1659. else
  1660. {
  1661. pll_delete1.SetDatabaseDefaults();
  1662. btr.AppendEntity(pll_delete1);
  1663. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1664. }
  1665. }
  1666. else
  1667. {
  1668. pll_delete1.SetDatabaseDefaults();
  1669. btr.AppendEntity(pll_delete1);
  1670. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1671. }
  1672. }
  1673. pll_delete.Erase();
  1674. Polyline pll_cg = new Polyline();
  1675. pll_cg.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
  1676. //pll_cg.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
  1677. //pll_cg.AddVertexAt(2, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
  1678. pll_cg.AddVertexAt(1, new Point2d(pts[3].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
  1679. //pll_cg.AddVertexAt(4, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
  1680. Polyline pll_cg_1 = new Polyline();
  1681. pll_cg_1.AddVertexAt(0, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y), 0, 0, 0);
  1682. pll_cg_1.AddVertexAt(1, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1)), 0, 0, 0);
  1683. pll_cg.Layer = "9800";
  1684. pll_cg.Linetype = "Bylayer";
  1685. pll_cg.SetDatabaseDefaults();
  1686. btr.AppendEntity(pll_cg);
  1687. tran.AddNewlyCreatedDBObject(pll_cg, true);
  1688. pll_cg_1.Layer = "9800";
  1689. pll_cg_1.Linetype = "Bylayer";
  1690. pll_cg_1.SetDatabaseDefaults();
  1691. btr.AppendEntity(pll_cg_1);
  1692. tran.AddNewlyCreatedDBObject(pll_cg_1, true);
  1693. x_addline.Add(pll_cg);
  1694. x_addline.Add(pll_cg_1);
  1695. DBText tfh = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1696. tfh.HorizontalMode = TextHorizontalMode.TextCenter;
  1697. tfh.VerticalMode = TextVerticalMode.TextVerticalMid;
  1698. tfh.AlignmentPoint = tfh.Position;
  1699. Point3d Frompt = new Point3d(tfh.AlignmentPoint.X, tfh.AlignmentPoint.Y, tfh.AlignmentPoint.Z);
  1700. 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);
  1701. Vector3d acVec3d = Frompt.GetVectorTo(Topt);
  1702. tfh.TransformBy(Matrix3d.Displacement(acVec3d));
  1703. tfh.Layer = "9800";
  1704. tfh.ColorIndex = 4;
  1705. tfh.Height = 1.25 * bl;
  1706. tfh.TextStyleId = HZ;
  1707. if (bl > 4) tfh.WidthFactor = 0.75;
  1708. }
  1709. }
  1710. }
  1711. //y方向错位
  1712. else if (y_check % bc != 0)
  1713. {
  1714. double y_plus1 = (Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5) / bc) * dist_w;
  1715. double y_plus2 = (Math.Round(pts[2].Y - y - dist_nw - dist_w2jt, 5) / bc) * dist_w;
  1716. if (y_plus1 < 0)
  1717. y_plus1 = 0;
  1718. Point3dCollection ptscoll = new Point3dCollection();
  1719. ptscoll.Add(new Point3d(x + dist_l * num_x + 0.01, y + dist_nw + dist_w2jt + y_plus1, 0));
  1720. ptscoll.Add(new Point3d(x + dist_l * num_x + 0.01, y + dist_nw + dist_w2jt + y_plus2, 0));
  1721. TypedValue[] value = new TypedValue[]
  1722. {
  1723. new TypedValue((int)DxfCode.LayerName,"9800"),
  1724. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  1725. };
  1726. SelectionFilter filter = new SelectionFilter(value);
  1727. //dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  1728. //acadApp.ZoomExtents();
  1729. PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
  1730. //acadApp.ZoomPrevious();
  1731. if (psr.Status == PromptStatus.OK)
  1732. {
  1733. SelectionSet ss = psr.Value;
  1734. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  1735. Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  1736. if (idcoll.Count > 1)
  1737. {
  1738. Polyline temp1 = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  1739. Polyline temp2 = tran.GetObject(idcoll[1], OpenMode.ForWrite) as Polyline;
  1740. if (temp1.Length > temp2.Length)
  1741. {
  1742. pll_delete = temp1;
  1743. }
  1744. else
  1745. {
  1746. pll_delete = temp2;
  1747. }
  1748. }
  1749. //有相交但超出上方
  1750. if (pll_delete.StartPoint.Y == y + dist_nw + dist_w2jt + dist_w * 3)
  1751. {
  1752. Polyline pll_ad = new Polyline();
  1753. 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);
  1754. 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);
  1755. pll_ad.Layer = "9800";
  1756. pll_ad.Linetype = "Bylayer";
  1757. pll_ad.SetDatabaseDefaults();
  1758. btr.AppendEntity(pll_ad);
  1759. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1760. y_addline.Add(pll_ad);
  1761. //判断高度能否放下文字
  1762. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1763. tfh_temp.TextStyleId = HZ;
  1764. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  1765. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1766. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1767. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1768. //计算图幅号位数判断是否需要保留
  1769. int ws = tfh_temp.TextString.Length;
  1770. if (Math.Abs((dist_w * (3 - num_y) - y_plus)) > 1.25 * bl)
  1771. {
  1772. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1773. //图幅号y坐标计算
  1774. double tfh_y = y + dist_nw + dist_w2jt + dist_w * num_y + y_plus + (dist_w * (3 - num_y) - y_plus) / 2;
  1775. Point3d Topt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_y, tfh_temp.AlignmentPoint.Z);
  1776. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1777. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1778. tfh_temp.Layer = "9800";
  1779. tfh_temp.ColorIndex = 4;
  1780. tfh_temp.Height = 1.25 * bl;
  1781. }
  1782. else
  1783. {
  1784. tfh_temp.Erase();
  1785. }
  1786. //删除接图表内上横线
  1787. Point3dCollection deleteptscoll = new Point3dCollection();
  1788. deleteptscoll.Add(new Point3d(x + dist_l / 2 + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w * 2, 0));
  1789. deleteptscoll.Add(new Point3d(x + dist_l / 2 + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w * 2 + 0.01, 0));
  1790. TypedValue[] deletevalue = new TypedValue[]
  1791. {
  1792. new TypedValue((int)DxfCode.LayerName,"9800"),
  1793. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  1794. };
  1795. SelectionFilter deletefilter = new SelectionFilter(deletevalue);
  1796. //acadApp.ZoomExtents();
  1797. PromptSelectionResult deletepsr = ed.SelectFence(deleteptscoll, deletefilter);
  1798. //acadApp.ZoomPrevious();
  1799. if (deletepsr.Status == PromptStatus.OK)
  1800. {
  1801. SelectionSet deletess = deletepsr.Value;
  1802. ObjectIdCollection deleteidcoll = new ObjectIdCollection(deletess.GetObjectIds());
  1803. Polyline deletepll = tran.GetObject(deleteidcoll[0], OpenMode.ForWrite) as Polyline;
  1804. Point3dCollection pt_break = new Point3dCollection();
  1805. DBObjectCollection obj = new DBObjectCollection();
  1806. if (num_x == 0)
  1807. {
  1808. pt_break.Add(new Point3d(x + dist_l, deletepll.StartPoint.Y, 0));
  1809. obj = deletepll.GetSplitCurves(pt_break);
  1810. Polyline pll_delete1 = obj[0] as Polyline;
  1811. Polyline pll_delete2 = obj[1] as Polyline;
  1812. if (pll_delete1.StartPoint.X == x ||
  1813. pll_delete1.EndPoint.Y == x)
  1814. {
  1815. pll_delete2.SetDatabaseDefaults();
  1816. btr.AppendEntity(pll_delete2);
  1817. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1818. }
  1819. else
  1820. {
  1821. pll_delete1.SetDatabaseDefaults();
  1822. btr.AppendEntity(pll_delete1);
  1823. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1824. }
  1825. deletepll.Erase();
  1826. }
  1827. else
  1828. {
  1829. pt_break.Add(new Point3d(x + dist_l * 2, deletepll.StartPoint.Y, 0));
  1830. obj = deletepll.GetSplitCurves(pt_break);
  1831. Polyline pll_delete1 = obj[0] as Polyline;
  1832. Polyline pll_delete2 = obj[1] as Polyline;
  1833. if (pll_delete1.StartPoint.Y == x + dist_l * 3 ||
  1834. pll_delete1.EndPoint.Y == x + dist_l * 3)
  1835. {
  1836. pll_delete2.SetDatabaseDefaults();
  1837. btr.AppendEntity(pll_delete2);
  1838. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1839. }
  1840. else
  1841. {
  1842. pll_delete1.SetDatabaseDefaults();
  1843. btr.AppendEntity(pll_delete1);
  1844. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1845. }
  1846. deletepll.Erase();
  1847. }
  1848. }
  1849. }
  1850. //有相交但超出下方
  1851. else if (pll_delete.StartPoint.Y == y + dist_nw + dist_w2jt)
  1852. {
  1853. Polyline pll_ad = new Polyline();
  1854. 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);
  1855. 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);
  1856. pll_ad.Layer = "9800";
  1857. pll_ad.Linetype = "Bylayer";
  1858. pll_ad.SetDatabaseDefaults();
  1859. btr.AppendEntity(pll_ad);
  1860. tran.AddNewlyCreatedDBObject(pll_ad, true);
  1861. y_addline.Add(pll_ad);
  1862. //判断高度能否放下文字
  1863. DBText tfh_temp = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  1864. tfh_temp.TextStyleId = HZ;
  1865. if (bl > 4) tfh_temp.WidthFactor = 0.75;
  1866. tfh_temp.HorizontalMode = TextHorizontalMode.TextCenter;
  1867. tfh_temp.VerticalMode = TextVerticalMode.TextVerticalMid;
  1868. tfh_temp.AlignmentPoint = tfh_temp.Position;
  1869. //计算图幅号位数判断是否需要保留
  1870. int ws = tfh_temp.TextString.Length;
  1871. if (dist_w - y_plus > 1.25 * bl)
  1872. {
  1873. Point3d Frompt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_temp.AlignmentPoint.Y, tfh_temp.AlignmentPoint.Z);
  1874. //图幅号y坐标计算
  1875. double tfh_y = y + dist_nw + dist_w2jt + (dist_w - y_plus) / 2;
  1876. Point3d Topt_temp = new Point3d(tfh_temp.AlignmentPoint.X, tfh_y, tfh_temp.AlignmentPoint.Z);
  1877. Vector3d acVec3d_temp = Frompt_temp.GetVectorTo(Topt_temp);
  1878. tfh_temp.TransformBy(Matrix3d.Displacement(acVec3d_temp));
  1879. tfh_temp.Layer = "9800";
  1880. tfh_temp.ColorIndex = 4;
  1881. tfh_temp.Height = 1.25 * bl;
  1882. }
  1883. else
  1884. {
  1885. tfh_temp.Erase();
  1886. }
  1887. //删除接图表内下横线
  1888. Point3dCollection deleteptscoll = new Point3dCollection();
  1889. deleteptscoll.Add(new Point3d(x + dist_l / 2 + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w, 0));
  1890. deleteptscoll.Add(new Point3d(x + dist_l / 2 + dist_l * num_x, y + dist_nw + dist_w2jt + dist_w + 0.01, 0));
  1891. TypedValue[] deletevalue = new TypedValue[]
  1892. {
  1893. new TypedValue((int)DxfCode.LayerName,"9800"),
  1894. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  1895. };
  1896. SelectionFilter deletefilter = new SelectionFilter(deletevalue);
  1897. //acadApp.ZoomExtents();
  1898. PromptSelectionResult deletepsr = ed.SelectFence(deleteptscoll, deletefilter);
  1899. //acadApp.ZoomPrevious();
  1900. if (deletepsr.Status == PromptStatus.OK)
  1901. {
  1902. SelectionSet deletess = deletepsr.Value;
  1903. ObjectIdCollection deleteidcoll = new ObjectIdCollection(deletess.GetObjectIds());
  1904. Polyline deletepll = tran.GetObject(deleteidcoll[0], OpenMode.ForWrite) as Polyline;
  1905. Point3dCollection pt_break = new Point3dCollection();
  1906. DBObjectCollection obj = new DBObjectCollection();
  1907. if (num_x == 0)
  1908. {
  1909. pt_break.Add(new Point3d(x + dist_l, deletepll.StartPoint.Y, 0));
  1910. obj = deletepll.GetSplitCurves(pt_break);
  1911. Polyline pll_delete1 = obj[0] as Polyline;
  1912. Polyline pll_delete2 = obj[1] as Polyline;
  1913. if (pll_delete1.StartPoint.X == x ||
  1914. pll_delete1.EndPoint.Y == x)
  1915. {
  1916. pll_delete2.SetDatabaseDefaults();
  1917. btr.AppendEntity(pll_delete2);
  1918. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1919. }
  1920. else
  1921. {
  1922. pll_delete1.SetDatabaseDefaults();
  1923. btr.AppendEntity(pll_delete1);
  1924. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1925. }
  1926. deletepll.Erase();
  1927. }
  1928. else
  1929. {
  1930. pt_break.Add(new Point3d(x + dist_l * 2, deletepll.StartPoint.Y, 0));
  1931. obj = deletepll.GetSplitCurves(pt_break);
  1932. Polyline pll_delete1 = obj[0] as Polyline;
  1933. Polyline pll_delete2 = obj[1] as Polyline;
  1934. if (pll_delete1.StartPoint.Y == x + dist_l * 3 ||
  1935. pll_delete1.EndPoint.Y == x + dist_l * 3)
  1936. {
  1937. pll_delete2.SetDatabaseDefaults();
  1938. btr.AppendEntity(pll_delete2);
  1939. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  1940. }
  1941. else
  1942. {
  1943. pll_delete1.SetDatabaseDefaults();
  1944. btr.AppendEntity(pll_delete1);
  1945. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  1946. }
  1947. deletepll.Erase();
  1948. }
  1949. }
  1950. }
  1951. else
  1952. {
  1953. //if (cw_y != pts[0].X)
  1954. //{
  1955. // zj_y.Add(tf[i]);
  1956. // flag_y = 1;
  1957. // cw_y = pts[0].X;
  1958. //}
  1959. //else if (cw_y == pts[0].X && flag_y == 1)
  1960. //{
  1961. // zj_y.RemoveAt(zj_y.Count - 1);
  1962. // flag_y = 0;
  1963. //}
  1964. //if (cw_y.Count != 0)
  1965. //{
  1966. // int flag = 0;
  1967. // int cf = 0;
  1968. // for (int ii = 0; ii < cw_y.Count; ii++)
  1969. // {
  1970. // if (cw_y[ii].X != pts[0].X)
  1971. // flag = 1;
  1972. // else
  1973. // {
  1974. // flag = 0;
  1975. // cf = ii;
  1976. // }
  1977. // }
  1978. // if (flag == 1)
  1979. // {
  1980. // zj_y.Add(tf[i]);
  1981. // cw_y.Add(pts[0]);
  1982. // }
  1983. // else
  1984. // {
  1985. // zj_y.RemoveAt(cf);
  1986. // cw_y.RemoveAt(cf);
  1987. // }
  1988. //}
  1989. //else
  1990. //{
  1991. // zj_y.Add(tf[i]);
  1992. // cw_y.Add(pts[0]);
  1993. //}
  1994. cw_y.Add(pts[0]);
  1995. zj_y.Add(tf[i]);
  1996. if (pll_delete.Length != 22.5 * bl / 3)
  1997. {
  1998. Point3dCollection pt_break = new Point3dCollection();
  1999. DBObjectCollection obj = new DBObjectCollection();
  2000. pt_break.Add(new Point3d(x + (((num_x + 2) / 2) * dist_l), y + dist_nw
  2001. + dist_w2jt + (num_y + 1) * dist_w, 0));
  2002. obj = pll_delete.GetSplitCurves(pt_break);
  2003. Polyline pll_delete1 = obj[0] as Polyline;
  2004. Polyline pll_delete2 = obj[1] as Polyline;
  2005. if (pll_delete1.Length < pll_delete2.Length)
  2006. {
  2007. pll_delete2.SetDatabaseDefaults();
  2008. btr.AppendEntity(pll_delete2);
  2009. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  2010. }
  2011. else if (pll_delete1.Length == pll_delete2.Length)
  2012. {
  2013. if (pll_delete1.StartPoint.X == x || pll_delete1.EndPoint.X == x ||
  2014. pll_delete1.EndPoint.X == x + dist_l * 3 || pll_delete1.StartPoint.X == x + dist_l * 3)
  2015. {
  2016. pll_delete2.SetDatabaseDefaults();
  2017. btr.AppendEntity(pll_delete2);
  2018. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  2019. }
  2020. else
  2021. {
  2022. pll_delete1.SetDatabaseDefaults();
  2023. btr.AppendEntity(pll_delete1);
  2024. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  2025. }
  2026. }
  2027. else
  2028. {
  2029. pll_delete1.SetDatabaseDefaults();
  2030. btr.AppendEntity(pll_delete1);
  2031. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  2032. }
  2033. }
  2034. pll_delete.Erase();
  2035. Polyline pll_cg_1 = new Polyline();
  2036. pll_cg_1.AddVertexAt(0, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  2037. pll_cg_1.AddVertexAt(1, new Point2d(pts[1].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  2038. Polyline pll_cg_2 = new Polyline();
  2039. 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);
  2040. 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);
  2041. //pll_cg.AddVertexAt(2, new Point2d(pts[2].X, y + dist_nw + dist_w2jt + dist_w * (num_y + 1) + y_plus), 0, 0, 0);
  2042. //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);
  2043. //pll_cg.AddVertexAt(4, new Point2d(pts[0].X, y + dist_nw + dist_w2jt + dist_w * num_y + y_plus), 0, 0, 0);
  2044. pll_cg_1.Layer = "9800";
  2045. pll_cg_1.Linetype = "Bylayer";
  2046. pll_cg_1.SetDatabaseDefaults();
  2047. btr.AppendEntity(pll_cg_1);
  2048. tran.AddNewlyCreatedDBObject(pll_cg_1, true);
  2049. pll_cg_2.Layer = "9800";
  2050. pll_cg_2.Linetype = "Bylayer";
  2051. pll_cg_2.SetDatabaseDefaults();
  2052. btr.AppendEntity(pll_cg_2);
  2053. tran.AddNewlyCreatedDBObject(pll_cg_2, true);
  2054. y_addline.Add(pll_cg_1);
  2055. y_addline.Add(pll_cg_2);
  2056. DBText tfh = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  2057. tfh.HorizontalMode = TextHorizontalMode.TextCenter;
  2058. tfh.VerticalMode = TextVerticalMode.TextVerticalMid;
  2059. tfh.AlignmentPoint = tfh.Position;
  2060. Point3d Frompt = new Point3d(tfh.AlignmentPoint.X, tfh.AlignmentPoint.Y, tfh.AlignmentPoint.Z);
  2061. 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);
  2062. Vector3d acVec3d = Frompt.GetVectorTo(Topt);
  2063. tfh.TransformBy(Matrix3d.Displacement(acVec3d));
  2064. tfh.Layer = "9800";
  2065. tfh.ColorIndex = 4;
  2066. tfh.Height = 1.25 * bl;
  2067. tfh.TextStyleId = HZ;
  2068. if (bl > 4) tfh.WidthFactor = 0.75;
  2069. }
  2070. }
  2071. }
  2072. else
  2073. {
  2074. DBText tfh1 = tran.GetObject(tf[i].tfhid, OpenMode.ForWrite) as DBText;
  2075. tfh1.HorizontalMode = TextHorizontalMode.TextCenter;
  2076. tfh1.VerticalMode = TextVerticalMode.TextVerticalMid;
  2077. tfh1.AlignmentPoint = tfh1.Position;
  2078. Point3d Frompt1 = new Point3d(tfh1.AlignmentPoint.X, tfh1.AlignmentPoint.Y, tfh1.AlignmentPoint.Z);
  2079. 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);
  2080. Vector3d acVec3d1 = Frompt1.GetVectorTo(Topt1);
  2081. tfh1.TransformBy(Matrix3d.Displacement(acVec3d1));
  2082. tfh1.Layer = "9800";
  2083. tfh1.ColorIndex = 4;
  2084. tfh1.Height = 1.25 * bl;
  2085. tfh1.TextStyleId = HZ;
  2086. if (bl > 4) tfh1.WidthFactor = 0.75;
  2087. }
  2088. //pll.Erase();
  2089. tran.Commit();
  2090. }
  2091. }
  2092. List<int> delex = new List<int>();//不需要删除对应竖线的x方向错位框
  2093. List<int> deley = new List<int>();//不需要删除对应横线的y方向错位框
  2094. //如果同一列中有两个y方向错位图框,由于在y方向错位时已经进行了对应横线的
  2095. //删除,所以将序号加入列表中,不需要再删除。
  2096. for (int i = 0; i < zj_y.Count - 1; i++)
  2097. {
  2098. for (int ii = i + 1; ii < zj_y.Count; ii++)
  2099. {
  2100. if (cw_y[i].X == cw_y[ii].X)
  2101. {
  2102. deley.Add(i);
  2103. deley.Add(ii);
  2104. }
  2105. }
  2106. }
  2107. //如果同一行中有两个x方向错位图框,由于在x方向错位时已经进行了对应竖线的
  2108. //删除,所以将序号加入列表中,不需要再删除。
  2109. for (int i = 0; i < zj_x.Count - 1; i++)
  2110. {
  2111. for (int ii = i + 1; ii < zj_x.Count; ii++)
  2112. {
  2113. if (cw_x[i].Y == cw_x[ii].Y)
  2114. {
  2115. delex.Add(i);
  2116. delex.Add(ii);
  2117. }
  2118. }
  2119. }
  2120. //如果同时有x方向错位和y方向错位且在同一个角,不需要再删除
  2121. for (int i = 0; i < zj_x.Count; i++)
  2122. {
  2123. for (int ii = 0; ii < zj_y.Count; ii++)
  2124. {
  2125. if (Math.Abs(cw_x[i].X - cw_y[ii].X) > dist_l &&
  2126. Math.Abs(cw_x[i].Y - cw_y[ii].Y) > dist_l &&
  2127. !delex.Contains(i))
  2128. delex.Add(i);
  2129. else if (Math.Abs(cw_x[i].X - cw_y[ii].X) < dist_l &&
  2130. !deley.Contains(ii))
  2131. deley.Add(ii);
  2132. else if (Math.Abs(cw_x[i].Y - cw_y[ii].Y) < dist_l &&
  2133. !delex.Contains(i))
  2134. delex.Add(i);
  2135. }
  2136. }
  2137. if (zj_x.Count != 0)
  2138. {
  2139. delecentrol(doc, x, y, dist_l, dist_w, dist_nw, dist_w2jt, zj_x, delex, ptcoll, 0);
  2140. }
  2141. if (zj_y.Count != 0)
  2142. {
  2143. delecentrol(doc, x, y, dist_l, dist_w, dist_nw, dist_w2jt, zj_y, deley, ptcoll, 1);
  2144. }
  2145. //删除图框
  2146. for (int i = 0; i < tf.Count; i++)
  2147. {
  2148. using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
  2149. {
  2150. BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
  2151. BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  2152. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  2153. Point3dCollection pts = new Point3dCollection();
  2154. Polyline pll = tran.GetObject(tf[i].id, OpenMode.ForWrite) as Polyline;
  2155. pll.Erase();
  2156. if (i == tf.Count - 1)
  2157. {
  2158. LayerTable layerTable = tran.GetObject(doc.Database.LayerTableId, OpenMode.ForWrite) as LayerTable;
  2159. LayerTableRecord layer = tran.GetObject(layerTable[tc_tfh], OpenMode.ForWrite) as LayerTableRecord;
  2160. layer.Erase(true);
  2161. if (tc_tfh != tc_tk)
  2162. {
  2163. layer = tran.GetObject(layerTable[tc_tk], OpenMode.ForWrite) as LayerTableRecord;
  2164. layer.Erase(true); // 删除图层
  2165. }
  2166. }
  2167. tran.Commit();
  2168. }
  2169. }
  2170. if (x_addline.Count != 0)
  2171. {
  2172. for (int i = 0; i < x_addline.Count; i++)
  2173. {
  2174. Polyline pl = x_addline[i];
  2175. if (pl.StartPoint.X == pl.EndPoint.X)
  2176. ifneedaddline(pl, doc, dist_l, 0);
  2177. else
  2178. ifneedaddline(pl, doc, dist_w, 1);
  2179. }
  2180. }
  2181. }
  2182. /// <summary>
  2183. /// x、y方向错位竖\横线删除
  2184. /// </summary>
  2185. private void delecentrol(Document doc, double x, double y, double dist_l, double dist_w,
  2186. double dist_nw, double dist_w2jt, List<tkinfo> tk, List<int> deleindex, Point3dCollection ptcoll, int index)
  2187. {
  2188. //x方向错位竖线删除
  2189. if (index == 0)
  2190. {
  2191. for (int i = 0; i < tk.Count; i++)
  2192. {
  2193. if (deleindex.Contains(i))
  2194. continue;
  2195. using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
  2196. {
  2197. BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
  2198. BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  2199. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  2200. Point3dCollection pts = new Point3dCollection();
  2201. Polyline pll = tran.GetObject(tk[i].id, OpenMode.ForWrite) as Polyline;
  2202. double bc = pll.Length / 4.0; //边长
  2203. pll.GetStretchPoints(pts);
  2204. sortpts(pts);
  2205. double x_check = Math.Round(pts[0].X - ptcoll[3].X, 5);
  2206. double y_check = Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5);
  2207. double num_x = Math.Round(Math.Floor(x_check / bc), 3);
  2208. double num_y = Math.Round(Math.Floor(y_check / bc), 3);
  2209. Point3dCollection ptscoll = new Point3dCollection();
  2210. //右错位
  2211. if (pts[0].X > x + dist_l)
  2212. {
  2213. ptscoll.Add(new Point3d(x + dist_l, y + dist_nw + dist_w2jt + dist_w * num_y + dist_w / 2, 0));
  2214. ptscoll.Add(new Point3d(x + dist_l + 0.01, y + dist_nw + dist_w2jt + dist_w * num_y + dist_w / 2, 0));
  2215. }
  2216. //左错位
  2217. else
  2218. {
  2219. ptscoll.Add(new Point3d(x + dist_l * 2, y + dist_nw + dist_w2jt + dist_w * num_y + dist_w / 2, 0));
  2220. ptscoll.Add(new Point3d(x + dist_l * 2 + 0.01, y + dist_nw + dist_w2jt + dist_w * num_y + dist_w / 2, 0));
  2221. }
  2222. TypedValue[] value = new TypedValue[]
  2223. {
  2224. new TypedValue((int)DxfCode.LayerName,"9800"),
  2225. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  2226. };
  2227. SelectionFilter filter = new SelectionFilter(value);
  2228. dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  2229. acadApp.ZoomExtents();
  2230. PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
  2231. acadApp.ZoomPrevious();
  2232. if (psr.Status == PromptStatus.OK)
  2233. {
  2234. SelectionSet ss = psr.Value;
  2235. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  2236. Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  2237. Point3dCollection pt_break = new Point3dCollection();
  2238. DBObjectCollection obj = new DBObjectCollection();
  2239. int num = 0;
  2240. if (num_y / 2 == 0)
  2241. num = 1;
  2242. else if (num_y / 2 == 1)
  2243. num = 2;
  2244. pt_break.Add(new Point3d(pll_delete.StartPoint.X, y + dist_nw + dist_w2jt + dist_w * num, 0));
  2245. obj = pll_delete.GetSplitCurves(pt_break);
  2246. Polyline pll_delete1 = obj[0] as Polyline;
  2247. Polyline pll_delete2 = obj[1] as Polyline;
  2248. if (num == 1 && pll_delete1.StartPoint.Y == y + dist_nw + dist_w2jt ||
  2249. num == 1 && pll_delete1.EndPoint.Y == y + dist_nw + dist_w2jt)
  2250. {
  2251. pll_delete2.SetDatabaseDefaults();
  2252. btr.AppendEntity(pll_delete2);
  2253. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  2254. }
  2255. else
  2256. {
  2257. pll_delete1.SetDatabaseDefaults();
  2258. btr.AppendEntity(pll_delete1);
  2259. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  2260. }
  2261. pll_delete.Erase();
  2262. }
  2263. tran.Commit();
  2264. }
  2265. }
  2266. }
  2267. //y方向错位横线删除
  2268. if (index == 1)
  2269. {
  2270. for (int i = 0; i < tk.Count; i++)
  2271. {
  2272. if (deleindex.Contains(i))
  2273. continue;
  2274. using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
  2275. {
  2276. BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
  2277. BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  2278. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  2279. Point3dCollection pts = new Point3dCollection();
  2280. Polyline pll = tran.GetObject(tk[i].id, OpenMode.ForWrite) as Polyline;
  2281. double bc = pll.Length / 4.0; //边长
  2282. pll.GetStretchPoints(pts);
  2283. sortpts(pts);
  2284. double x_check = Math.Round(pts[0].X - ptcoll[3].X, 5);
  2285. double y_check = Math.Round(pts[0].Y - y - dist_nw - dist_w2jt, 5);
  2286. double num_x = Math.Round(Math.Floor(x_check / bc), 3);
  2287. double num_y = Math.Round(Math.Floor(y_check / bc), 3);
  2288. double y_plus = (y_check % bc) * (dist_w / bc);
  2289. Point3dCollection ptscoll = new Point3dCollection();
  2290. //下错位
  2291. if (y + dist_nw + dist_w2jt + dist_w * num_y + y_plus < y + dist_nw + dist_w2jt + dist_w)
  2292. {
  2293. ptscoll.Add(new Point3d(x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w * 2, 0));
  2294. ptscoll.Add(new Point3d(x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w * 2 + 0.01, 0));
  2295. }
  2296. //上错位
  2297. else
  2298. {
  2299. ptscoll.Add(new Point3d(x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w, 0));
  2300. ptscoll.Add(new Point3d(x + dist_l / 2, y + dist_nw + dist_w2jt + dist_w + 0.01, 0));
  2301. }
  2302. TypedValue[] value = new TypedValue[]
  2303. {
  2304. new TypedValue((int)DxfCode.LayerName,"9800"),
  2305. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  2306. };
  2307. SelectionFilter filter = new SelectionFilter(value);
  2308. dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  2309. acadApp.ZoomExtents();
  2310. PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
  2311. acadApp.ZoomPrevious();
  2312. if (psr.Status == PromptStatus.OK)
  2313. {
  2314. SelectionSet ss = psr.Value;
  2315. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  2316. Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  2317. Point3dCollection pt_break = new Point3dCollection();
  2318. DBObjectCollection obj = new DBObjectCollection();
  2319. int num = 0;
  2320. if (num_x / 2 == 0)
  2321. num = 1;
  2322. else if (num_x / 2 == 1)
  2323. num = 2;
  2324. pt_break.Add(new Point3d(x + dist_l * num, pll_delete.StartPoint.Y, 0));
  2325. obj = pll_delete.GetSplitCurves(pt_break);
  2326. Polyline pll_delete1 = obj[0] as Polyline;
  2327. Polyline pll_delete2 = obj[1] as Polyline;
  2328. if (num == 1 && pll_delete1.StartPoint.X == x ||
  2329. num == 1 && pll_delete1.EndPoint.X == x)
  2330. {
  2331. pll_delete2.SetDatabaseDefaults();
  2332. btr.AppendEntity(pll_delete2);
  2333. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  2334. }
  2335. else
  2336. {
  2337. pll_delete1.SetDatabaseDefaults();
  2338. btr.AppendEntity(pll_delete1);
  2339. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  2340. }
  2341. pll_delete.Erase();
  2342. }
  2343. tran.Commit();
  2344. }
  2345. }
  2346. }
  2347. }
  2348. /// <summary>
  2349. /// x、y方向都错位时删除对应方向的竖\横线
  2350. /// </summary>
  2351. private void sele_dele(Point3dCollection ptscoll, Editor ed, Transaction tran, double by, Point3d bk, BlockTableRecord btr)
  2352. {
  2353. TypedValue[] value = new TypedValue[]
  2354. {
  2355. new TypedValue((int)DxfCode.LayerName,"9800"),
  2356. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  2357. };
  2358. SelectionFilter filter = new SelectionFilter(value);
  2359. dynamic acadApp = GrxCAD.ApplicationServices.Application.AcadApplication;
  2360. acadApp.ZoomExtents();
  2361. PromptSelectionResult psr = ed.SelectFence(ptscoll, filter);
  2362. acadApp.ZoomPrevious();
  2363. if (psr.Status == PromptStatus.OK)
  2364. {
  2365. SelectionSet ss = psr.Value;
  2366. ObjectIdCollection idcoll = new ObjectIdCollection(ss.GetObjectIds());
  2367. Polyline pll_delete = tran.GetObject(idcoll[0], OpenMode.ForWrite) as Polyline;
  2368. Point3dCollection pt_break = new Point3dCollection();
  2369. DBObjectCollection obj = new DBObjectCollection();
  2370. pt_break.Add(bk);
  2371. obj = pll_delete.GetSplitCurves(pt_break);
  2372. Polyline pll_delete1 = obj[0] as Polyline;
  2373. Polyline pll_delete2 = obj[1] as Polyline;
  2374. if (pll_delete1.StartPoint.X == by ||
  2375. pll_delete1.EndPoint.X == by)
  2376. {
  2377. pll_delete2.SetDatabaseDefaults();
  2378. btr.AppendEntity(pll_delete2);
  2379. tran.AddNewlyCreatedDBObject(pll_delete2, true);
  2380. }
  2381. else
  2382. {
  2383. pll_delete1.SetDatabaseDefaults();
  2384. btr.AppendEntity(pll_delete1);
  2385. tran.AddNewlyCreatedDBObject(pll_delete1, true);
  2386. }
  2387. pll_delete.Erase();
  2388. }
  2389. }
  2390. private void ifneedaddline(Polyline pl, Document doc, double length,int index)
  2391. {
  2392. bool flag1 = false;
  2393. bool flag2 = false;
  2394. length = length + 0.1;
  2395. Editor ed = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  2396. if (index == 0)
  2397. {
  2398. double y = Math.Min(pl.StartPoint.Y, pl.EndPoint.Y) + Math.Abs(pl.StartPoint.Y - pl.EndPoint.Y) / 2;
  2399. Point3dCollection ptcol1 = new Point3dCollection();
  2400. ptcol1.Add(new Point3d(pl.StartPoint.X, y, 0));
  2401. ptcol1.Add(new Point3d(pl.StartPoint.X + length, y, 0));
  2402. Point3dCollection ptcol2 = new Point3dCollection();
  2403. ptcol2.Add(new Point3d(pl.StartPoint.X, y, 0));
  2404. ptcol2.Add(new Point3d(pl.StartPoint.X - length, y, 0));
  2405. TypedValue[] value = new TypedValue[]
  2406. {
  2407. new TypedValue((int)DxfCode.LayerName,"9800"),
  2408. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  2409. };
  2410. SelectionFilter filter = new SelectionFilter(value);
  2411. PromptSelectionResult psr1 = ed.SelectFence(ptcol1, filter);
  2412. PromptSelectionResult psr2 = ed.SelectFence(ptcol2, filter);
  2413. ObjectIdCollection idcoll1 = new ObjectIdCollection();
  2414. ObjectIdCollection idcoll2 = new ObjectIdCollection();
  2415. if (psr1.Status == PromptStatus.OK)
  2416. {
  2417. SelectionSet ss = psr1.Value;
  2418. idcoll1 = new ObjectIdCollection(ss.GetObjectIds());
  2419. }
  2420. if (psr2.Status == PromptStatus.OK)
  2421. {
  2422. SelectionSet ss = psr2.Value;
  2423. idcoll2 = new ObjectIdCollection(ss.GetObjectIds());
  2424. }
  2425. using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
  2426. {
  2427. BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
  2428. BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  2429. for (int i = 0; i < idcoll1.Count; i++)
  2430. {
  2431. Polyline neighbpl = tran.GetObject(idcoll1[i], OpenMode.ForRead) as Polyline;
  2432. if (Math.Round(neighbpl.StartPoint.X, 4) == Math.Round(neighbpl.EndPoint.X, 4)&& idcoll1[i]!=pl.ObjectId)
  2433. {
  2434. flag1 = true;
  2435. break;
  2436. }
  2437. }
  2438. if(flag1==false)
  2439. {
  2440. Polyline ad_pl1 = new Polyline();
  2441. ad_pl1.AddVertexAt(0, new Point2d(pl.StartPoint.X + length, pl.StartPoint.Y), 0, 0, 0);
  2442. ad_pl1.AddVertexAt(1, new Point2d(pl.StartPoint.X + length, pl.EndPoint.Y), 0, 0, 0);
  2443. ad_pl1.Layer = "9800";
  2444. ad_pl1.Linetype = "Bylayer";
  2445. ad_pl1.SetDatabaseDefaults();
  2446. btr.AppendEntity(ad_pl1);
  2447. tran.AddNewlyCreatedDBObject(ad_pl1, true);
  2448. }
  2449. for (int i = 0; i < idcoll2.Count; i++)
  2450. {
  2451. Polyline neighbpl = tran.GetObject(idcoll2[i], OpenMode.ForRead) as Polyline;
  2452. if (Math.Round(neighbpl.StartPoint.X, 4) == Math.Round(neighbpl.EndPoint.X, 4) && idcoll2[i] != pl.ObjectId)
  2453. {
  2454. flag2 = true;
  2455. break;
  2456. }
  2457. }
  2458. if (flag2==false)
  2459. {
  2460. Polyline ad_pl2 = new Polyline();
  2461. ad_pl2.AddVertexAt(0, new Point2d(pl.StartPoint.X - length, pl.StartPoint.Y), 0, 0, 0);
  2462. ad_pl2.AddVertexAt(1, new Point2d(pl.StartPoint.X - length, pl.EndPoint.Y), 0, 0, 0);
  2463. ad_pl2.Layer = "9800";
  2464. ad_pl2.Linetype = "Bylayer";
  2465. ad_pl2.SetDatabaseDefaults();
  2466. btr.AppendEntity(ad_pl2);
  2467. tran.AddNewlyCreatedDBObject(ad_pl2, true);
  2468. }
  2469. tran.Commit();
  2470. }
  2471. }
  2472. if (index == 1)
  2473. {
  2474. double x = Math.Min(pl.StartPoint.X, pl.EndPoint.X) + Math.Abs(pl.StartPoint.X - pl.EndPoint.X) / 2;
  2475. Point3dCollection ptcol1 = new Point3dCollection();
  2476. ptcol1.Add(new Point3d(x, pl.StartPoint.Y, 0));
  2477. ptcol1.Add(new Point3d(x, pl.StartPoint.Y + length, 0));
  2478. Point3dCollection ptcol2 = new Point3dCollection();
  2479. ptcol2.Add(new Point3d(x, pl.StartPoint.Y, 0));
  2480. ptcol2.Add(new Point3d(x, pl.StartPoint.Y - length, 0));
  2481. TypedValue[] value = new TypedValue[]
  2482. {
  2483. new TypedValue((int)DxfCode.LayerName,"9800"),
  2484. new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE")
  2485. };
  2486. SelectionFilter filter = new SelectionFilter(value);
  2487. PromptSelectionResult psr1 = ed.SelectFence(ptcol1, filter);
  2488. PromptSelectionResult psr2 = ed.SelectFence(ptcol2, filter);
  2489. ObjectIdCollection idcoll1 = new ObjectIdCollection();
  2490. ObjectIdCollection idcoll2 = new ObjectIdCollection();
  2491. if (psr1.Status == PromptStatus.OK)
  2492. {
  2493. SelectionSet ss = psr1.Value;
  2494. idcoll1 = new ObjectIdCollection(ss.GetObjectIds());
  2495. }
  2496. if (psr2.Status == PromptStatus.OK)
  2497. {
  2498. SelectionSet ss = psr2.Value;
  2499. idcoll2 = new ObjectIdCollection(ss.GetObjectIds());
  2500. }
  2501. using (Transaction tran = doc.Database.TransactionManager.StartTransaction())
  2502. {
  2503. BlockTable bt = (BlockTable)tran.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
  2504. BlockTableRecord btr = (BlockTableRecord)tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  2505. for (int i = 0; i < idcoll1.Count; i++)
  2506. {
  2507. Polyline neighbpl = tran.GetObject(idcoll1[i], OpenMode.ForRead) as Polyline;
  2508. if (Math.Round(neighbpl.StartPoint.Y, 4) == Math.Round(neighbpl.EndPoint.Y, 4) && idcoll1[i] != pl.ObjectId)
  2509. {
  2510. flag1 = true;
  2511. break;
  2512. }
  2513. }
  2514. if (flag1 == false)
  2515. {
  2516. Polyline ad_pl1 = new Polyline();
  2517. ad_pl1.AddVertexAt(0, new Point2d(pl.StartPoint.X, pl.StartPoint.Y + length), 0, 0, 0);
  2518. ad_pl1.AddVertexAt(1, new Point2d(pl.EndPoint.X, pl.EndPoint.Y + length), 0, 0, 0);
  2519. ad_pl1.Layer = "9800";
  2520. ad_pl1.Linetype = "Bylayer";
  2521. ad_pl1.SetDatabaseDefaults();
  2522. btr.AppendEntity(ad_pl1);
  2523. tran.AddNewlyCreatedDBObject(ad_pl1, true);
  2524. }
  2525. for (int i = 0; i < idcoll2.Count; i++)
  2526. {
  2527. Polyline neighbpl = tran.GetObject(idcoll2[i], OpenMode.ForRead) as Polyline;
  2528. if (Math.Round(neighbpl.StartPoint.Y, 4) == Math.Round(neighbpl.EndPoint.Y, 4) && idcoll2[i] != pl.ObjectId)
  2529. {
  2530. flag2 = true;
  2531. break;
  2532. }
  2533. }
  2534. if (flag2 == false)
  2535. {
  2536. Polyline ad_pl2 = new Polyline();
  2537. ad_pl2.AddVertexAt(0, new Point2d(pl.StartPoint.X, pl.StartPoint.Y - length), 0, 0, 0);
  2538. ad_pl2.AddVertexAt(1, new Point2d(pl.StartPoint.X, pl.EndPoint.Y - length), 0, 0, 0);
  2539. ad_pl2.Layer = "9800";
  2540. ad_pl2.Linetype = "Bylayer";
  2541. ad_pl2.SetDatabaseDefaults();
  2542. btr.AppendEntity(ad_pl2);
  2543. tran.AddNewlyCreatedDBObject(ad_pl2, true);
  2544. }
  2545. tran.Commit();
  2546. }
  2547. }
  2548. }
  2549. public ObjectId createTextStyle(Document doc)
  2550. {
  2551. Database database = doc.Database;
  2552. ObjectId textstyleID = new ObjectId();
  2553. string stylename = "HZ";
  2554. using (Transaction traction = database.TransactionManager.StartTransaction())
  2555. {
  2556. TextStyleTable styletable = traction.GetObject(database.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
  2557. if (styletable.Has(stylename) == false)
  2558. {
  2559. TextStyleTableRecord R1 = new TextStyleTableRecord();
  2560. R1.Name = stylename;
  2561. //R1.FileName = "方正细等线简体";
  2562. R1.FileName = "rs.shx";
  2563. R1.BigFontFileName = "hztxt.shx";
  2564. R1.ObliquingAngle = 0;
  2565. R1.XScale = 1;
  2566. //textstyleID = styletable.Add(R1);
  2567. traction.AddNewlyCreatedDBObject(R1, true);
  2568. //database.TextStyleId = textstyleID;
  2569. }
  2570. traction.Commit();
  2571. }
  2572. using (Transaction traction = database.TransactionManager.StartTransaction())
  2573. {
  2574. TextStyleTable styletable = traction.GetObject(database.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
  2575. TextStyleTableRecord record = traction.GetObject(styletable[stylename], OpenMode.ForRead) as TextStyleTableRecord;
  2576. textstyleID = record.ObjectId;
  2577. traction.Commit();
  2578. }
  2579. return textstyleID;
  2580. }
  2581. }
  2582. }