明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1855|回复: 0

[求助]多文档和数据库写入的问题

[复制链接]
发表于 2010-6-11 09:58:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2010-6-11 11:13:42 编辑

我要实现的功能是:在cad中已经打开了一个文件,然后我提取了这个数据库中我所需要的某些实体并存入ID,然后用acDocManager再新建一个文档,然后把刚才存起来的实体写入这个新建的模型空间,可是要么写入原来的文档中,要么就写不进去,请问要如何实现呢。已经调试发现现在得问题是运行到写入的时候CAD提示不能写入请问是为什么。下面是试验代码,请各位帮帮忙吧,谢谢大家:

void main()

{

    newSyncDoc();                   

 

    AcApDocument* NewDoc;                                               //

    pDocIter = acDocManager->newAcApDocumentIterator();  //

    for ( ; !pDocIter->done(); pDocIter->step())                    //

   {                                                                                   //找到新建文档指针
        NewDoc = pDocIter->document();                               //
    }                                                                                  //
    delete pDocIter;                                                             //

 

    acDocManager->setCurDocument(NewDoc);                  //设置当前文档
    acDocManager->activateDocument(NewDoc,true);         //激活当前文档,并且第2个参数要设为ture,否则不往下运行。

    acDocManager->unlockDocument(NewDoc);                  //将新建文档解锁

    AcDbDatabase* pNewDb=NewDoc->database();        //得到新建文档连接的数据库

 

    AcDbBlockTable* pBlockTable;

    pNewDb->getSymbolTable(pBlockTable,AcDb::kForRead);

    AcDbBlockTableRecord* pBlockTableRecord;
    pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);  
    pBlockTable->close();                                                                              

   

    AcGePoint3d ptCenter(0,0,0);                                           //
    AcGeVector3d vec(0,0,1);                                                 //
    double rad=10000;                                                          //
    AcDbCircle* pCircle=new AcDbCircle(ptCenter,vec,rad);        //做了个圆写进去

    AcDbObjectId id;                                                              //
    pBlockTableRecord->appendAcDbEntity(id,pCircle);              //到这里就出错了,CAD显示写入错误

                                

    pBlockTableRecord->close();

    acDocManager->lockDocument(NewDoc);                  //将新建文档锁定

    delete pNewDb;

}

 

void newSyncDocHelper(void *pData)
{
     AcApDocument* pDoc = acDocManager->curDocument();
     if (acDocManager->isApplicationContext())

    {
          acDocManager->appContextNewDocument((const TCHAR *)pData);
          acDocManager->activateDocument(pDoc);        //激活原先的文档,否则运行到newSyncDoc()语句后不往下运行
     }

     else
     acutPrintf(_T("\nERROR: in Document context : %s\n"),pDoc->fileName());

}


void newSyncDoc()
{
     static TCHAR pData[] = _T(/*NOXLATE*/"acad.dwt");
     AcApDocument* pDoc = acDocManager->curDocument();
     if (pDoc)

    {
      acDocManager->executeInApplicationContext(newSyncDocHelper, (void *)pData);
    }   

}

 

 

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

本版积分规则

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

GMT+8, 2024-11-25 12:31 , Processed in 0.184947 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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