找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1375|回复: 2

ARX获得XREF文件的路径(包括嵌套)内附代码....

[复制链接]

已领礼包: 145个

财富等级: 日进斗金

发表于 2002-1-10 18:15:20 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
HOW TO RETAIN THE XREFS OF AN INSERTED SOURCE DRAWING
Product AUTOCAD  Author BOLAN,SHAWN
Date 26-MAY-99  Document ID 34804
Expiration date    Attachments  
Keywords API_R13_BAD; API_R14_OK; API_TAHOE_OK; ARX; OBJECTARX

Developer Consulting Group technical solution. Autodesk confidential, for ADN members only. Please read the disclaimer

Question


I am copying a number of drawings into the one drawing using wblock/insert,
similar to the actions taken in the clones sample function, clone3().
However, if the drawing being copied has an external reference in it, it is
not correctly copied. How do I carry the XREF over into the target drawing?


Answer


Some side effects occur when a source drawing with XREFs is inserted into a
target drawing. This behavior is not confined to the ObjectARX API only. It
can be replicated in AutoCAD by performing the following steps:

1) Create a drawing which contains an XRef,
2) Save it,
3) Create a new drawing,
4) Use the "Insert" command and insert the previously created drawing in the
actual one.

AcDbDatabase::insert(pDb) on a source database with a XREF attached results
in a target database that contains a block table record with the name of the
XREF. But, the BTR contains an extraneous AcDbText entity in place of
entities contained in the XREF's modelspace. This AcDbText entity therefore
holds no useful info on tracing where the original XREF resides nor what the
drawing contains.

If the source contains an overlaid XREF, a different behavior occurs upon an
ARX insert: The target contains a block table record with the same name for
the XREF, but the record is empty - no entities whatsoever.

So in ObjectARX, if you want to retain the XREF's intact, you basically need
to bind them to their containing database before issuing an insert so that
the target database won't drop or mutate them. Once inserted into the target
database, former XREF blocks will appear as regular block table records, but
with the crucial distinction of a pathname citing the drawing from which the
binding occurred. In other words, unlike a basic block table record, a call
to AcDbBlockTableRecord::pathName() will not return NULL even though XREF
status shows "kXrfNotAnXref".    Gleaning the XREF pathnames from the target
database's block records, you should be able to restore XREF connections via
AutoCAD XREF-Attach. Of course, this also entail cleanup because you'll have
to erase the unresolved XREF block table records that were initially inserted
into the target. Therefore, it's easier just to leave the bound XREFs
untouched in the target DWG.


void copyDBIn() {
     AcDbBlockTable *pBlockTable;
     AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();

     pDb->getBlockTable(pBlockTable,AcDb::kForRead);
     // We have to iterate through the block table and look for XREF's: //
     AcDbBlockTableIterator* pIterator;
     AcDbBlockTableRecord *pBlockTableRec;
     pBlockTable->newIterator( pIterator );

     AcDbBlockTable *pDestBlockTable;
     AcDbBlockTableRecord *pDestBlockTableRec;

     // Will convert attached XREFs into AcDbText and overlaid XREFs are
dropped
     // finalDB->insert(*matr, pDb, Adesk::kTrue);
     AcDbDatabase *xrefDB;
     AcDbObjectId newXrefBlockId;

     for (pIterator->start(); !pIterator->done(); pIterator->step())  {
         Acad::ErrorStatus es = pIterator->getRecord( pBlockTableRec,
AcDb::kForRead );  
         // Is it an XREF?
         if ( pBlockTableRec->isFromExternalReference() ==
Adesk::kTrue ||
             pBlockTableRec->isFromOverlayReference() ==
Adesk::kTrue )  {
             AcDbObjectId recordId;

             char *xrefBlockName;
             pBlockTableRec->getName(xrefBlockName);
             pBlockTableRec->close();

             if ( RTNORM != ads_command( RTSTR, "_.-XREF", RTSTR,
"_BIND", RTSTR,
                 xrefBlockName, RTNONE )) {
                 delete [] xrefBlockName;
                 return;
             }
             delete [] xrefBlockName;
         }
     }
     pBlockTable->close();

     AcGeMatrix3d *matr= new AcGeMatrix3d();
     AcDbDatabase *finalDB = new AcDbDatabase();
     finalDB->insert(*matr, pDb);
     
     finalDB->saveAs("target.dwg");
     
     delete matr;
     delete finalDB;
}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2006-8-17 12:26:38 | 显示全部楼层
晓东这么好的帖子怎么没有人来顶呢!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2006-10-23 14:24:24 | 显示全部楼层
晓东院长,恐怕这个问题只能问你了,我实在是找不到相关的资料呀,对于插入了外部参照的图中,参照的插入点,比例的相关信息怎么得到呢?


  1. 1if ((es = acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead)) == Acad::eOk)
  2. 2{
  3. 3    if ((es = pBlockTable->getAt(blockname, pBlockRecord, AcDb::kForRead)) == Acad::eOk)
  4. 4    {
  5. 5        ads_printf("pBlockTable->getAt()成功。\n");    //for test
  6. 6
  7. 7        AcDbBlockReferenceIdIterator* pIter;
  8. 8        if (pBlockRecord->newBlockReferenceIdIterator(pIter) == Acad::eOk)
  9. 9        {
  10. 10            ads_printf("pBlockRecord->newBlockReferenceIdIterator()成功。\n");    //for test
  11. 11            for (pIter->start(); !pIter->done(); pIter->step())
  12. 12            {
  13. 13                ads_printf("迭代中。\n");    //for test
  14. 14                AcDbBlockReference* pBlockRef = NULL;
  15. 15                if (pIter->getBlockReference(pBlockRef, AcDb::kForRead) == Acad::eOk)
  16. 16                {
  17. 17                    i++;
  18. 18                    ads_printf("第%d个图:", i);
  19. 19                    AcGePoint3d pos = pBlockRef->position();
  20. 20                    ads_printf("位置(%f,%f),", pos[0], pos[1]);
  21. 21                    AcGeScale3d scale = pBlockRef->scaleFactors();
  22. 22                    ads_printf("缩放因子(%f,%f)\n", scale[0], scale[1]);
  23. 23                }
  24. 24            }
  25. 25            delete pIter;
  26. 26        }
  27. 27        pBlockRecord->close();
  28. 28    }
  29. 29    pBlockTable->close();
  30. 30}

复制代码

用上面的这段代码得到的参照迭代器怎么会是空的呢?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-15 04:51 , Processed in 0.334560 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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