明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1845|回复: 4

这样插入外部块?请大家帮帮忙看看那里错了

[复制链接]
发表于 2008-6-9 09:02:00 | 显示全部楼层 |阅读模式

 AcDbObjectId blockId ;

 AcDbDatabase *pDb=new AcDbDatabase(Adesk::kFalse);
 pDb->readDwgFile(name);
 blockId=pDb->xrefBlockId();

AcDbBlockReference *pBlkRef =new AcDbBlockReference ;
pBlkRef->setBlockTableRecord (blockId) ;
pBlkRef->setScaleFactors(AcGeScale3d(Scale,Scale,Scale));
pBlkRef->setPosition(pt) ;
pBlkRef->setRotation (Rotation) ;

AcDbBlockTable *pBlockTable ;
acdbHostApplicationServices()->workingDatabase()->getBlockTable (pBlockTable, AcDb::kForRead) ;
AcDbBlockTableRecord *pBlockTableRecord ;
pBlockTable->getAt (ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite) ;
pBlockTable->close () ;
pBlockTableRecord->appendAcDbEntity(pBlkRef);
pBlockTableRecord->close();
pBlkRef->close();

运行的时候提示** 未定义的块 #-1

发表于 2008-6-15 20:51:00 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2008-6-17 08:55:00 | 显示全部楼层

同问

我试着用一个insert()函数来插入块。但是insert()函数老是没执行成功,没返回 Acad::eOk

也是提示找不到块定义

发表于 2008-6-17 10:55:00 | 显示全部楼层

你这样试试:

HDR_API BOOL fdm_InsertDwgFile(const TCHAR *FileName,const AcGePoint3d &insPt,AcDbObjectId &BlkRefId,const double ang,const TCHAR *lay)
{
  BOOL state=FALSE;
  TCHAR FullPath[128];

  if(ads_findfile(FileName,FullPath)==RTNORM)
  {
    AcDbDatabase *pDb=new AcDbDatabase(Adesk::kFalse);

    if(pDb->readDwgFile(FullPath)==Acad::eOk)
    {
      if(pDb!=NULL)
      {
        AcDbObjectId ObjId;

        if(acdbCurDwg()->insert(ObjId,_T("*U"),pDb)==Acad::eOk)
        {
          AcDbObjectId ReferenceId=AcDbObjectId::kNull;
          AcDbBlockReference *pReference=new AcDbBlockReference;
          pReference->setBlockTableRecord(ObjId);
          pReference->setPosition(insPt);
          pReference->setRotation(ang);
          pReference->setLayer(lay);
          if(fdm_addToModelSpace(BlkRefId,pReference)==Acad::eOk)
          {
            state=TRUE;
          }
          else delete pReference;
        }
        delete pDb;
      }     
    }
  }
 
  return state;
}

//将实体加入到(模型/图纸)空间
HDR_API Acad::ErrorStatus fdm_addToModelSpace(AcDbObjectId &ObjId,AcDbEntity *pObj,BOOL IsToMs)
{
  AcDbBlockTable *pBlockTable;
 AcDbBlockTableRecord *pSpaceRecord;
  Acad::ErrorStatus es;

  es=acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForRead);
 if(es==Acad::eOk)
  {
    if(IsToMs) es=pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord,AcDb::kForWrite);
    else es=pBlockTable->getAt(ACDB_PAPER_SPACE,pSpaceRecord,AcDb::kForWrite);
   if(es==Acad::eOk)
    {
      es=pSpaceRecord->appendAcDbEntity(ObjId,pObj);
      if(es==Acad::eOk) pObj->close();
     pSpaceRecord->close();
    }
    pBlockTable->close();
  }

 return es;
}

 楼主| 发表于 2008-6-17 19:40:00 | 显示全部楼层

非常感谢!

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

本版积分规则

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

GMT+8, 2024-11-25 16:01 , Processed in 0.193837 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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