.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Filtering entities by name

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
cnicholas
1505 Views, 4 Replies

Filtering entities by name

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 

 

4 REPLIES 4
Message 2 of 5
dgorsman
in reply to: cnicholas

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.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 3 of 5
Hallex
in reply to: cnicholas

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());
                    }
                }
            }
        }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 5
cnicholas
in reply to: cnicholas

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

Message 5 of 5
Hallex
in reply to: cnicholas

You're welcome
Cheers, Craig
_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost