找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 125|回复: 0

[每日一码] ARX实例代码--获得XREF的路径而不管是否在图中保存

[复制链接]

1

主题

0

回帖

33

积分

管理员

积分
33
发表于 2024-3-14 20:49:38 | 显示全部楼层 |阅读模式
  1. Acad::ErrorStatus getXrefPath( AcDbObjectId pId, const char *&pName )
  2. {
  3.     AcDbObject *pObj,*pRecObj;
  4.     AcDbBlockReference *pBlkRef;
  5.     AcDbObjectId pBTRId;
  6.     AcDbBlockTableRecord* pRec;
  7.     Acad::ErrorStatus es;
  8.     //    open entiry
  9.     es = acdbOpenObject(pObj, pId, AcDb::kForRead);
  10.     assert(es == Acad::eOk);
  11.     if(pObj->isKindOf(AcDbBlockReference::desc()))    // Is it a blockreference?
  12.     {
  13.         pBlkRef = AcDbBlockReference::cast(pObj);
  14.         assert( pBlkRef );
  15.         // get ID of the block table record that pObj referenced.
  16.         pBTRId = pBlkRef->blockTableRecord();
  17.         pObj->close();
  18.         // open the block table record that pObj referenced.
  19.         es = acdbOpenObject(pRecObj, pBTRId, AcDb::kForRead);
  20.         assert(es == Acad::eOk);
  21.         if(pRecObj->isKindOf(AcDbBlockTableRecord::desc())) // Is it a block table record?
  22.         {
  23.             pRec = AcDbBlockTableRecord::cast(pRecObj);
  24.             assert( pRec );
  25.             if( pRec->isFromExternalReference() )    // Is it a XREF?
  26.             {
  27. // The following lines apply to all conditions, retaining path information or not
  28.                 pName =pRec->xrefDatabase(true)->originalFileName();
  29. //    The following line just apply to XREF retaining the path information when inserted
  30. //                pRec->pathName(pName);    // get path name if retained when insert
  31.                 if(pName)
  32.                     es = Acad::eOk;
  33.                 else
  34.                     es = Acad::eInvalidInput;
  35.             }
  36.             else
  37.                 es = Acad::eInvalidInput;
  38.         }
  39.         else
  40.             es = Acad::eInvalidInput;
  41.     }
  42.     else
  43.     {
  44.         pObj->close();
  45.         es = Acad::eInvalidInput;
  46.     }
  47.     pRecObj->close();    // close XREF object
  48.     return es;
  49. }
  50. //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.
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2024-12-29 21:42 , Processed in 0.130254 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表