- UID
- 3
- 积分
- 3635
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2013-8-14 09:22:19
|
显示全部楼层
huangshan(460534293)于2013-08-14 09-22-19:
谁帮忙看下这个属性块怎么只有个块点,没有块文字
// 获得绘图比例尺
struct resbuf cxm;
cxm.restype = RTREAL;
acedGetVar("USERR1",&cxm);
ads_real blc,blc1;
blc = cxm.resval.rreal;
if (blc == 0.0)
{
if (acedGetReal("\n请输入比例尺",&blc1) != RTNORM)
{
blc1 = 500.00;
cxm.resval.rreal = blc1;
acedSetVar("USERR1",&cxm);
}
cxm.resval.rreal = blc1;
acedSetVar("USERR1",&cxm);
}
// 获得当前数据库的块表
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForWrite);
// 查找用户指定的块定义是否存在
CString strBlkDef;
strBlkDef.Format("%s", "GC200");
if (!pBlkTbl->has(strBlkDef))
{
acutPrintf("\n当前图形中未包含GC200的块定义!");
pBlkTbl->close();
return;
}
// 获得用户输入的块参照的插入点
AcGePoint3d basePt(0,0,0);
if (acedGetPoint(NULL, "\n输入块参照的插入点:",asDblArray(basePt)) != RTNORM)
{
pBlkTbl->close();
return;
}
char height[20];
if (acedGetString(NULL,"\n输入高程值:",height) != RTNORM)
{
pBlkTbl->close();
return;
}
// 定义图块比例系数
double xyzScale = blc * 0.001;
AcGePoint3d newbasePt(basePt.x,basePt.y,atof(height)); // 设置图块插入点
AcGePoint3d textPt(basePt.x + blc * 0.0012,basePt.y,0.0); // 设置文字插入点
double textH(blc * 0.002); // 设置文字高度
// 获得用户指定的块表记录
AcDbObjectId blkDefId;
pBlkTbl->getAt(strBlkDef,blkDefId);
// 创建块参照引用对象
AcDbBlockReference *pBlkRef = new AcDbBlockReference(newbasePt,blkDefId);
// 将块参照添加到模型空间
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite);
// 设置块比例系数
pBlkRef->setScaleFactors(xyzScale);
pBlkTbl->close();
AcDbObjectId entId;
pBlkTblRcd->appendAcDbEntity(entId,pBlkRef);
// 属性插入部分
AcDbBlockTableRecord *pBlkDefRcd; // 定义指向块表记录的指针
acdbOpenObject(pBlkDefRcd,blkDefId,AcDb::kForRead); // 获得指向块表记录的指针
if (pBlkDefRcd->hasAttributeDefinitions())
{
AcDbBlockTableRecordIterator *pIterator; // 定义遍历块表记录的浏览器
pBlkDefRcd->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();
// 设置属性插入位置
AcGePoint3d textPt = pAttDef->position();
textPt += pBlkRef->position().asVector();
pAtt->setPosition(textPt); // 设置属性位置
pAtt->setHeight(textH); // 设置属性文字的高度
pAtt->setRotation(0.0); // 设置文字旋转角度
pAtt->setHorizontalMode(AcDb::kTextLeft); // 设置水平对齐方式
pAtt->setVerticalMode(AcDb::kTextBase); // 设置垂直对齐方式
pAtt->setTextString(height); // 设置属性的缺省值
pAtt->setTag("heigth"); // 设置属性标签
pAtt->setInvisible(Adesk::kFalse); // 设置不可见选项为假
AcDbObjectId attId;
pBlkRef->appendAttribute(attId,pAtt);
pAtt->close(); // 关闭属性定义对象
}
pEnt->close(); // 关闭实体对象
}
delete pIterator; // 删除浏览器对象
}
// 关闭数据库的对象
pBlkRef->setLayer("GCD");
pBlkRef->close();
pBlkTblRcd->close();
pBlkDefRcd->close();
} |
|