马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[C#] 纯文本查看 复制代码
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();
}
}
}
另外一个
[C#] 纯文本查看 复制代码 // 访问AutoCAD程序对象。
using Autodesk.AutoCAD.ApplicationServices;
// 访问 the AutoCAD 编辑器。
using Autodesk.AutoCAD.EditorInput;
// 命令注册。
using Autodesk.AutoCAD.Runtime;
// 访问数据库对象。
using Autodesk.AutoCAD.DatabaseServices;
namespace EntitySelection
{
public class Commands
{
[CommandMethod("SelectOnlayer")]
static public void SelectEnt()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptResult pr =
ed.GetString("\n请输入图层名称: ");
if (pr.Status == PromptStatus.OK)
{
TypedValue[] filList = new TypedValue[1];
filList[0] = new TypedValue((int)DxfCode.LayerName, pr.StringResult);
SelectionFilter filter = new SelectionFilter(filList);
PromptSelectionResult ssRes = ed.SelectAll(filter);
if (ssRes.Status == PromptStatus.OK)
{
SelectionSet SS = ssRes.Value;
int nCount = SS.Count;
ed.WriteMessage("在{0}层上找到{1}个实体", pr.StringResult, nCount);
}
}
}
}
}
|