查看单个帖子
旧 2009-04-20, 02:52 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】[kean]使用.net获取一个层上的所有实体 - 精华帖集合

[kean]使用.net获取一个层上的所有实体 - 精华帖集合
www.dimcax.com
[kean]使用.net获取一个层上的所有实体
using autodesk.autocad.applicationservices;
using autodesk.autocad.runtime;
using autodesk.autocad.databaseservices;
using autodesk.autocad.editorinput;
namespace entityselection
{
public class commands
{
[commandmethod("eol")]
static public void entitiesonlayer()
{
document doc =
application.documentmanager.mdiactivedocument;
editor ed = doc.editor;
promptresult pr =
ed.getstring("\nenter name of layer: ");
if (pr.status == promptstatus.ok)
{
objectidcollection ents =
getentitiesonlayer(pr.stringresult);
ed.writemessage(
"\nfound {0} entit{1} on layer {2}",
ents.count,
(ents.count == 1 ? "y" : "ies"),
pr.stringresult
);
}
}
private static objectidcollection
getentitiesonlayer(string layername)
{
document doc =
application.documentmanager.mdiactivedocument;
editor ed = doc.editor;
// build a filter list so that only entities
// on the specified layer are selected
typedvalue[] tvs =
new typedvalue[1] {
new typedvalue(
(int)dxfcode.layername,
layername
)
};
selectionfilter sf =
new selectionfilter(tvs);
promptselectionresult psr =
ed.selectall(sf);
if (psr.status == promptstatus.ok)
return
new objectidcollection(
psr.value.getobjectids()
);
else
return new objectidcollection();
}
}
}
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)