admin 发表于 2024-3-14 20:49:38

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

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.
页: [1]
查看完整版本: [每日一码] ARX实例代码--获得XREF的路径而不管是否在图中保存