#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