求教!!C#有条件选择CAD实体
http://www.cnblogs.com/wf225/archive/2008/08/08/1263674.html这篇文章有相关代码,可是我运行时怎么提示“错误 CS0103: 当前上下文中不存在名称"Tools"”;自己搞不明白,所以请教各位大神了,谢谢。
各位,帮帮小弟吧,谢谢!!
本帖最后由 liuxu042 于 2012-2-7 13:38 编辑
Tools应该是作者自己定义的类,可以自己改动一下代码,试试如下代码:
public static void SelectEntitiesWithProperties()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
TypedValue[] tvs = new TypedValue[]
{
new TypedValue((int)DxfCode.Operator, "<or"),
new TypedValue((int)DxfCode.Operator, "<and"),
new TypedValue((int)DxfCode.LayerName, "0"),
new TypedValue((int)DxfCode.Start, "LINE"),
new TypedValue((int)DxfCode.Operator, "and>"),
new TypedValue((int)DxfCode.Operator, "<and"),
new TypedValue((int)DxfCode.Start, "CIRCLE"),
new TypedValue((int)DxfCode.Operator, ">="),
new TypedValue((int)DxfCode.Real, 10.0),// Circle Radius
new TypedValue((int)DxfCode.Operator, "and>"),
new TypedValue((int)DxfCode.Operator, "or>")
};
SelectionFilter sf = new SelectionFilter(tvs);
PromptSelectionResult psr = ed.SelectAll(sf);
if (psr.Status == PromptStatus.OK)
{
SelectionSet SS = psr.Value;
ObjectId[] idArray = SS.GetObjectIds();
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction ta = db.TransactionManager.StartTransaction())
{
for (int i = 0; i < idArray.Length; i++)
{
Entity ent = (Entity)ta.GetObject(idArray, OpenMode.ForRead);
ent.Highlight();
ed.WriteMessage("\n"+i + ":" + ent.ObjectId.ToString() + "," + ent.GetType().Name);
}
ta.Commit();
}
}
}
liuxu042 发表于 2012-2-7 13:28 static/image/common/back.gif
Tools应该是作者自己定义的类,可以自己改动一下代码,试试如下代码:
...
运行通过了,谢谢了。
如果返回值让它为直线的起始坐标和终点坐标,圆的话返回圆心和半径该怎么修改呢? xiaozhuyaofei 发表于 2012-2-7 18:07 static/image/common/back.gif
运行通过了,谢谢了。
如果返回值让它为直线的起始坐标和终点坐标,圆的话返回圆心和半径该怎么修改呢?
for (int i = 0; i < idArray.Length; i++)
{
Entity ent = (Entity)ta.GetObject(idArray, OpenMode.ForRead);
ent.Highlight();
if (ent is Line)
{
Line myline = ent as Line;
ed.WriteMessage("\n直线"+i+"起点坐标:"+myline.StartPoint.ToString()+"终点坐标:"+myline.EndPoint.ToString());
}
else if (ent is Circle)
{
Circle mycircle = ent as Circle;
ed.WriteMessage("\n圆" + i +"圆心:"+ mycircle.Center.ToString() +"半径:" +mycircle.Radius.ToString());
}
}
页:
[1]