马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- 问题:
- 在插入 图中的XREF没有保留路径信息时候,如何获得路径名? AcDbBlockTableRecord::pathName 仅能获得保存的路径,是否有另外的API方法能获得完整的路径名?
复制代码
- 解决方案:
- 没有一个直接简单的API方法获得,但是要完成这个,可以用AcDbBlockTableRecord::xrefDatabase(bool incUnres = false) 来打开XREF文件的数据库,然后用AcDbDatabase::getFilename(const char*&
- pOutput) 获得完整的路径,下面代码演示了如何做,具体看代码的注释。
复制代码
 - Acad::ErrorStatus getXrefPath( AcDbObjectId pId, const char *&pName )
- {
- AcDbObject *pObj,*pRecObj;
- AcDbBlockReference *pBlkRef;
- AcDbObjectId pBTRId;
- AcDbBlockTableRecord* pRec;
- Acad::ErrorStatus es;
- // open entiry
- es = acdbOpenObject(pObj, pId, AcDb::kForRead);
- assert(es == Acad::eOk);
- if(pObj->isKindOf(AcDbBlockReference::desc())) // Is it a blockreference?
- {
- pBlkRef = AcDbBlockReference::cast(pObj);
- assert( pBlkRef );
- // get ID of the block table record that pObj referenced.
- pBTRId = pBlkRef->blockTableRecord();
- pObj->close();
- // open the block table record that pObj referenced.
- es = acdbOpenObject(pRecObj, pBTRId, AcDb::kForRead);
- assert(es == Acad::eOk);
- if(pRecObj->isKindOf(AcDbBlockTableRecord::desc())) // Is it a block table record?
- {
- pRec = AcDbBlockTableRecord::cast(pRecObj);
- assert( pRec );
- if( pRec->isFromExternalReference() ) // Is it a XREF?
- {
- // The following lines apply to all conditions, retaining path information or not
- pName =pRec->xrefDatabase(true)->originalFileName();
- // The following line just apply to XREF retaining the path information when inserted
- // pRec->pathName(pName); // get path name if retained when insert
- if(pName)
- es = Acad::eOk;
- else
- es = Acad::eInvalidInput;
- }
- else
- es = Acad::eInvalidInput;
- }
- else
- es = Acad::eInvalidInput;
- }
- else
- {
- pObj->close();
- es = Acad::eInvalidInput;
- }
- pRecObj->close(); // close XREF object
- return es;
- }
- //Please bear in mind that the above code will retrieve the path name of the copied drawing instead of the original drawing if XLOADCTL is set to 2.
|