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