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?
Solved! Go to Solution.
Solved by _gile. Go to Solution.
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>") };
For future readers, this is a much better way:
http://through-the-interface.typepad.com/through_the_interface/2008/07/conditional-sel.html
and also here:
http://help.autodesk.com/view/ACD/2016/ENU/?guid=GUID-04B8192E-B0D8-4731-A882-AE92B7CFAE22
hope this helps
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...
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.
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>")
};