.NET

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

Draworder of objects in newly created blocks

220 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: 157
Registered: ‎09-15-2011
Message 2 of 5 (211 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 (186 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: 54
Registered: ‎11-12-2012
Message 4 of 5 (177 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: 54
Registered: ‎11-13-2006
Message 5 of 5 (94 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community