Hi Gile,
thank you for your response and your hint!
I have already created a similar code, but it has no graphical effect at all. What could be the reason for this?
Do I need to regenerate or update the selected block—possibly with a screen refresh (Flush Screen)?
Both system variables, DRAWORDERCTL and HPDRAWORDER, seem to be correctly set to a value of 3.
Are there any insights regarding dictionaries or other system variables that might affect this?
public void MoveHatchesToBackInBlock ( )
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions promptOptions = new PromptEntityOptions("\nSelect a block reference:");
promptOptions.SetRejectMessage("\nOnly block references are allowed.");
promptOptions.AddAllowedClass ( typeof ( BlockReference ), true );
PromptEntityResult promptResult = ed.GetEntity ( promptOptions );
if ( promptResult.Status != PromptStatus.OK )
{
ed.WriteMessage("\nCommand canceled.");
return;
}
ObjectId blockId = promptResult.ObjectId;
ObjectIdCollection hatchIds = new ObjectIdCollection ();
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockReference blockRef = tr.GetObject ( blockId, OpenMode.ForRead) as BlockReference;
if ( blockRef == null )
{
ed.WriteMessage("\nSelected entity is not a block reference.");
return;
}
BlockTableRecord blockRecord = tr.GetObject(blockRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId entId in blockRecord)
{
Entity entity = tr.GetObject(entId, OpenMode.ForRead) as Entity;
ed.WriteMessage("\nEntity: " + entity.GetType() );
if ( entity is Hatch )
{
ed.WriteMessage(" ... hatch found. " );
hatchIds.Add ( entId );
}
}
if ( hatchIds.Count > 0 )
{
DrawOrderTable drawOrderTable = tr.GetObject( blockRecord.DrawOrderTableId, OpenMode.ForWrite ) as DrawOrderTable;
drawOrderTable.MoveToBottom( hatchIds );
ed.WriteMessage("\nAll hatches (" + hatchIds.Count + ") + have been moved to the back within the block.");
}
else
{
ed.WriteMessage("\nNo hatches found in the block.");
}
tr.Commit();
}
}