With regards to the code by miki on Jun 7 2019
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"); }
I have tested and made corrections on the POLYLINE DXF CODE for Closed Polyline or Open Polyline
In LISP
Closed Polygon
(setq var (ssget "X" '((-4 . "<and")(-4 . "<or")(-4 . "<and")(0 . "POLYLINE")(-4 . "&")(70 . 1)(-4 . "and>")(-4 . "<and")(0 . "LWPOLYLINE")(-4 . "&")(70 . 1)(-4 . "and>")(-4 . "or>")(-4 . "<or")(410 . "MODEL")(67 . 0)(67 . 1)(-4 . "or>")(8 . "LAYERNAME")(-4 . "and>"))))
Open Polygon
(setq var (ssget "X" '((-4 . "<and")(-4 . "<or")(-4 . "<and")(0 . "POLYLINE")(-4 . "&")(70 . 0)(-4 . "and>")(-4 . "<and")(0 . "LWPOLYLINE")(-4 . "&")(70 . 0)(-4 . "and>")(-4 . "or>")(-4 . "<or")(410 . "MODEL")(67 . 0)(67 . 1)(-4 . "or>")(8 . "V-QURY-BNDY-LEGN")(-4 . "and>"))))
In C#
typedValue = new List<TypedValue>{
new TypedValue(Convert.ToInt32(DxfCode.Operator), "<and"),
new TypedValue(Convert.ToInt32(DxfCode.Operator), "<or"),
new TypedValue(Convert.ToInt32(DxfCode.Operator), "<and"),
new TypedValue(Convert.ToInt32(DxfCode.Start), "POLYLINE"),
new TypedValue(Convert.ToInt32(DxfCode.Operator), "&"),
new TypedValue(Convert.ToInt32(DxfCode.Int16), 1),
new TypedValue(Convert.ToInt32(DxfCode.Operator), "and>"),
new TypedValue(Convert.ToInt32(DxfCode.Operator), "<and"),
new TypedValue(Convert.ToInt32(DxfCode.Start), "LWPOLYLINE"),
new TypedValue(Convert.ToInt32(DxfCode.Operator), "&"),
new TypedValue(Convert.ToInt32(DxfCode.Int16), 1),
new TypedValue(Convert.ToInt32(DxfCode.Operator), "and>"),
new TypedValue(Convert.ToInt32(DxfCode.Operator), "or>"),
new TypedValue(Convert.ToInt32(DxfCode.Operator), "<or"),
new TypedValue(Convert.ToInt32(DxfCode.LayoutName), "MODEL"),
new TypedValue(Convert.ToInt32(DxfCode.ViewportVisibility), 0),
new TypedValue(Convert.ToInt32(DxfCode.ViewportVisibility), 1),
new TypedValue(Convert.ToInt32(DxfCode.Operator), "or>"),
new TypedValue(Convert.ToInt32(DxfCode.LayerName), "LAYERNAME"),
new TypedValue(Convert.ToInt32(DxfCode.Operator), "and>")
};