.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Draworder of objects in newly created blocks

4 REPLIES 4
Reply
Message 1 of 5
coralie.jacobi
625 Views, 4 Replies

Draworder of objects in newly created blocks

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

4 REPLIES 4
Message 2 of 5
khoa.ho
in reply to: coralie.jacobi

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

Message 3 of 5
Hallex
in reply to: coralie.jacobi

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
Message 4 of 5
coralie.jacobi
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.

 

 

Message 5 of 5
frosty1_4me
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost