[ARX程序]:各位高人帮个忙,有用过 AcApLayoutManager 这个类吗
请各位高人帮个忙,有用过 AcApLayoutManager 这个类吗就是创建、或复制图纸空间的类
createLayout、copyLayout主要这两个函数怎么用
谢谢!
Re: [ARX程序]:各位高人帮个忙,有用过 AcApLayoutManager 这个类吗
最初由 ksbaidu 发布请各位高人帮个忙,有用过 AcApLayoutManager 这个类吗
就是创建、或复制图纸空间的类
createLayout、copyLayout主要这两个函数怎么用
谢谢!
有的
Acad::ErrorStatus
CreateLayoutFromTemplate(
AcDbObjectId &layoutId,
AcDbObjectId &blockTableRecId,
AcDbViewport*& pVP,
const char* dwtName,
const char* entryName
)
{
Acad::ErrorStatus es;
AcDbDatabase *pDWTdb = new AcDbDatabase(false);
es = pDWTdb->readDwgFile(dwtName);
if (es == Acad::eOk )
{
//get the layout dictionary
AcDbDictionary *pDict = NULL;
es = pDWTdb->getLayoutDictionary(pDict,AcDb::kForRead);
AcDbObject *pObj = NULL;
AcDbLayout *pSrcLayout = NULL;
AcDbLayout *pNewLayout = NULL;
//copy the layout entryName from the drawing template
//or you can use the AcDbDictionaryIterator to get the required AcDbLayoutfrom the database
es = pDict->getAt(entryName, pObj, AcDb::kForWrite);
//close the dictionary
pDict->close();
if(es == Acad::eOk) // es = pDict->getAt(entryName, pObj, AcDb::kForWrite);
{
pSrcLayout = AcDbLayout::cast(pObj);
//add new layout to the current document
AcApLayoutManager *pLayoutMan = (AcApLayoutManager*)acdbHostApplicationServices()->layoutManager();
//get the name to create a new layout
char* psName;
psName = pLayoutMan->getNextNewLayoutName();
//create a new layout
pLayoutMan->setCreateViewports(Adesk::kTrue);
pLayoutMan->createLayout(psName, layoutId, blockTableRecId);
pNewLayout = pLayoutMan->findLayoutNamed(psName, TRUE);
//copy from the source layout in to the new layout
pNewLayout->copyFrom(pSrcLayout);
//open the newlayout object to refresh the list
//this required to refresh the device list
pNewLayout->upgradeOpen();
AcDbPlotSettingsValidator *pPltValid = NULL;
pPltValid = acdbHostApplicationServices()->plotSettingsValidator();
pPltValid->refreshLists(pNewLayout);
//close the layouts
pNewLayout->close();
pSrcLayout->close();
//update the layout tabs using the layout manager
pLayoutMan->updateLayoutTabs();
// copy entity from template
// Source BlockTableRecordId
AcDbObjectId sourceId = pSrcLayout->getBlockTableRecordId();
// Source BlockTableRecord
AcDbBlockTableRecord *pSource = 0;
// Open Source for Read
es = acdbOpenObject(pSource, sourceId, AcDb::kForRead);
if(es == Acad::eOk) // es = acdbOpenObject(pSource, sourceId, AcDb::kForRead);
{
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;
pSource->close();
// New BlockTableRecordId
//AcDbObjectId newId = pNewLayout->getBlockTableRecordId();
// Set this Layout Current
//es = pLayoutMan->setCurrentLayoutId(newId);
es = pLayoutMan->setCurrentLayoutId(layoutId);
AcDbDatabase *pNewDb;
es = pDWTdb->wblock( pNewDb, Idlist, AcGePoint3d::kOrigin);
acdbHostApplicationServices()->workingDatabase()->insert(AcGeMatrix3d::kIdentity, pNewDb);
delete pNewDb;
}
// delete the damnnnnnnnnn- AcDbViewPort
AcDbBlockTableRecord *pTarget = 0;
// Open Source for Read
es = acdbOpenObject(pTarget, blockTableRecId, AcDb::kForRead);
if(es == Acad::eOk)
{
AcDbBlockTableRecordIterator* pIter = 0;
pTarget->newIterator(pIter);
bool bFirst = true;
while(!pIter->done())
{
// Add all the entities to the list
AcDbEntity *pEnt = 0;
es = pIter->getEntity(pEnt, AcDb::kForRead);
if(es == Acad::eOk)
{
if (pEnt->isKindOf(AcDbViewport::desc()))
{
AcDbViewport *pVPort = (AcDbViewport *)pEnt;
es = pVPort->upgradeOpen();
if (!pVPort->isOn() )
{
if (bFirst)
{
pVPort->erase();
bFirst = false;
}
else
{
pVPort->setOn();
pVP = pVPort;
}
}
}
pEnt->close();
}
pIter->step();
}
pTarget->close();
}
}
}
delete pDWTdb;
return es;
}
谢谢rave 学习了,好代码 赞
页:
[1]