.NET

.NET

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

TypedValue filter by color with bylayer`

181 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,133
Registered: ‎04-29-2006
Message 2 of 3 (161 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: 37
Registered: ‎07-15-2010
Message 3 of 3 (130 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!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.