Hi
I've borrowed and modified the filtering code from the online help to create a selection set. Here's the code.
private SelectionSet FilterSelectionSet(string entityTypeName) { // Create a TypedValue array to define the filter criteria TypedValue[] acTypValAr = new TypedValue[1]; acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, entityTypeName), 0); // Assign the filter criteria to a SelectionFilter object SelectionFilter acSelFtr = new SelectionFilter(acTypValAr); // Select all objects according to the filter in the drawing area PromptSelectionResult acSSPrompt; acSSPrompt = Active.Editor.SelectAll(acSelFtr); // If the prompt status is OK, objects were selected if (acSSPrompt.Status == PromptStatus.OK) { SelectionSet acSSet = acSSPrompt.Value; return acSSet; } else return null; }
I pass in the entityName using code like this
SelectionSet ss = FilterSelectionSet(typeof(Polyline).Name);
In the case of polylines which have been drawn using AutoCAD, it does not find any entities. After looking around I found the use of LWPOLYLINE so if I now introduce this test in the method it finds the polylines.
if (entityTypeName.ToUpper() == "POLYLINE") entityTypeName = "LWPOLYLINE";
Is this to be expected?
When would "POLYLINE" need to be left as "POLYLINE"?
Does this occur for any other entities?
Craig
Solved! Go to Solution.
Solved by Hallex. Go to Solution.
AutoCAD has several types of polylines. Most of them will be lightweight, or LWPOLYLINE objects. Older files may have the old "heavy" polylines, which have slightly different data. There may also be 3D polylines as well.
Try this very basic example, you will see how to detect
polyline type anyway:
//using System.Text;// for StringBuilder [CommandMethod("spt", CommandFlags.UsePickSet)] public void testPolySelect() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; StringBuilder sb = new StringBuilder(); using (DocumentLock docloc = doc.LockDocument()) { using (Transaction tr = db.TransactionManager.StartTransaction()) { try { // select line, lwpolyline,polyline3d, polyline2d TypedValue[] tv = new TypedValue[] { new TypedValue((int)DxfCode.Start, "LINE,*POLY*") }; SelectionFilter flt = new SelectionFilter(tv); //select on screen PromptSelectionResult selRes = ed.GetSelection(flt); SelectionSet selSet = selRes.Value; ObjectId[] ids = selSet.GetObjectIds(); foreach (ObjectId entId in ids) { Line ln = tr.GetObject(entId, OpenMode.ForRead) as Line; if (ln != null) { sb.AppendLine(string.Format("{0:f3}\t{1:f3}", ln.StartPoint, ln.EndPoint)); } Polyline poly = tr.GetObject(entId, OpenMode.ForRead) as Polyline; if (poly != null) { sb.AppendLine(string.Format("{0:f3}\t{1:f3}", poly.StartPoint,poly.EndPoint)); } Polyline3d poly3d = tr.GetObject(entId, OpenMode.ForRead) as Polyline3d; if (poly3d != null) { sb.AppendLine(string.Format("{0:f3}\t{1:f3}", poly3d.StartPoint, poly3d.EndPoint)); } Polyline2d poly2d = tr.GetObject(entId, OpenMode.ForRead) as Polyline2d; if (poly2d != null) { sb.AppendLine(string.Format("{0:f3}\t{1:f3}", poly2d.StartPoint, poly2d.EndPoint)); } } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.StackTrace); } finally { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(sb.ToString()); } } } }
Thanks for the hint. I've simply used the wildcard character in the entity name as you have done and it simplifies what I need to do.
if (entityTypeName.ToUpper() == "POLYLINE") entityTypeName = "*POLYLINE*";
Craig