马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Changing draworder of entities By Balaji Ramamoorthy
An MText with background mask set can hide entities that are behind it. To send the MText to the back and make the entity behind it to be visible, we can set the DrawOrder in AutoCAD using the context menu option. This can also be achieved programmatically for an entity.
Here is a sample code to send a selected entity behind. i.e., change the draworder of the selected entity to bottom.
Using ObjectARX :- static void ADSProjectSendToBottom(void)
- {
- ads_name ent;
- ads_point pt;
- Acad::ErrorStatus es;
- int ret = RTNORM;
- ret = acedEntSel( _T("\nSelect Entity: "),
- ent,
- pt
- );
- if (RTNORM != ret)
- return;
- AcDbObjectId ent_id;
- if (Acad::eOk != acdbGetObjectId( ent_id, ent ))
- return;
- configureSortents();
- AcDbEntity *pEnt;
- es = acdbOpenObject( pEnt, ent_id, AcDb::kForRead );
- if (Acad::eOk != es)
- return;
- AcDbSortentsTable *pSt = GetSortentsTableOf( pEnt );
- pEnt->close();
- if (NULL == pSt)
- return;
- AcDbObjectIdArray entity_array;
- entity_array.append( ent_id );
- pSt->moveToBottom( entity_array );
- pSt->close();
- // Send regen command or use the
- // undocumented ads_regen method.
- acDocManager->sendStringToExecute
- (
- acDocManager->curDocument(),
- L"_regen\n",
- false,
- true
- );
- }
Using AutoCAD .Net API :
- [CommandMethod("SendToBottom")]
- public void commandDrawOrderChange()
- {
- Document activeDoc
- = Application.DocumentManager.MdiActiveDocument;
- Database db = activeDoc.Database;
- Editor ed = activeDoc.Editor;
- PromptEntityOptions peo
- = new PromptEntityOptions("Select an entity : ");
- PromptEntityResult per = ed.GetEntity(peo);
- if (per.Status != PromptStatus.OK)
- {
- return;
- }
- ObjectId oid = per.ObjectId;
- SortedList<long, ObjectId> drawOrder
- = new SortedList<long, ObjectId>();
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = tr.GetObject(
- db.BlockTableId,
- OpenMode.ForRead
- ) as BlockTable;
- BlockTableRecord btrModelSpace =
- tr.GetObject(
- bt[BlockTableRecord.ModelSpace],
- OpenMode.ForRead
- ) as BlockTableRecord;
- DrawOrderTable dot =
- tr.GetObject(
- btrModelSpace.DrawOrderTableId,
- OpenMode.ForWrite
- ) as DrawOrderTable;
- ObjectIdCollection objToMove = new ObjectIdCollection();
- objToMove.Add(oid);
- dot.MoveToBottom(objToMove);
- tr.Commit();
- }
- ed.WriteMessage("Done");
- }
|