明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2611|回复: 3

不打开CAD 读取.dwg文件内部的实体元素的信息

[复制链接]
发表于 2006-11-21 12:27:00 | 显示全部楼层 |阅读模式

在不打开CAD软件的情况下,通过程序读取.dwg文件内部的实体元素的信息,这个想法能否实现,若能实现用什么技术可以实现,希望版主和对这方面了解的同仁给与解答。

发表于 2007-1-12 11:00:00 | 显示全部楼层
有的,ODT技术就是做这个的
发表于 2007-1-16 12:15:00 | 显示全部楼层
朋友,我和你的问题一样,搞出来了没?
发表于 2007-2-24 17:41:00 | 显示全部楼层

如下代码可以实现

void
clone3()
{
    AcDbObjectId id;
    AcDbObjectIdArray list;
    AcDbDatabase extDatabase( Adesk::kFalse );
    char dwgName[_MAX_PATH];

    if (RTNORM != getFile( "Enter DWG name", "Select Drawing", "dwg",
                           dwgName ))
    {
        return;
    }
    if (Acad::eOk != extDatabase.readDwgFile( dwgName ))
    {
        acedAlert( "Error reading DWG!" );
        return;
    }
 extDatabase.
    AcDbBlockTable* pBT;
    if (Acad::eOk != extDatabase.getSymbolTable( pBT, AcDb::kForRead ))
    {
        acedAlert( "Error getting BlockTable of DWG" );
        return;
    }
    AcDbBlockTableRecord* pBTR;
    Acad::ErrorStatus es = pBT->getAt( ACDB_MODEL_SPACE, pBTR, AcDb::kForRead );
    pBT->close();
    if (Acad::eOk != es) {
        acedAlert( "Error getting model space of DWG" );
        return;
    }

    AcDbBlockTableRecordIterator* pIT;
    if (Acad::eOk != pBTR->newIterator( pIT )) {
        acedAlert( "Error iterating model space of DWG" );
        pBTR->close();
        return;
    }

    for ( ; !pIT->done(); pIT->step()) {
        if (Acad::eOk == pIT->getEntityId( id )) {
            list.append( id );

            // There is a bug in ARX that causes extension dictionaries
            // to appear to be soft owners of their contents.  This causes
     // the contents to be skipped during wblock.  To fix this we
     // must explicitly tell the extension dictionary to be a hard
     // owner of it's entries.
            //
            AcDbEntity *pEnt;
            if ( Acad::eOk == pIT->getEntity(pEnt, AcDb::kForRead)) {
                AcDbObjectId obj;
                if ((obj = pEnt->extensionDictionary())
                    != AcDbObjectId::kNull)
                {
                    AcDbDictionary *pDict = NULL;
                    acdbOpenObject(pDict, obj, AcDb::kForWrite);
                    if (pDict) {
                        pDict->setTreatElementsAsHard(Adesk::kTrue);
                        pDict->close();
                    }
                }
                pEnt->close();
            }
        }
    }

    delete pIT;
    pBTR->close();

    if (list.isEmpty()) {
        acedAlert( "No entities found in model space of DWG" );
        return;
    }

    AcDbDatabase *pTempDb;

    if (Acad::eOk != extDatabase.wblock( pTempDb, list, AcGePoint3d::kOrigin ))
    {
        acedAlert( "wblock failed!" );
        return;
    }
    if (Acad::eOk != acdbHostApplicationServices()->workingDatabase()
        ->insert( AcGeMatrix3d::kIdentity, pTempDb ))
        acedAlert( "insert failed!" );

    delete pTempDb;
}

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 20:49 , Processed in 0.269668 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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