.NET

.NET

Reply
Valued Contributor
cjacobi
Posts: 55
Registered: ‎11-12-2012
Message 1 of 5 (244 Views)

Draworder of objects in newly created blocks

244 Views, 4 Replies
11-12-2012 12:51 PM

This is my first post here, so any help will be awesome.

 

I am creating a new block that includes text, lines and a solid object. The block is creating properly, however, the linework is behind the solid object.

 

How do I control the draworder of the items in the block?

 

Is there a way to set the order before I create the block, OR do I have to modifiy the block after I have created it?

 

Any help will be appreciated.

 

cj

Mentor
khoa.ho
Posts: 224
Registered: ‎09-15-2011
Message 2 of 5 (235 Views)

Re: Draworder of objects in newly created blocks

11-12-2012 03:33 PM in reply to: cjacobi

Hi,

 

I think you should set the draw order after creating the block, because a block can copy from one drawing to another. If you set order before creating the block, the entity’s draw orders will belong to the model space, not the block itself.

The custom draw orders of entities are saved in the DrawOrderTable attached to the block table record containing those entities. The block table record is the Model/Paper space or any block definition.

During creation of a block definition, you may collect all line entities, and also save an ObjectId of a solid entity that will stay behind all of linework. This following method will place all source entities above a given target entity.

 

// Move all source entities above a target entity
public static void DrawOrderMoveAbove(ObjectIdCollection sourceEntities, ObjectId targetEntity)
{
    Database db = targetEntity.Database;
    using (Transaction trans = db.TransactionManager.StartTransaction())
    {
        var entity = trans.GetObject(targetEntity, OpenMode.ForRead) as Entity;
        if (entity == null)
            return;
        // Get the block definition (block table record) containing this entity
        var btr = (BlockTableRecord)trans.GetObject(entity.BlockId, OpenMode.ForRead);
        // Get the draw order table of the block
        var drawOrder = (DrawOrderTable)trans.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite);

        // Move all source entities above a target entity
        drawOrder.MoveAbove(sourceEntities, targetEntity);
        drawOrder.DowngradeOpen();
        trans.Commit();
    }
}

 

-Khoa

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 5 (210 Views)

Re: Draworder of objects in newly created blocks

11-13-2012 06:33 AM in reply to: cjacobi

Have you tried to change order of adding the objects

in the block record, e.g. first add a solid, then other things after?

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
cjacobi
Posts: 55
Registered: ‎11-12-2012
Message 4 of 5 (201 Views)

Re: Draworder of objects in newly created blocks

11-13-2012 01:54 PM in reply to: Hallex

It's a very complex process to add the objects to be in the block so the order that things get added to the block cannot be altered. I did try previously to move things around in the code, without success.

 

Looks like I will have to create a function that goes and puts the lines above the shade as suggested after the block as been created.

 

Will let you know how I make out.

 

 

Valued Contributor
frosty1_4me
Posts: 100
Registered: ‎11-13-2006
Message 5 of 5 (118 Views)

Re: Draworder of objects in newly created blocks

03-05-2014 12:42 PM in reply to: khoa.ho

I'm looking to do exactl this, I haven't figured out how to set the sourceEntitie which in my case is an Xref and the targetEntity.  Can this code be modified to do that?

 

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.