AutoCAD.net: DrawOrder--Change display order of the entities in the drawing

public class DrawOrderTable :

Autodesk.AutoCAD.DatabaseServices.DBObject

Member of

Autodesk.AutoCAD.DatabaseServices

Summary:

Is the persistent container for draw order information. It resides in the extension dictionary of an associated BlockTableRecord under the key ACAD_SORTENTS.

Method 
Description 

Returns true if first is drawn before second. 
SYstem

Returns an collection of the entity object IDs of the block in the order in which they would be...
more  

Rearranges the object IDs in the input array into their current relative draw order.
When one or more bits of...
more  

Given an input object ID, this function returns the Handle that indicates the draw order. Entities with lesser handle values... more  

Places all the entities specified in the input object ID array above the specified target entity. The entities being moved... more  

Places all the entities specified in the input object ID array below the specified target entity. The entities being moved... more  

Places all the entities specified in the input object ID array at the beginning of the draw order. The entities... more  

Places all the entities specified in the input object ID array at the ending of the draw order. The entities... more  

Takes the object IDs in the input collection and moves them in their current associated draw order slots so that... more  

Swaps the draw order positions of the entities. 

 

Sample Code:

ContractedBlock.gif ExpandedBlockStart.gif          DrawOrder #region DrawOrder

        [CommandMethod(
"DrawOrderTest")]
        
public void DrawOrderTest()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
            Document doc 
= Application.DocumentManager.MdiActiveDocument;
            Database db 
= Application.DocumentManager.MdiActiveDocument.Database;
            Editor ed 
= doc.Editor;
            ObjectId id1 
= ObjectId.Null;
            ObjectId id2 
= ObjectId.Null;

            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                
using (Transaction tr = db.TransactionManager.StartTransaction())
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    BlockTable bt 
= (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite, false);
                    BlockTableRecord btr 
= (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
                    
//Get the DrawOrderTable
                    DrawOrderTable orderTable = tr.GetObject(btr.DrawOrderTableId, OpenMode.ForWrite) as DrawOrderTable;

                    PromptEntityOptions entOpt 
= new PromptEntityOptions("\nSelect first");
                    PromptEntityResult entRes 
= ed.GetEntity(entOpt);
                    
if (entRes.Status != PromptStatus.OK) return;
                    id1 
= entRes.ObjectId;

                    entOpt.Message 
= "\nSelect second";
                    
do
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        entRes 
= ed.GetEntity(entOpt);
                        
if (entRes.Status != PromptStatus.OK) return;
                        id2 
= entRes.ObjectId;
                        entOpt.Message 
= "\nYou selected one and the same entity, select again";
                    }
 while (id2 == id1);

                    
if (id1 != ObjectId.Null && id2 != ObjectId.Null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        
//if (orderTable.FirstEntityIsDrawnBeforeSecond(id1, id2)) //Why it will be crash?
ExpandedSubBlockStart.gifContractedSubBlock.gif
                        {
                            
//orderTable.SwapOrder(id1, id2); //Why it didn't execute?

                            ObjectIdCollection ids 
= new ObjectIdCollection();
                            ids.Add(id1);
                            orderTable.MoveAbove(ids, id2); 
//It's OK.
                            
//orderTable.MoveBelow(ids, id2); //It's OK.
                            
//orderTable.MoveToBottom(ids); //It's OK.
                            
//orderTable.MoveToTop(ids); //It's OK.
                        }

                    }

                    tr.Commit();
                }

            }

            
catch (Autodesk.AutoCAD.Runtime.Exception exc)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{

            }

        }


        
#endregion

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值