工具箱相关
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using GrxCAD.ApplicationServices;
  7. using GrxCAD.DatabaseServices;
  8. using GrxCAD.EditorInput;
  9. using GrxCAD.Geometry;
  10. namespace HCTools
  11. {
  12. class Inters
  13. {
  14. public static int blc;//比例尺
  15. public static string jqx;
  16. public static string sqx;
  17. //由于AUTOCAD的IntersectWith()函数在实体离开原点过远的情况下精确度会大幅下降,
  18. //在进行相交检查时需要将待检查的实体都添加到一个块中,移动块到原点再进行检查,
  19. //将检查后的标记也添加到块中,检查完后移动回原位。
  20. #region 线自相交
  21. public void SelfInts()
  22. {
  23. double flagradius = 4.0 * blc / 1000;//画圆标记半径
  24. string layername = jqx + "," + sqx;
  25. Document doc = Application.DocumentManager.MdiActiveDocument;
  26. Database db = doc.Database;
  27. Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  28. TypedValue[] value = new TypedValue[]
  29. {
  30. new TypedValue((int)DxfCode.LayerName,layername),
  31. new TypedValue((int)DxfCode.Start,"LWPOLYLINE")
  32. };//设置筛选条件
  33. SelectionFilter filter = new SelectionFilter(value);//选择区域中全部对象
  34. //PromptSelectionResult psr = ed.SelectAll(filter);// 要求在图形区域中手动选择对象
  35. PromptSelectionResult psr = ed.GetSelection(filter);
  36. if (psr.Status == PromptStatus.OK)
  37. {
  38. Point3dCollection intersectPts = new Point3dCollection();
  39. int j = 0;
  40. SelectionSet ss = psr.Value;
  41. if (ss == null)
  42. return;
  43. //创建标注相交点符号的图层
  44. LayerControl layerscontrol = new LayerControl();
  45. string layname = "线自相交点";
  46. if (!layerscontrol.haslayername(layname))
  47. {
  48. colorgb col = new colorgb(255, 0, 255);
  49. layerscontrol.creatlayer(layname, col);
  50. layerscontrol.movelayertofront(layname);
  51. }
  52. else
  53. layerscontrol.movelayertofront(layname);
  54. ObjectIdCollection idcoll1 = new ObjectIdCollection(ss.GetObjectIds());//需要添加到块中的实体
  55. ObjectIdCollection idcoll2 = new ObjectIdCollection();//explode后重新添加到数据库的实体
  56. ObjectIdCollection idcoll3 = new ObjectIdCollection();//添加标记后实体
  57. Point3d MoveToPt = new Point3d(0, 0, 0);//目标点
  58. Point3d SelfPt = new Point3d();//基点
  59. //将选中多段线添加到块中并移动
  60. DBObjectCollection objcoll = MovebyBlock(idcoll1, out SelfPt, MoveToPt);
  61. //将explode之后的实体重新添加到数据库中并检查是否自相交
  62. foreach (Polyline ent in objcoll)
  63. {
  64. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  65. using (Transaction trans = db.TransactionManager.StartTransaction())
  66. {
  67. BlockTable blocktable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
  68. BlockTableRecord blocktablerecord = trans.GetObject(blocktable[BlockTableRecord.ModelSpace],
  69. OpenMode.ForWrite) as BlockTableRecord;
  70. blocktablerecord.AppendEntity(ent);
  71. trans.AddNewlyCreatedDBObject(ent, true);
  72. idcoll2.Add(ent.Id);
  73. trans.Commit();
  74. }
  75. doclock.Dispose();
  76. }
  77. for(int i =0;i<idcoll2.Count;i++)
  78. {
  79. Polyline pll = BasicFunction.GetDBObject(idcoll2[i]) as Polyline;
  80. SelfIntersectDetect(pll, out intersectPts);
  81. idcoll3.Add(idcoll2[i]);
  82. if (intersectPts.Count != 0)
  83. {
  84. j += intersectPts.Count;
  85. foreach (Point3d pt in intersectPts)
  86. {
  87. Makeflag(pt.X, pt.Y, pt.Z, flagradius, "线自相交点", idcoll3);
  88. }
  89. }
  90. else
  91. continue;
  92. }
  93. //将检查后的所有实体添加到块中并移动
  94. Point3d Self = new Point3d();
  95. Point3d MoveTo = SelfPt;
  96. DBObjectCollection objcoll1 = MovebyBlock(idcoll3, out Self, MoveTo);
  97. //将explode之后的实体添加到数据库中
  98. foreach (Entity ent in objcoll1)
  99. {
  100. ObjectIdCollection idcoll = new ObjectIdCollection();
  101. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  102. using (Transaction trans = db.TransactionManager.StartTransaction())
  103. {
  104. BlockTable blocktable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
  105. BlockTableRecord blocktablerecord = trans.GetObject(blocktable[BlockTableRecord.ModelSpace],
  106. OpenMode.ForWrite) as BlockTableRecord;
  107. blocktablerecord.AppendEntity(ent);
  108. trans.AddNewlyCreatedDBObject(ent, true);
  109. DrawOrderTable orderTable = trans.GetObject(blocktablerecord.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;
  110. idcoll.Add(ent.Id);
  111. orderTable.MoveToBottom(idcoll);
  112. trans.Commit();
  113. }
  114. doclock.Dispose();
  115. }
  116. ed.WriteMessage("有" + j.ToString() + "个交点");
  117. }
  118. }
  119. /// <summary>
  120. /// 线自相交检查
  121. /// </summary>
  122. private static bool SelfIntersectDetect(Polyline pPolyline, out Point3dCollection intersectPoint3Ds)
  123. {
  124. intersectPoint3Ds = new Point3dCollection();
  125. try
  126. {
  127. // 自身与自身相交结果(包含顶点和相交点)
  128. var intersectWithResult = new Point3dCollection();
  129. //pPolyline.IntersectWith(pPolyline, Intersect.OnBothOperands, intersectWithResult, IntPtr.Zero, IntPtr.Zero);
  130. // 存储顶点
  131. List<Point3d> vertices = new List<Point3d>();
  132. int count = pPolyline.NumberOfVertices;
  133. for (int j = 0; j < count; j++)
  134. {
  135. Point3d pt = pPolyline.GetPoint3dAt(j);
  136. //Point3d pt1 = new Point3d(Math.Round(pt.X, 6), Math.Round(pt.Y, 6), Math.Round(pt.Z, 6));
  137. vertices.Add(pt);
  138. }
  139. for (int i = 0; i < count - 2; i++)
  140. {
  141. LineSegment3d lsgment0 = pPolyline.GetLineSegmentAt(i);
  142. for (int ii = i + 1; ii < count - 1; ii++)
  143. {
  144. LineSegment3d lsgment1 = pPolyline.GetLineSegmentAt(ii);
  145. Point3d[] itpt = lsgment0.IntersectWith(lsgment1);
  146. if (itpt != null)
  147. {
  148. foreach (Point3d pt in itpt)
  149. {
  150. intersectWithResult.Add(pt);
  151. }
  152. }
  153. }
  154. if (i == 0)
  155. {
  156. if (intersectWithResult.Count > 1)
  157. {
  158. for (int j = 0; j < intersectWithResult.Count - 1; j++)
  159. {
  160. for (int jj = j + 1; jj < intersectWithResult.Count; jj++)
  161. {
  162. if (intersectWithResult[j] == intersectWithResult[jj]&&
  163. !intersectPoint3Ds.Contains(intersectWithResult[jj]))
  164. {
  165. intersectPoint3Ds.Add(intersectWithResult[jj]);
  166. }
  167. }
  168. }
  169. foreach (Point3d pt in intersectWithResult)
  170. {
  171. if (pt == vertices[1])
  172. continue;
  173. else
  174. {
  175. if(!intersectPoint3Ds.Contains(pt))
  176. intersectPoint3Ds.Add(pt);
  177. }
  178. }
  179. }
  180. }
  181. else if (i == count - 3)
  182. {
  183. if (intersectWithResult.Count > 1)
  184. {
  185. for (int j = 0; j < intersectWithResult.Count - 1; j++)
  186. {
  187. for (int jj = j + 1; jj < intersectWithResult.Count; jj++)
  188. {
  189. if (intersectWithResult[j] == intersectWithResult[jj] &&
  190. !intersectPoint3Ds.Contains(intersectWithResult[jj]))
  191. {
  192. intersectPoint3Ds.Add(intersectWithResult[jj]);
  193. }
  194. }
  195. }
  196. foreach (Point3d pt in intersectWithResult)
  197. {
  198. if (pt == vertices[i])
  199. continue;
  200. else
  201. {
  202. if (!intersectPoint3Ds.Contains(pt))
  203. intersectPoint3Ds.Add(pt);
  204. }
  205. }
  206. }
  207. }
  208. else
  209. {
  210. if (intersectWithResult.Count > 1)
  211. {
  212. for (int j = 0; j < intersectWithResult.Count - 1; j++)
  213. {
  214. for (int jj = j + 1; jj < intersectWithResult.Count; jj++)
  215. {
  216. if (intersectWithResult[j] == intersectWithResult[jj] &&
  217. !intersectPoint3Ds.Contains(intersectWithResult[jj]))
  218. {
  219. intersectPoint3Ds.Add(intersectWithResult[jj]);
  220. }
  221. }
  222. }
  223. foreach (Point3d pt in intersectWithResult)
  224. {
  225. if (pt == vertices[i]||pt == vertices[i + 1])
  226. continue;
  227. else
  228. {
  229. if (!intersectPoint3Ds.Contains(pt))
  230. intersectPoint3Ds.Add(pt);
  231. }
  232. }
  233. }
  234. }
  235. intersectWithResult.Clear();
  236. }
  237. return true;
  238. }
  239. catch (Exception ex)
  240. {
  241. string str = ex.ToString();
  242. Application.ShowAlertDialog(str);
  243. return false;
  244. }
  245. }
  246. #endregion
  247. #region 线相交
  248. public void Ints()
  249. {
  250. double flagradius = 4.0 * blc / 1000;//画圆标记半径
  251. Document doc = Application.DocumentManager.MdiActiveDocument;
  252. Database db = doc.Database;
  253. Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  254. string layername = jqx + "," + sqx;
  255. TypedValue[] value = new TypedValue[]
  256. {
  257. new TypedValue((int)DxfCode.LayerName,layername),
  258. new TypedValue((int)DxfCode.Start,"LWPOLYLINE")
  259. };//设置筛选条件
  260. SelectionFilter filter = new SelectionFilter(value);//选择区域中全部对象
  261. //PromptSelectionResult psr = ed.SelectAll(filter);// 要求在图形区域中手动选择对象
  262. PromptSelectionResult psr = ed.GetSelection(filter);
  263. if (psr.Status == PromptStatus.OK)
  264. {
  265. List<Point3d> intersectPts = new List<Point3d>();
  266. int j = 0;
  267. SelectionSet ss = psr.Value;
  268. if (ss == null)
  269. return;
  270. //创建标注相交点符号的图层
  271. LayerControl layerscontrol = new LayerControl();
  272. string layname = "线相交点";
  273. if (!layerscontrol.haslayername(layname))
  274. {
  275. colorgb col = new colorgb(0, 0, 255);
  276. layerscontrol.creatlayer(layname, col);
  277. layerscontrol.movelayertofront(layname);
  278. }
  279. else
  280. layerscontrol.movelayertofront(layname);
  281. ObjectIdCollection idcoll1 = new ObjectIdCollection(ss.GetObjectIds());//需要添加到块中的实体
  282. ObjectIdCollection idcoll2 = new ObjectIdCollection();//explode之后的实体
  283. Point3d MoveToPt = new Point3d(0, 0, 0);//目标点
  284. Point3d SelfPt = new Point3d();//基点
  285. //将选中多段线添加到块中并移动
  286. DBObjectCollection objcoll = MovebyBlock(idcoll1, out SelfPt, MoveToPt);
  287. //将explode之后的实体重新添加到数据库中
  288. foreach (Entity ent in objcoll)
  289. {
  290. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  291. using (Transaction trans = db.TransactionManager.StartTransaction())
  292. {
  293. BlockTable blocktable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
  294. BlockTableRecord blocktablerecord = trans.GetObject(blocktable[BlockTableRecord.ModelSpace],
  295. OpenMode.ForWrite) as BlockTableRecord;
  296. blocktablerecord.AppendEntity(ent);
  297. trans.AddNewlyCreatedDBObject(ent, true);
  298. idcoll2.Add(ent.Id);
  299. trans.Commit();
  300. }
  301. doclock.Dispose();
  302. }
  303. #region//检查线相交情况
  304. ////检查线相交情况
  305. //int num = 0;
  306. //int numb = 0;//记录无法判断的实体数量
  307. //ObjectIdCollection objidcoll_check = new ObjectIdCollection();
  308. //List<Point3d> interpoint = new List<Point3d>();
  309. //for (int i = 0; i < objcoll.Count; i++)
  310. //{
  311. // DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  312. // using (Transaction trans = db.TransactionManager.StartTransaction())
  313. // {
  314. // Polyline pll1 = trans.GetObject(objcoll[i].Id, OpenMode.ForWrite) as Polyline;
  315. // ObjectIdCollection pllids = GetIntersectPlline(pll1,out num);//获取附近多段线
  316. // numb = numb + num;
  317. // //根据获取的多段线进行相交检查
  318. // for (int ii = 0; ii < pllids.Count; ii++)
  319. // {
  320. // if (objidcoll_check.Contains(pllids[ii]))
  321. // continue;
  322. // Polyline pll2 = trans.GetObject(pllids[ii], OpenMode.ForWrite) as Polyline;
  323. // EachIntersect(pll1, pll2, out intersectPts);
  324. // foreach (Point3d pt in intersectPts)
  325. // {
  326. // interpoint.Add(pt);
  327. // }
  328. // }
  329. // if (intersectPts.Count != 0)
  330. // objidcoll_check.Add(objcoll[i].Id);
  331. // trans.Commit();
  332. // doclock.Dispose();
  333. // }
  334. //}
  335. #endregion
  336. //检查线相交情况
  337. ObjectIdCollection objidcoll_check = new ObjectIdCollection();
  338. List<Point3d> interpoint = new List<Point3d>();
  339. for (int i = 0; i < objcoll.Count - 1; i++)
  340. {
  341. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  342. using (Transaction trans = db.TransactionManager.StartTransaction())
  343. {
  344. Polyline pll1 = trans.GetObject(objcoll[i].Id, OpenMode.ForWrite) as Polyline;
  345. for (int ii = i + 1; ii < objcoll.Count; ii++)
  346. {
  347. Polyline pll2 = trans.GetObject(objcoll[ii].Id, OpenMode.ForWrite) as Polyline;
  348. EachIntersect(pll1, pll2, out intersectPts);
  349. foreach (Point3d pt in intersectPts)
  350. {
  351. interpoint.Add(pt);
  352. }
  353. }
  354. if (intersectPts.Count != 0)
  355. objidcoll_check.Add(objcoll[i].Id);
  356. trans.Commit();
  357. doclock.Dispose();
  358. }
  359. if (interpoint.Count != 0)
  360. {
  361. j = interpoint.Count;
  362. foreach (Point3d pt in interpoint)
  363. {
  364. Makeflag(pt.X, pt.Y, pt.Z, flagradius, "线相交点", idcoll2);
  365. }
  366. }
  367. }
  368. //将检查后的实体都添加到块中并移动
  369. Point3d Self = new Point3d();
  370. Point3d MoveTo = SelfPt;
  371. DBObjectCollection objcoll1 = MovebyBlock(idcoll2, out Self, MoveTo);
  372. //将explode之后的实体添加到数据库中
  373. foreach (Entity ent in objcoll1)
  374. {
  375. ObjectIdCollection idcoll = new ObjectIdCollection();
  376. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  377. using (Transaction trans = db.TransactionManager.StartTransaction())
  378. {
  379. BlockTable blocktable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
  380. BlockTableRecord blocktablerecord = trans.GetObject(blocktable[BlockTableRecord.ModelSpace],
  381. OpenMode.ForWrite) as BlockTableRecord;
  382. blocktablerecord.AppendEntity(ent);
  383. trans.AddNewlyCreatedDBObject(ent, true);
  384. DrawOrderTable orderTable = trans.GetObject(blocktablerecord.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;
  385. idcoll.Add(ent.Id);
  386. orderTable.MoveToBottom(idcoll);
  387. trans.Commit();
  388. }
  389. doclock.Dispose();
  390. }
  391. ed.WriteMessage("有" + j.ToString() + "个交点");
  392. //ed.WriteMessage("\n有" + numb.ToString() + "处无法判断");
  393. }
  394. }
  395. /// <summary>
  396. /// 获取附近多段线
  397. /// </summary>
  398. private static ObjectIdCollection GetIntersectPlline(Polyline pll, out int num)
  399. {
  400. num = 0;
  401. ObjectIdCollection objidcoll = new ObjectIdCollection();
  402. DBObjectCollection objcoll = new DBObjectCollection();
  403. Editor editor = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  404. Point3dCollection ptcoll = new Point3dCollection();
  405. //检查是否有相交线
  406. pll.GetStretchPoints(ptcoll);
  407. TypedValue[] vl = new TypedValue[]
  408. {
  409. new TypedValue((int)DxfCode.LayerName,"8110,8120"),
  410. new TypedValue((int)DxfCode.Start,"LWPOLYLINE")
  411. };//设置筛选条件
  412. SelectionFilter selefilter = new SelectionFilter(vl);//选择区域中全部对象
  413. //PromptSelectionResult psr = ed.SelectAll(filter);// 要求在图形区域中手动选择对象
  414. //SelectFence()无法找到不在当前视图的实体,需要将视图转移到实体所在的位置
  415. dynamic acadApp = Application.AcadApplication;
  416. acadApp.ZoomExtents();
  417. PromptSelectionResult seleresult = editor.SelectFence(ptcoll, selefilter);
  418. acadApp.ZoomPrevious();
  419. if (seleresult.Status == PromptStatus.OK)
  420. {
  421. SelectionSet selectionset = seleresult.Value;
  422. objidcoll = new ObjectIdCollection(selectionset.GetObjectIds());
  423. if (objidcoll.Contains(pll.Id))
  424. objidcoll.Remove(pll.Id);
  425. }
  426. return objidcoll;
  427. }
  428. /// <summary>
  429. /// 线相交检查
  430. /// </summary>
  431. private static bool EachIntersect(Polyline oPolyline, Polyline tPolyline, out List<Point3d> intersectPoint3Ds)
  432. {
  433. intersectPoint3Ds = new List<Point3d>();
  434. try
  435. {
  436. //两线相交结果
  437. var intersectWithResult = new Point3dCollection();
  438. double temp = oPolyline.Elevation;
  439. oPolyline.Elevation = tPolyline.Elevation;
  440. oPolyline.IntersectWith(tPolyline, Intersect.OnBothOperands, intersectWithResult, IntPtr.Zero, IntPtr.Zero);
  441. if (intersectWithResult.Count!=0)
  442. {
  443. for (int i = 0; i < intersectWithResult.Count; i++)
  444. intersectPoint3Ds.Add(intersectWithResult[i]);
  445. }
  446. oPolyline.Elevation = temp;
  447. return true;
  448. }
  449. catch (Exception ex)
  450. {
  451. string str = ex.ToString();
  452. Application.ShowAlertDialog(str);
  453. return false;
  454. }
  455. }
  456. #endregion
  457. /// <summary>
  458. /// 将多段线添加到块后将块移动到目标位置并explode
  459. /// </summary>
  460. private static DBObjectCollection MovebyBlock(ObjectIdCollection idcoll, out Point3d SelfPt, Point3d MoveToPt)
  461. {
  462. Document doc = Application.DocumentManager.MdiActiveDocument;
  463. Database db = doc.Database;
  464. DBObjectCollection objcoll = new DBObjectCollection();//explode后的实体
  465. ObjectId btrid = new ObjectId();//块id
  466. DocumentLock documentlock1 = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  467. using (Transaction trans = db.TransactionManager.StartTransaction())
  468. {
  469. BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
  470. BlockTableRecord btr = new BlockTableRecord();
  471. Polyline pll = trans.GetObject(idcoll[0], OpenMode.ForRead) as Polyline;
  472. btr.Name = "BLK";
  473. bt.UpgradeOpen();
  474. btrid = bt.Add(btr);
  475. trans.AddNewlyCreatedDBObject(btr, true);
  476. btr.AssumeOwnershipOf(idcoll);
  477. btr.Origin = pll.StartPoint;
  478. SelfPt = pll.StartPoint;
  479. BlockTableRecord ms = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
  480. BlockReference br = new BlockReference(pll.StartPoint, btrid);
  481. Vector3d acVec3d = SelfPt.GetVectorTo(MoveToPt);
  482. br.TransformBy(Matrix3d.Displacement(acVec3d));
  483. ms.AppendEntity(br);
  484. trans.AddNewlyCreatedDBObject(br, true);
  485. br.Explode(objcoll);
  486. btr.UpgradeOpen();
  487. btr.Erase();
  488. trans.Commit();
  489. }
  490. documentlock1.Dispose();
  491. return objcoll;
  492. }
  493. /// <summary>
  494. /// 错误标记
  495. /// </summary>
  496. private void Makeflag(double x, double y, double z, double radius, string layername, ObjectIdCollection idcoll)
  497. {
  498. Database database = HostApplicationServices.WorkingDatabase;
  499. DocumentLock doclock = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
  500. using (Transaction traction = database.TransactionManager.StartTransaction())
  501. {
  502. BlockTable blocktable = traction.GetObject(database.BlockTableId,OpenMode.ForWrite) as BlockTable;
  503. BlockTableRecord blocktablerecord = traction.GetObject(blocktable[BlockTableRecord.ModelSpace],
  504. OpenMode.ForWrite) as BlockTableRecord;
  505. Circle circ = new Circle();
  506. circ.Center = new Point3d(x, y, z);
  507. circ.Radius = radius;
  508. circ.Normal = new Vector3d(0, 0, 1);
  509. circ.SetDatabaseDefaults();
  510. circ.Layer = layername;
  511. blocktablerecord.AppendEntity(circ);
  512. traction.AddNewlyCreatedDBObject(circ, true);
  513. idcoll.Add(circ.Id);
  514. traction.Commit();
  515. //traction.Dispose();
  516. }
  517. doclock.Dispose();
  518. }
  519. }
  520. }