.NET

Reply
Active Contributor
absStructural
Posts: 36
Registered: ‎07-15-2010
Message 1 of 3 (149 Views)
Accepted Solution

TypedValue filter by color with bylayer`

149 Views, 2 Replies
08-09-2014 09:07 AM

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? 

 

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

 

*Expert Elite*
_gile
Posts: 2,086
Registered: ‎04-29-2006
Message 2 of 3 (129 Views)

Re : TypedValue filter by color with bylayer`

08-09-2014 12:54 PM 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
Active Contributor
absStructural
Posts: 36
Registered: ‎07-15-2010
Message 3 of 3 (98 Views)

Re : TypedValue filter by color with bylayer`

08-11-2014 06:27 AM in reply to: _gile

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

 

Thanks!

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.