[每日一码] 改变显示顺序的代码
Acad::ErrorStatus changeDrawOrder(AcDbObjectId parent, AcDbObjectIdArray &childArray, AcEdDrawOrderCmdType variant){
if (childArray.isEmpty()) return Acad::eInvalidInput;
Acad::ErrorStatus es = Acad::eOk;
AcDbSortentsTable *pSortTab = NULL;
AcDbObjectId spaceId = AcDbObjectId::kNull;
AcDbEntityPointer pEnt(childArray.first(),AcDb::kForRead);
if (pEnt.openStatus() == Acad::eOk)
{
spaceId = pEnt->ownerId();
pEnt->close();
}
if (!spaceId.isNull())
{
AcDbBlockTableRecordPointer pBTR(spaceId,AcDb::kForRead);
if (pBTR.openStatus() == Acad::eOk)
{
if (pBTR->getSortentsTable(pSortTab, AcDb::kForWrite, true) == Acad::eOk)
{
switch (variant)
{
case kDrawOrderBottom:
es = pSortTab->moveToBottom(childArray);
break;
case kDrawOrderTop:
es = pSortTab->moveToTop(childArray);
break;
case kDrawOrderBelow:
es = pSortTab->moveBelow(childArray,parent);
break;
case kDrawOrderAbove:
es = pSortTab->moveAbove(childArray,parent);
break;
}
pSortTab->close();
}
}
}
return es;
} ads采用name entName;
ads采用point entpoint;
if (acedEntSel(采用T("\nlayer:"),entName,entpoint)!=RTNORM)
{
return;
}
AcDbObjectId layerId;
acdbGetObjectId(layerId,entName);
AcDbEntity *pEnt;
acdbOpenObject(pEnt,layerId,AcDb::kForWrite);
TCHAR *layerName=pEnt->layer();
pEnt->close();
struct resbuf *rb;
ads采用name ssname;
rb=acutBuildList(8,layerName,RTNONE);
int rc=acedSSGet(采用T("X"),NULL,NULL,rb,ssname);
AcDbObjectIdArray objIds;
if (rc!=RTNORM)
{
acutRelRb(rb);
return;
}
long length;
acedSSLength(ssname,&length);
acutPrintf(采用T("\nlayer%sall%d个"),layerName,length);
for (int i=0;i<length;i++)
{
ads采用name ent;
acedSSName(ssname,i,ent);
AcDbObjectId objId;
acdbGetObjectId(objId,ent);
objIds.append(objId);
}
changeDrawOrder(NULL,objIds,kDrawOrderTop);
//acedDrawOrderInherit(NULL,objIds,::kDrawOrderTop);
acedSSFree(ssname);
acutDelString(layerName);
if (rb!=NULL)
{
acutRelRb(rb);
} 改变选择的实体显示顺序到最下
static void MoveToBottom(void)
{
ads采用point p;
ads采用name en;
Acad::ErrorStatus es;
if (acedEntSel(L"\nSelect entity: ",en,p) == RTNORM) {
AcDbObjectId id; acdbGetObjectId(id,en);
AcDbSortentsTable *pSortTab = NULL;
AcDbObjectId spaceId = acdbCurDwg()->currentSpaceId();
AcDbObjectPointer<AcDbBlockTableRecord> pBTR(spaceId,AcDb::kForRead);
if ((es = pBTR.openStatus()) == Acad::eOk) {
if ((es = pBTR->getSortentsTable(pSortTab, AcDb::kForWrite, true)) == Acad::eOk) {
AcDbObjectIdArray ar; ar.append(id);
pSortTab->moveToBottom(ar);
pSortTab->close();
} else {
acutPrintf(L"\nError open AcDbSortentsTable: %s",acadErrorStatusText(es));
}
} else {
acutPrintf(L"\nError open AcDbBlockTableRecord: %s",acadErrorStatusText(es));
}
}
}
页:
[1]