.NET

Reply
Valued Mentor
kevin.barnett
Posts: 397
Registered: ‎08-13-2007
Message 1 of 6 (667 Views)
Accepted Solution

selection filer typedvalue between X and between Y

667 Views, 5 Replies
06-04-2012 05:25 AM

AutoCAD 2012

C#

Windows 7

 

I need a selection filter to find text objects within a rectangular area using dxf operators (do not want to use Editor.SelectWindow).

 

Whats wrong with the following code attempt?

It causes Fatal Error!

Thx.. Kevn..

 

 

TypedValue[] tv2 = new TypedValue[15];


tv2.SetValue(new TypedValue((int)DxfCode.Start, "TEXT"), 0);

 

tv2.SetValue(new TypedValue((int)DxfCode.Operator, "<and"), 1);
tv2.SetValue(new TypedValue((int)DxfCode.Operator, "<and"), 2);
tv2.SetValue(new TypedValue((int)DxfCode.Operator, ">"), 3);
tv2.SetValue(new TypedValue((int)DxfCode.XCoordinate,
Match1[0].GeometricExtents.MinPoint.X - 20), 4);
tv2.SetValue(new TypedValue((int)DxfCode.Operator, "<"), 5);
tv2.SetValue(new TypedValue((int)DxfCode.XCoordinate,
Match1[0].GeometricExtents.MaxPoint.X + 20), 6);
tv2.SetValue(new TypedValue((int)DxfCode.Operator, "and>"), 7);

tv2.SetValue(new TypedValue((int)DxfCode.Operator, "<and"), 8);
tv2.SetValue(new TypedValue((int)DxfCode.Operator, ">"), 9);
tv2.SetValue(new TypedValue((int)DxfCode.YCoordinate,
Match1[0].GeometricExtents.MinPoint.Y + 109), 10);
tv2.SetValue(new TypedValue((int)DxfCode.Operator, "<"), 11);
tv2.SetValue(new TypedValue((int)DxfCode.YCoordinate,
Match1[0].GeometricExtents.MaxPoint.Y + 131), 12);
tv2.SetValue(new TypedValue((int)DxfCode.Operator, "and>"), 13);
tv2.SetValue(new TypedValue((int)DxfCode.Operator, "and>"), 14);

 

SelectionFilter sf2 = new SelectionFilter(tv2);
PromptSelectionResult psr2 = AcadDoc1.Editor.SelectAll(sf2);

See if this working for you,

I used Polyline instead of "unknown Match[0]" on my machine:

 Extents3d ext = pline.GeometricExtents;
double xmin = ext.MinPoint.X - 20;
double ymin = ext.MinPoint.Y + 109;
double xmax = ext.MaxPoint.X + 20;
double ymax = ext.MaxPoint.Y + 131;
Point3d minpt = new Point3d(xmin, ymin, pline.Elevation).TransformBy(Matrix3d.Identity);
Point3d maxpt = new Point3d(xmax, ymax, pline.Elevation).TransformBy(Matrix3d.Identity);
string tab = (string)Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("CTAB");
TypedValue[] tvs = new TypedValue[] {
new TypedValue((int) DxfCode.Start, "TEXT"),
new TypedValue(410, tab),
new TypedValue((int) DxfCode.Operator, "<AND"),
new TypedValue((int) DxfCode.Operator, ">,>,*"),
new TypedValue((int) 10, minpt),
new TypedValue((int) DxfCode.Operator, "<,<,*"),
new TypedValue((int) 10, maxpt),
new TypedValue((int) DxfCode .Operator, "AND>")
};
SelectionFilter sf = new SelectionFilter(tvs);
PromptSelectionResult psr = ed.SelectAll(sf);
if (psr.Status == PromptStatus.OK)
{
count = psr.Value.GetObjectIds().Length;
ed.WriteMessage("\nSelected: " + count.ToString());
}
else
{
ed.WriteMessage("\nBad selection");
return;
}
tr.Commit();
}

 

~'J'~

Valued Mentor
kevin.barnett
Posts: 397
Registered: ‎08-13-2007
Message 2 of 6 (666 Views)

Re: selection filer typedvalue between X and between Y

06-04-2012 05:50 AM in reply to: kevin.barnett

.. this also did not work ... fatal error ...

 

TypedValue[] tv2 =
new TypedValue[]
{
new TypedValue((int)DxfCode.Operator, "<and"),

new TypedValue((int)DxfCode.Operator, "<and"),
new TypedValue((int)DxfCode.Start, "TEXT"),
new TypedValue((int)DxfCode.Operator, ">"),
new TypedValue((int)DxfCode.XCoordinate, Match1[0].GeometricExtents.MinPoint.X - 20),
new TypedValue((int)DxfCode.Operator, "and>"),

new TypedValue((int)DxfCode.Operator, "<and"),
new TypedValue((int)DxfCode.Start, "TEXT"),
new TypedValue((int)DxfCode.Operator, "<"),
new TypedValue((int)DxfCode.XCoordinate, Match1[0].GeometricExtents.MaxPoint.X + 20),
new TypedValue((int)DxfCode.Operator, "and>"),

new TypedValue((int)DxfCode.Operator, "<and"),
new TypedValue((int)DxfCode.Start, "TEXT"),
new TypedValue((int)DxfCode.Operator, ">"),
new TypedValue((int)DxfCode.YCoordinate, Match1[0].GeometricExtents.MinPoint.Y + 109),
new TypedValue((int)DxfCode.Operator, "and>"),

new TypedValue((int)DxfCode.Operator, "<and"),
new TypedValue((int)DxfCode.Start, "TEXT"),
new TypedValue((int)DxfCode.Operator, "<"),
new TypedValue((int)DxfCode.YCoordinate, Match1[0].GeometricExtents.MaxPoint.Y + 131),
new TypedValue((int)DxfCode.Operator, "and>"),

new TypedValue((int)DxfCode.Operator, "and>")
};

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 6 (640 Views)

Re: selection filer typedvalue between X and between Y

06-05-2012 08:53 AM in reply to: kevin.barnett

See if this working for you,

I used Polyline instead of "unknown Match[0]" on my machine:

                    Extents3d ext = pline.GeometricExtents;
                    double xmin = ext.MinPoint.X - 20;
                    double ymin = ext.MinPoint.Y + 109;
                    double xmax = ext.MaxPoint.X + 20;
                    double ymax = ext.MaxPoint.Y + 131;
                    Point3d minpt = new Point3d(xmin, ymin, pline.Elevation).TransformBy(Matrix3d.Identity);
                    Point3d maxpt = new Point3d(xmax, ymax, pline.Elevation).TransformBy(Matrix3d.Identity);  
                    string tab = (string)Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("CTAB");
                
                    TypedValue[] tvs = new TypedValue[] { 
              new TypedValue((int) DxfCode.Start, "TEXT"),
              new TypedValue(410, tab),
               new TypedValue((int) DxfCode.Operator, "<AND"),
              new TypedValue((int)  DxfCode.Operator, ">,>,*"), 
              new TypedValue((int) 10, minpt),   
              new TypedValue((int) DxfCode.Operator, "<,<,*"), 
              new TypedValue((int) 10, maxpt), 
              new TypedValue((int) DxfCode .Operator, "AND>")
            };
                    SelectionFilter sf = new SelectionFilter(tvs);

                    PromptSelectionResult psr = ed.SelectAll(sf);

                    if (psr.Status == PromptStatus.OK)
                    {
                        count = psr.Value.GetObjectIds().Length;
                        ed.WriteMessage("\nSelected:    " + count.ToString());

                    }
                    else
                    {
                        ed.WriteMessage("\nBad selection");
                        return;

                    }
                   
                    tr.Commit();
                }

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Mentor
kevin.barnett
Posts: 397
Registered: ‎08-13-2007
Message 4 of 6 (619 Views)

Re: selection filer typedvalue between X and between Y

06-07-2012 02:27 AM in reply to: Hallex

Dude! You ROCK! Thanks!

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 6 (616 Views)

Re: selection filer typedvalue between X and between Y

06-07-2012 04:01 AM in reply to: kevin.barnett

Glad to help :smileyhappy:

 

Regards,

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
amitk_189
Posts: 242
Registered: ‎12-15-2011
Message 6 of 6 (218 Views)

Re: selection filer typedvalue between X and between Y

04-22-2014 01:24 AM in reply to: Hallex
Hi Hallex,

I have two confusions

1) I am using COM objects, in this case will this logic work.
2) On what basis is Pline initialised.

Please reply.

rgds
Amit
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!