明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1785|回复: 1

[原创]用户圈选LINE实体,并获得所有LINE相交的交点坐标

[复制链接]
发表于 2009-12-9 18:00 | 显示全部楼层 |阅读模式

用户圈选LINE实体
时进行层过滤·实体过滤,并获得所有LINE相交的交点坐标点以坐标点为中心画柱子

#region 圈选方式画柱子
[CommandMethod("SelectingCreatePillar2")]
public static void SelectingCreatePillar2()
{

Autodesk.AutoCAD.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<Line> lstLine = new List<Line>();

//遍历选择集
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<lstLine.Count;i++)
{
Line li=lstLine;
for(int j=i+1;j<lstLine.Count;j++)
{
Line pl1=lstLine[j];
//把LINE比配的交点存入pts集合中
li.IntersectWith(pl1, Intersect.OnBothOperands, pts, 0, 0);
}
}

//开始遍历循环存交点的集合并取出交点
if (pts.Count > 0)
{

for (int i = 0; i < pts.Count; i++)
{
Point3d p3d = new Point3d();
p3d = pts;//交点
//调用画柱子方法,以交点为中心点画柱子
DrawPillarMethod.DrawTrangle(p3d, "juxing", "800", "700", false);
}
}

//提交事务
trans.Commit();
}
}
else
{
MessageBox.Show("你没有选中任何实体");
}

}
#endregion

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

评分

参与人数 1威望 +1 收起 理由
雪山飞狐_lzh + 1 【好评】好程序

查看全部评分

 楼主| 发表于 2009-12-10 09:10 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-6-3 07:27 , Processed in 0.135631 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表