//
// 问题描述,我有一个模板文件路径 c:/MapMaper/TCAD01.dwt ,其中有9种块,
//块名分别为 1,2,3,4,5,6,7,8,9 我想做的是,在当前文档中插入c:/MapMaper/TCAD01.dwt
//中定义过的块,以下代码命令为 InsertBlock_1(其功能为在当前文档中插入块名为1的块)
//开发思路为:首先将块1克隆到当前文档中来,然后再以正常的方式插入一个块引用。
//
// 遇到的问题:我想让CAD以后台的方式打开TCAD01.dwt,当我想取得块1的ObjectID时
//系统说没找到(可以用for语句测试,代码地81行)可是当我以前台方式打开时(将第79,80
//行注销将82行打开)就可以访问到块1,地95行后的代码还没有测试不知道写的对不对,请求
//各位帮助解决。
//
//
// 万分感谢!!!
// 沈阳 杜冰
//
// ObjectARX defined commands, created by [六月/25/2002] ,
#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
}
// 问题描述,我有一个模板文件路径 c:/MapMaper/TCAD01.dwt ,其中有9种块,
//块名分别为 1,2,3,4,5,6,7,8,9 我想做的是,在当前文档中插入c:/MapMaper/TCAD01.dwt
//中定义过的块,以下代码命令为 InsertBlock_1(其功能为在当前文档中插入块名为1的块)
//开发思路为:首先将块1克隆到当前文档中来,然后再以正常的方式插入一个块引用。
//
// 遇到的问题:我想让CAD以后台的方式打开TCAD01.dwt,当我想取得块1的ObjectID时
//系统说没找到(可以用for语句测试,代码地81行)可是当我以前台方式打开时(将第79,80
//行注销将82行打开)就可以访问到块1,地95行后的代码还没有测试不知道写的对不对,请求
//各位帮助解决。
//
//
// 万分感谢!!!
// 沈阳 杜冰
//
// ObjectARX defined commands, created by [六月/25/2002] ,
#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
}