Author Topic: DrawOrder operation on Layer  (Read 3853 times)

0 Members and 1 Guest are viewing this topic.

MaksimS

  • Guest
DrawOrder operation on Layer
« on: March 23, 2007, 10:28:05 AM »
Dear all,

I'd like to perform a DrawOrder table SendToBack operation on complete Layer (entities residing on given Layer). I'm using WorkingDatabase opened within Editor. What do you think, what is the most optimal (read - fastest) :-) way of doing this?

Regards,
Maksim Sestic
« Last Edit: March 23, 2007, 10:34:36 AM by MaksimS »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: DrawOrder operation on Layer
« Reply #1 on: March 23, 2007, 11:05:09 AM »
Too late to fire up the IDE, but ..

A selection Set is based on ICollection.
The moveBelow first parameter is an ObjectIdCollection.

public void MoveBelow(ObjectIdCollection collection, ObjectId target);

just a W.A.G. cause I haven't tried to play with Draworder.



Have you tried to make a selection filtered for the layer and passing that collection to MoveBelow ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

TonyT

  • Guest
Re: DrawOrder operation on Layer
« Reply #2 on: March 23, 2007, 12:34:23 PM »
Something like this should do what you need
(completely untested and minimal error checking):

Code: [Select]
public static class Class1
{
   public static int SendLayerToBack( ObjectId BlockId, string layerName )
   {
      Database db = BlockId.Database;
      using( Transaction tr = db.TransactionManager.StartTransaction() )
      {
         LayerTable layers = tr.GetObject(
              db.LayerTableId, OpenMode.ForRead ) as LayerTable;
         ObjectId layerId;
         try
         {
            layerId = layers[layerName];
         }
         catch
         {
            return -1;
         }
         BlockTableRecord rec = tr.GetObject(
               BlockId, OpenMode.ForWrite ) as BlockTableRecord;
         ObjectIdCollection ids = new ObjectIdCollection();
         foreach( ObjectId id in rec )
         {
            if( id.IsEffectivelyErased )
               continue;
            Entity ent = tr.GetObject( id, OpenMode.ForRead ) as Entity;
            if( ent.LayerId == layerId )
               ids.Add( id );
         }
         if( ids.Count > 0 )
         {
            DrawOrderTable tbl = tr.GetObject(
                   rec.DrawOrderTableId, OpenMode.ForWrite ) as DrawOrderTable;
            tbl.MoveToBottom( ids );
            tr.Commit();
         }
         return ids.Count;
      }
   }
}


Dear all,

I'd like to perform a DrawOrder table SendToBack operation on complete Layer (entities residing on given Layer). I'm using WorkingDatabase opened within Editor. What do you think, what is the most optimal (read - fastest) :-) way of doing this?

Regards,
Maksim Sestic
« Last Edit: March 23, 2007, 07:46:07 PM by TonyT »

sinc

  • Guest
Re: DrawOrder operation on Layer
« Reply #3 on: March 23, 2007, 05:53:12 PM »
You can also just use something like GETSEL (in Express Tools) to select all items on the layer, then do a "Move to Back" and select "P" (for previous selection set).

Around here, we have GETSEL assigned to SHIFT+CTRL+G and Move to Back assigned to CTRL+B, so the operation is very fast, and takes no custom coding.

However, custom coding like Tony's is even quicker.

MaksimS

  • Guest
Re: DrawOrder operation on Layer
« Reply #4 on: March 24, 2007, 08:17:32 AM »
Thanks guys,

Since I'm constrained to WorkingDatabase opened within Editor I resorted to mix of the two (Kerry's and Tony's solutions):

1) create a filtered selection set based on Layer name
2) check if selset is valid (no layer name validity chech here since there's no selset if layer name doesn't exist)
3) pass selset's array of ObjectIds (selset.Value.GetObjectIds) to DrawOrderTable's MoveToBottom function (as it receives array of ObjectIds)

Regards,
Maksim Sestic




« Last Edit: March 24, 2007, 08:20:37 AM by MaksimS »

TonyT

  • Guest
Re: DrawOrder operation on Layer
« Reply #5 on: March 24, 2007, 06:37:56 PM »
Glad you found a solution.

The code I posted was adapted from something that
was designed to work with the draworder table of
any block, in any database. Of course, it can be used
with the model space of the current working database
by just passing it the model space block id.

Thanks guys,

Since I'm constrained to WorkingDatabase opened within Editor I resorted to mix of the two (Kerry's and Tony's solutions):

1) create a filtered selection set based on Layer name
2) check if selset is valid (no layer name validity chech here since there's no selset if layer name doesn't exist)
3) pass selset's array of ObjectIds (selset.Value.GetObjectIds) to DrawOrderTable's MoveToBottom function (as it receives array of ObjectIds)

Regards,
Maksim Sestic






Glenn R

  • Guest
Re: DrawOrder operation on Layer
« Reply #6 on: March 25, 2007, 10:27:47 AM »
Of course, it can be used
with the model space of the current working database
by just passing it the model space block id.

I think that one "went through to the keeper" as we say down here Tony.