【转载】CAD 克隆实体 块插入

#include "StdAfx.h" 
#include "StdArx.h" 
#include "stdafx.h" 
#include "resource.h" 
#include "acutads.h" 
#include "dbents.h" 
#include "dbpl.h" 
#include "MALLOC.h" 
#include "STDLIB.h" 
#include "acedads.h" 
#include "acutads.h" 
#include "dbmtext.h " 
#include <stdio.h> 
#include "dbapserv.h" 
#include "dbidmap.h" 
#include "dbsymutl.h" 
#include "dbsymtb.h" 
#include "actrans.h" 

//----------------------------------------------------------------------------- 
// This is command 'INSERTBLOCK_1, by [六月/25/2002], , 
void SKDInsertBlock_1() 

#ifdef OARXWIZDEBUG 
acutPrintf ("\nOARXWIZDEBUG - SKDInsertBlock_1() called."); 
#endif // OARXWIZDEBUG 



//Program Start 

//获得块的插入点 
ads_point Pnt1; 
AcGePoint3d insertPt; 
if (acedGetPoint(NULL,"\nPlease give me Insert point:",Pnt1)!=RTNORM) 

acutPrintf("\n...User Cancel\n"); 
return; 

insertPt[X]=Pnt1[X]; 
insertPt[Y]=Pnt1[Y]; 
insertPt[Z]=0; 
//对数据库操作开始 
AcDbDatabase *pCurrentDb = NULL; //用于指向当前数据库 
AcDbDatabase *pSourceDb = new AcDbDatabase;//用于指向后台数据库 
AcDbObjectId InsertblockId; //块的ObjctId 
AcDbObjectId referenceId;//快参考的ObjectId 
AcDbIdMapping pIdMap; 
AcDbObjectIdArray list; 
AcDbObjectId MyBlockId; 
AcDbBlockTable *pBlockTable = NULL; 
AcDbBlockTableRecord *pBlockTableRecord; 
char *pBlockName; 
AcDbBlockTableIterator *pLtIterator; 

//********************************************************************************* 
//以后台方式打开TCAD01.dwt数据库 
pSourceDb->readDwgFile("c:\\MapMaper\\TCAD01.dwt"); //Line 79 
pSourceDb->getSymbolTable(pBlockTable,AcDb::kForRead); //Line 80 
//以前台方式打开TCAD01.dwt数据库 
//acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable,AcDb::kForRead); //Line 82 
//*********************************************************************************** 


//以下for语句用于测试块表中的块的名称 
//!!! 问题在于如果以后台方式打开就无法访问块表,如果以前台打开(当前文档就是TCAD01.dwt)就可以 Why??? 
pBlockTable->newIterator(pLtIterator); 
for(;!pLtIterator->done();pLtIterator->step ()) 

pLtIterator->getRecord(pBlockTableRecord,AcDb::kForRead); 
pBlockTableRecord->getName(pBlockName); 
pBlockTableRecord->close(); 
acutPrintf("\n Block Name is: %s",pBlockName); 



delete pLtIterator; 
if(pBlockTable->has("1")) 

pBlockTable->getAt("1",MyBlockId); 
list.append( MyBlockId ); 
AcDbDatabase *curDb=acdbHostApplicationServices()->workingDatabase(); 
AcDbObjectId ablockId = NULL; 
AcDbSymbolUtilities::getBlockId(ablockId,ACDB_MODEL_SPACE,curDb); 
pSourceDb->deepCloneObjects (list,ablockId,pIdMap);//复制块到当前打开的文档 

AcDbBlockReference *pBlockReference = new AcDbBlockReference; 
pBlockReference->setBlockTableRecord(MyBlockId); 
pBlockReference->setPosition(insertPt); //设置插入点 
pBlockReference->setRotation(0);//设置旋转角度 
pBlockReference->setLayer("0");//为插入的图块设置图层 
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite); 
pBlockTableRecord->appendAcDbEntity(referenceId,pBlockReference); 
pBlockTable->close(); 
pBlockTableRecord->close(); 
pBlockReference->close(); 


else 

pBlockTable->close(); 
pSourceDb->closeInput(); 
delete pSourceDb; 
return; //没有图块返回 

pBlockTable->close(); 
pSourceDb->closeInput(); 
delete pSourceDb; 
//Program End 

}

转载于:https://www.cnblogs.com/lihao102/archive/2013/04/14/3020262.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值