我知道这是个老问题,但也许有人会觉得它有用。
使用 SelectionFilter 仅选择打开或关闭的折线(任何类型的折线):
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
int polylineState = 1; // 0 - closed, 1 - open
TypedValue[] vals= new TypedValue[]
{
new TypedValue((int)DxfCode.Operator, "<or"),
// This catches Polyline object.
new TypedValue((int)DxfCode.Operator, "<and"),
new TypedValue((int)DxfCode.Start, "LWPOLYLINE"),
new TypedValue(70, polylineState),
new TypedValue((int)DxfCode.Operator, "and>"),
new TypedValue((int)DxfCode.Operator, "<and"),
new TypedValue((int)DxfCode.Start, "POLYLINE"),
new TypedValue((int)DxfCode.Operator, "<or"),
// This catches Polyline2d object.
new TypedValue(70, polylineState),
// This catches Polyline3d object.
new TypedValue(70, 8|polylineState),
new TypedValue((int)DxfCode.Operator, "or>"),
new TypedValue((int)DxfCode.Operator, "and>"),
new TypedValue((int)DxfCode.Operator, "or>"),
};
SelectionFilter filter = new SelectionFilter(vals);
PromptSelectionResult prompt = ed.GetSelection(filter);
// If the prompt status is OK, objects were selected
if (prompt.Status == PromptStatus.OK)
{
SelectionSet sset = prompt.Value;
Application.ShowAlertDialog($"Number of objects selected: {sset.Count.ToString()}");
}
else
{
Application.ShowAlertDialog("Number of objects selected: 0");
}
所有绘图实体的列表:链接 1(旧)或链接 2(新)
在这个链接中,我们看到值为 1 的代码 70 是闭合的折线。
在这个链接中,我们看到这同样适用于 2d/3d 折线,但另外使用值 8,我们定义它是 2d 还是 3d 折线。值可以按位组合,因此 8|1 表示封闭的 3d 折线。