几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   ObjectARX(VB.NET/C#) (http://www.dimcax.com/hust/forumdisplay.php?f=176)
-   -   【转帖】[kean]使用.net获取一个层上的所有实体 - 精华帖集合 (http://www.dimcax.com/hust/showthread.php?t=9065)

yang686526 2009-04-20 02:52 PM

【转帖】[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();
}
}
}


所有的时间均为北京时间。 现在的时间是 05:57 AM.