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
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
Have you tried to change order of adding the objects
in the block record, e.g. first add a solid, then other things after?
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.
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