- UID
- 344993
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-11-2
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
实现快速复制另外一张图的所有布局。特别用于视口分好一张图,其他图直接复制视口,不用安装专业软件再分了。
void TOMcplayout()
{
char pSrcFile[255];
char* lyName;
const char* filea = "myfile.dwg";
struct resbuf *result = acutNewRb(RTSTR);
if (acedGetFileNavDialog("选择",filea, "dwg;eps;abc",NULL, 33, &result)!=RTNORM)
return;
strcpy(pSrcFile,result->resval.rstring);
acutRelRb(result);
char buf[10];
bool bCopyModel;
if (acedGetString(1,"复制模型空间实体<n>:",buf)!=RTNORM)
return;
if (buf[0]==0 || buf[0]=='n' || buf[0]=='N')
bCopyModel=FALSE;
else
bCopyModel=TRUE;
//acedGetString(0,"源文件名:",pSrcFile);
Acad::ErrorStatus mEs;
AcDbDatabase *pDWTdb = new AcDbDatabase(false);
if (Acad::eOk == pDWTdb->readDwgFile(pSrcFile))
{
//get the layout dictionary
AcDbDictionary *pDict = NULL;
pDWTdb->getLayoutDictionary(pDict,AcDb::kForRead);
AcDbObject *pObj = NULL;
AcDbLayout *pSrcLayout = NULL;
AcDbLayout *pNewLayout = NULL;
AcApLayoutManager *pLayoutMan = (AcApLayoutManager*)acdbHostApplicationServices()->layoutManager();
AcDbObjectId pLayoutID,pBTRId;
AcDbDictionaryIterator *pDicItr=pDict->newIterator(AcRx::kDictSorted);
for(;!pDicItr->done();pDicItr->next())
{
mEs=pDicItr->getObject(pObj,AcDb::kForRead);
if(mEs == Acad::eOk)
{
pSrcLayout=AcDbLayout::cast(pObj);
pSrcLayout->getLayoutName(lyName);
if (!bCopyModel && stricmp(lyName,"Model")==0)
continue;
pNewLayout=0;
pNewLayout=pLayoutMan->findLayoutNamed(lyName,TRUE);
if (!pNewLayout)
{
pLayoutMan->createLayout(lyName,pLayoutID,pBTRId);
mEs=acdbOpenObject(pNewLayout,pLayoutID,AcDb::kForWrite);
}
copyLayout(pNewLayout,pSrcLayout,pDWTdb);
pNewLayout->close();
pSrcLayout->close();
}
}
delete pDicItr;
pDict->close();
pLayoutMan->updateLayoutTabs();
}
delete pDWTdb;
}
void copyLayout(AcDbLayout*pNewLayout, AcDbLayout* pSrcLayout,AcDbDatabase* pSrcDoc)
{
pNewLayout->copyFrom(pSrcLayout);
//copy entitys from source layout
AcDbObjectId sourceId = pSrcLayout->getBlockTableRecordId();
AcDbObjectId newBtrId = pNewLayout->getBlockTableRecordId();
// Source BlockTableRecord
AcDbBlockTableRecord *pSource = 0,*pNewBTR=0;
// Open Source for Read
AcDbIdMapping idMap;
Acad::ErrorStatus es = acdbOpenObject(pSource, sourceId, AcDb::kForRead);
if(es == Acad::eOk)
{
//es=acdbOpenObject(pNewBTR,newBtrId,AcDb::kForWrite);
if (es==Acad::eOk)
{
AcDbBlockTableRecordIterator* pIter = 0;
pSource->newIterator(pIter);
AcDbObjectIdArray Idlist;
while(!pIter->done())
{
// Add all the entities to the list
AcDbEntity *pEnt = 0;
es = pIter->getEntity(pEnt, AcDb::kForRead);
if(es == Acad::eOk)
{
AcDbObjectId obj;
AcDbObjectId id = pEnt->objectId();
Idlist.append( id );
if((obj = pEnt->extensionDictionary()) != AcDbObjectId::kNull)
{
AcDbDictionary *pDict = 0;
acdbOpenObject(pDict, obj, AcDb::kForWrite);
pDict->setTreatElementsAsHard(Adesk::kTrue);
pDict->close();
}
pEnt->close();
}
pIter->step();
}
delete pIter;
pSrcDoc->wblockCloneObjects(Idlist,newBtrId,idMap,AcDb::kDrcReplace,false);
//pNewBTR->close();
}
pSource->close();
}
} |
|