[原创]用户圈选LINE实体,并获得所有LINE相交的交点坐标
<p>用户圈选LINE实体<br/>时进行层过滤·实体过滤,并获得所有LINE相交的交点坐标点以坐标点为中心画柱子<br/></p><p></p><p>#region 圈选方式画柱子<br/><br/>public static void SelectingCreatePillar2()<br/>{</p><p>Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; <br/>Editor ed = doc.Editor;<br/>Database db = doc.Database;</p><p>//TypedValue filterValue1 = new TypedValue((int)DxfCode.Start, "Line");//实体类型过滤<br/>TypedValue filterValue3 = new TypedValue((int)DxfCode.LayerName, "ArxLayer");//层过滤 <br/>TypedValue[] filterValues1 = {filterValue1, filterValue3 };<br/>SelectionFilter filter2 = new SelectionFilter(filterValues1);<br/>PromptSelectionResult psr1 = ed.GetSelection(filter2);<br/>Point3dCollection pts = new Point3dCollection(); //交点集合</p><p>if (psr1.Status == PromptStatus.OK || psr1.Value.Count != 0)<br/>{</p><p>using (Transaction trans = db.TransactionManager.StartTransaction())<br/>{</p><p>BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);</p><p>BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead);</p><p>List<Line> lstLine = new List<Line>();</p><p>//遍历选择集<br/>foreach (ObjectId BlockId in psr1.Value.GetObjectIds())<br/>{<br/>//获取选择集里块里面的对象<br/>BlockReference BlockObject = trans.GetObject(BlockId, OpenMode.ForRead) as BlockReference;<br/>BlockTableRecord btrBlock = trans.GetObject(BlockObject.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;</p><p>//遍历块选择集<br/>foreach (ObjectId BlcokId in btrBlock)<br/>{<br/>//创建实体用来存储ObjectID获得的实体<br/>Entity BlockEntity = trans.GetObject(BlcokId, OpenMode.ForRead) as Entity;</p><p>//判断实体的类型是否是Line<br/>if (BlockEntity.GetType() == typeof(Line))<br/>{<br/>Line pl = BlockEntity as Line;<br/>//pl.IntersectWith(pl1, Intersect.OnBothOperands, pts, 0, 0);<br/>lstLine.Add(pl);<br/>}<br/>} </p><p>}<br/>//循环遍历所有实体进行一个一个比配<br/>for(int i=0;i<lstLine.Count;i++)<br/>{<br/>Line li=lstLine;<br/>for(int j=i+1;j<lstLine.Count;j++)<br/>{<br/>Line pl1=lstLine;<br/>//把LINE比配的交点存入pts集合中<br/>li.IntersectWith(pl1, Intersect.OnBothOperands, pts, 0, 0);<br/>}<br/>}</p><p>//开始遍历循环存交点的集合并取出交点<br/>if (pts.Count > 0)<br/>{</p><p>for (int i = 0; i < pts.Count; i++)<br/>{<br/>Point3d p3d = new Point3d();<br/>p3d = pts;//交点<br/>//调用画柱子方法,以交点为中心点画柱子<br/>DrawPillarMethod.DrawTrangle(p3d, "juxing", "800", "700", false);<br/>}<br/>}</p><p>//提交事务<br/>trans.Commit(); <br/>}<br/>}<br/>else <br/>{<br/>MessageBox.Show("你没有选中任何实体");<br/>}</p><p>}<br/>#endregion</p>
页:
[1]