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

TypedValue filter by color with bylayer`

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
absStructural
1111 Views, 6 Replies

TypedValue filter by color with bylayer`

I have a filter set up like this:

 

TypedValue[] filter =

newTypedValue[]

{

   newTypedValue((int)DxfCode.Operator, "<OR"), // crossframe or bearing color

   newTypedValue((int)DxfCode.Color, Autodesk.AutoCAD.Interop.Common.ACAD_COLOR.acRed),

   newTypedValue((int)DxfCode.Color, Autodesk.AutoCAD.Interop.Common.ACAD_COLOR.acWhite),

   newTypedValue((int)DxfCode.Operator, "OR>")

};

 

I then create a SelectionFilter with this TypedValue array, and use Editor.SelectAll(selectionFilter) to retrieve the desired entities.

 

The goal is to select all entities that are either red or white.  This works fine - except I also want to include entities that are ByLayer - if the color of the layer is red or white.

 

Is there any way to do this in a single filter? 

 

6 REPLIES 6
Message 2 of 7
_gile
in reply to: absStructural

Hi,

 

You can try this way:

string layers = string.Empty;
using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction())
{
    LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
    foreach (ObjectId id in lt)
    {
        LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead);
        if (ltr.Color == Color.FromColorIndex(ColorMethod.ByAci, 1) ||
            ltr.Color == Color.FromColorIndex(ColorMethod.ByAci, 7))
        {
            layers += ltr.Name + ",";
        }
    }
}

 TypedValue[] filter = 
 { 
    new TypedValue(-4, "<OR"),
    new TypedValue(62, 1),
    new TypedValue(62, 7),
    new TypedValue(-4, "<AND"),
    new TypedValue(62, 256),
    new TypedValue(8, layers),
    new TypedValue(-4, "AND>"),
    new TypedValue(-4, "OR>")
};

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 7
absStructural
in reply to: _gile

Not quite as straight forward as I would like - but that works.

 

Thanks!

Message 4 of 7
BKSpurgeon
in reply to: absStructural
Message 5 of 7
_gile
in reply to: BKSpurgeon


BKSpurgeon a écrit :

For future readers, this is a much better way:

 

http://through-the-interface.typepad.com/through_the_interface/2008/07/conditional-sel.html


Why do you think it's a "much better way" ? It seems to me it's exactly the same way using relational groups...



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 6 of 7
k005
in reply to: _gile

 

If we add a third color in this code, how should we change the code?

 

and it doesn't select the colors that are Bylayer in this filter. Where does this originate from?

 

I am attaching the sample file.

 

 

Message 7 of 7
k005
in reply to: k005

 

With this selection filter, colors belonging to the 62 code are selected. But Bylayer ones are not selected..! where is

 

wrong with this code? ?

 

Is there anyone who can help?

 

Thank you.

 

 

      TypedValue[] acTypValAr =
                {
                 new TypedValue(-4, "<OR"),
                 new TypedValue(62, ilkRenk),
                 new TypedValue(62, ikinciRenk),
                 new TypedValue(62, ucuncuRenk),
                 new TypedValue(-4, "<AND"),
                 new TypedValue(62, 256),
                 new TypedValue(8, layers),
                 new TypedValue(-4, "AND>"),
                 new TypedValue(-4, "OR>")
                };

 

 

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