插图块??
请问:用ARX怎么插入一个图块(不用CAD的命令)!谢谢!给段代码你自己参考参考
如果你要插入外部图块,也就是说,要将另一张DWG图形插入,建议使用AcDbDatabase::insert()函数,以下代码用于插入AcDbBlockReference对象,即块参考。void addBlockWithAttributes()
{
AcGePoint3d basePoint; //插入基点
if(acedGetPoint(NULL,"\n请输入图块插入点:",asDblArray(basePoint))!= RTNORM)
return;
double textAngle; //属性文字旋转角度
if(acedGetAngle(asDblArray(basePoint),"\n属性文字旋转角度:", &textAngle)!= RTNORM)
return;
double textHeight;//属性文字高度
if(acedGetDist(asDblArray(basePoint),"\n属性文字高度:", textHeight)!= RTNORM)
return;
// 定义要插入的图块ID
AcDbObjectId blockId;
defineBlockWithAttributes(blockId, basePoint,textHeight, textAngle);
// 第一步,给新的块参考对象分配内存
AcDbBlockReference *pBlkRef = new AcDbBlockReference;
// 第二步,定义好的图块ID赋给块参考对象
pBlkRef->setBlockTableRecord(blockId);
// 若使用UCS,建立UCS与WCS之间的转换
struct resbuf to, from;
from.restype = RTSHORT;
from.resval.rint = 1; // UCS
to.restype = RTSHORT;
to.resval.rint = 0; // WCS
AcGeVector3d normal(0.0, 0.0, 1.0);
acedTrans(&(normal.x), &from, &to, Adesk::kTrue,&(normal.x));
// 设置块参考对象的插入点
pBlkRef->setPosition(basePoint);
// 指定LCS角度为0.
pBlkRef->setRotation(0.0);
pBlkRef->setNormal(normal);
// 第三步,打开当前AcDb数据库模型空间块表记录
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
pBlockTable->close();
// 向模型空间添加块参考对象
AcDbObjectId newEntId;
pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
pBlockTableRecord->close();
//以上是新建块参考对象的方法,以下读出块表并设置属性值
// 第四步,打开块表记录
AcDbBlockTableRecord *pBlockDef;
acdbOpenObject(pBlockDef, blockId, AcDb::kForRead);
// 建立块表记录浏览器,遍历块表
AcDbBlockTableRecordIterator *pIterator;
pBlockDef->newIterator(pIterator);
AcDbEntity *pEnt;
AcDbAttributeDefinition *pAttdef;
for (pIterator->start(); !pIterator->done();pIterator->step())
{
pIterator->getEntity(pEnt, AcDb::kForRead);
// 保证对象是块参考对象,且属性非常量
pAttdef = AcDbAttributeDefinition::cast(pEnt);
if (pAttdef != NULL && !pAttdef->isConstant()) {
// 因属性非常量,需要定义一个属性对象
AcDbAttribute *pAtt = new AcDbAttribute();
pAtt->setPropertiesFrom(pAttdef);
pAtt->setInvisible(pAttdef->isInvisible());
basePoint = pAttdef->position();
basePoint += pBlkRef->position().asVector();
pAtt->setPosition(basePoint);
pAtt->setHeight(pAttdef->height());
pAtt->setRotation(pAttdef->rotation());
pAtt->setTag("Tag");
pAtt->setFieldLength(25);
char *pStr = pAttdef->tag();
pAtt->setTag(pStr);
free(pStr);
pAtt->setFieldLength(pAttdef->fieldLength());
// 输入属性值
pAtt->setTextString("Assigned Attribute Value");
AcDbObjectId attId;
pBlkRef->appendAttribute(attId, pAtt);
pAtt->close();
}
pEnt->close(); // 不要忘记释放内存
}
delete pIterator;
pBlockDef->close();
pBlkRef->close();
}
非常感谢
非常感谢!!!还有没有别的方法?
还有没有别的方法?供参考
AcDbEntity* copyFromId(AcDbObjectId objId){
AcDbEntity *pRet=NULL;
static AcDbObjectId modelSpaceId;
if (modelSpaceId.isNull())
{
AcDbBlockTable *pBlkTbl;
getBlockTable(pBlkTbl, AcDb::kForRead);
pBlkTbl->getAt(ACDB_MODEL_SPACE, modelSpaceId);
pBlkTbl->close();
}
AcDbObjectIdArray objIds;
objIds.append(objId);
AcDbIdMapping idMap;
wblockCloneObjects(objIds, modelSpaceId, idMap, AcDb::kDrcIgnore);
AcDbIdPair idPair(objId, AcDbObjectId::kNull, false, false);
if (idMap.compute(idPair) == TRUE && idPair.value() != NULL)
{
acdbOpenObject(pRet, idPair.value(), AcDb::kForWrite);
}
return pRet;
}
该成员函数实现在不同的数据库中复制对象。参数中objId是另一个图形数据库的对象Id返回的pRet是已经存在于this图形数据库的实体。 <A name=17100><FONT color=#000066><B>leeyeafu</B></FONT></A>版主你好,初学ARX,请多指点:
defineBlockWithAttributes(blockId, basePoint,textHeight, textAngle); //未定义
谢谢 请问<A name=17100><FONT color=#000066><B>leeyeafu</B></FONT></A>版主,插入块的时候,如何使块分解插入到当前图形中? 请问版主 上面那个程序的 头文件是 什么?
谢谢
页:
[1]