通过一点选择所有经过该点的线(转载Kean的文章)
2012-11-26 11:06
176 查看
[CommandMethod("WinDb")]
public
void SelectCrossingDatabase()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Editor ed =
doc.Editor;
try
{
PromptPointOptions ptOpts =
new
PromptPointOptions(
"\nPick a point at which to select all lines: "
);
PromptPointResult ptRes = ed.GetPoint(ptOpts);
if (PromptStatus.OK == ptRes.Status)
{
ObjectIdCollection ids =
new
ObjectIdCollection();
Point3d p = ptRes.Value;
Database db = doc.Database;
Transaction tr =
db.TransactionManager.StartTransaction();
using( tr )
{
BlockTable bt =
(BlockTable)tr.GetObject(
db.BlockTableId,
OpenMode.ForRead
);
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(
bt[BlockTableRecord.ModelSpace],
OpenMode.ForRead
);
foreach(
ObjectId id in btr )
{
DBObject obj =
tr.GetObject( id,
OpenMode.ForRead );
Line dbLine = obj
as Line;
if (dbLine !=
null)
{
LineSegment3d lineSegment =
new
LineSegment3d(
dbLine.StartPoint,
dbLine.EndPoint
);
PointOnCurve3d q =
lineSegment.GetClosestPointTo(p);
if (p.DistanceTo( q.Point ) < 0.01)
{
ids.Add( dbLine.ObjectId );
}
}
}
tr.Commit();
}
int n = ids.Count;
ed.WriteMessage(
string.Format(
"\n{0} line{1} selected.",
n, 1 == n ?
"" : "s"
)
);
}
}
catch( System.Exception e )
{
ed.WriteMessage("\nException {0}.", e);
}
}
}
public
void SelectCrossingDatabase()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Editor ed =
doc.Editor;
try
{
PromptPointOptions ptOpts =
new
PromptPointOptions(
"\nPick a point at which to select all lines: "
);
PromptPointResult ptRes = ed.GetPoint(ptOpts);
if (PromptStatus.OK == ptRes.Status)
{
ObjectIdCollection ids =
new
ObjectIdCollection();
Point3d p = ptRes.Value;
Database db = doc.Database;
Transaction tr =
db.TransactionManager.StartTransaction();
using( tr )
{
BlockTable bt =
(BlockTable)tr.GetObject(
db.BlockTableId,
OpenMode.ForRead
);
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(
bt[BlockTableRecord.ModelSpace],
OpenMode.ForRead
);
foreach(
ObjectId id in btr )
{
DBObject obj =
tr.GetObject( id,
OpenMode.ForRead );
Line dbLine = obj
as Line;
if (dbLine !=
null)
{
LineSegment3d lineSegment =
new
LineSegment3d(
dbLine.StartPoint,
dbLine.EndPoint
);
PointOnCurve3d q =
lineSegment.GetClosestPointTo(p);
if (p.DistanceTo( q.Point ) < 0.01)
{
ids.Add( dbLine.ObjectId );
}
}
}
tr.Commit();
}
int n = ids.Count;
ed.WriteMessage(
string.Format(
"\n{0} line{1} selected.",
n, 1 == n ?
"" : "s"
)
);
}
}
catch( System.Exception e )
{
ed.WriteMessage("\nException {0}.", e);
}
}
}
相关文章推荐
- 这个分类几乎所有文章转载地址
- 城市选择插件研究(个人研究用——转载至他人文章)
- 看到一篇很有感触的文章,转载过来,希望更多的技术开发人员能有所得 ----五年软件开发的一点自我总结
- kingcms改进之递归多级子栏目一键生成所有文章(转载未验证)
- 一篇关于职业选择的好文章(转载)
- 经典技术文章转载:如何选择ASP.NET Web 服务与.NET Remoting
- MyEclipse 需要解决的一些辅助性问题 收藏 (所有文章全是转载)
- (转载)通过dbgrideh 从数据集中选择合适的记录
- [转载]《通过例子学习Lua》系列文章
- 如果你想推荐本文到CSDN 技术中心,请选择下列的文章分类之一。文章保存时将自动提交到CSDN技术中心,通过审核后本文将出现在您的CSDN 技术中心的专栏中。如果您不希望本文被提交到CSDN技术中心,请选择"不发表到CSDN技术中心"。注:还没有C
- Python NLTK学习6(创建词性标注器)除特别注明外,本站所有文章均为刘杰的个人网站原创 转载请注明出处: http://www.burnelltek.com/blog/60740e24d2f
- Google Friendly的网站设计 选择自 Kamus 的 Blog (转载,版权归原作者所有)
- wordpress通过$wpdb获取一个分类下所有的文章
- c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程
- 看到一篇很有感触的文章,转载过来,希望更多的技术开发人员能有所得 ----五年软件开发的一点自我总结
- 给所有关注SNMP朋友的一点小文章
- AutoCAD VBA 通过选择集 删除图层上所有对象和图层
- 一.jQuery 学习选择器(转载自Code-Cat文章)
- Easyui combotree 通过选择的节点获取所有父级节点
- 转载自博客园的一篇文章 通过SQL Server Profiler来监视分析死锁