块引用中的属性定义文字类
class McDbAttribute : public McDbText;
dbents.h
例如:遍历块中所有的属性定义文字
void CTestCommands::ReadBlockReferenceAttribute() { ads_name entName; ads_point pt; if(acedEntSel(_T("选择属性块实体:"),entName,pt) != RTNORM) { return; } AcDbObjectId objId; if(acdbGetObjectId(objId,entName) != Acad::eOk) return; AcDbObjectPointer<AcDbBlockReference> spBlkRef(objId,AcDb::kForRead); if(spBlkRef.openStatus() != Acad::eOk) { acutPrintf(_T("n 选择的实体不是一个块引用")); return; } AcDbObjectIterator* pAttribIter = spBlkRef->attributeIterator(); if(pAttribIter != NULL) { acutPrintf(_T("n 块的属性值为:")); for(;!pAttribIter->done();pAttribIter->step() ) { AcDbObjectPointer<AcDbAttribute> spAttribute(pAttribIter->objectId(),AcDb::kForRead); acutPrintf(_T("n %s"),spAttribute->textStringConst()); } acutPrintf(_T("n")); delete pAttribIter; } else { acutPrintf(_T("n 选择的不块不带属性")); } }
插入属性块的属性
void CTestCommands::InsertBlockRef() { CString sBlkName = _T("TestBlkName"); AcDbObjectId blkRecId; { AcDbBlockTableRecordPointer spBlkRec(sBlkName,acdbCurDwg(),AcDb::kForRead); if(spBlkRec.openStatus() == Acad::eOk) { blkRecId = spBlkRec->objectId(); } else { CString sT; sT.Format(_T("当前图上没有定义块记录名为:%s的块"),sBlkName); AfxMessageBox(sT); return; } } AcGePoint3d pos(0,0,0); std::auto_ptr<AcDbBlockReference> spBlkRef(new AcDbBlockReference); spBlkRef->setBlockTableRecord(blkRecId); spBlkRef->setPosition(pos); spBlkRef->setScaleFactors(10); spBlkRef->setRotation(0.0 * 3.14159265 / 180.0); CInsertBlockJig jig(spBlkRef.get()); AcGePoint3d insertPt; if(jig.DoIt(insertPt) ) { spBlkRef->setPosition(insertPt); AddToModelSpace(spBlkRef.get(),acdbCurDwg(),false); // 设置创建块属性定义文字。 McGeMatrix3d blkMat = spBlkRef->blockTransform(); AcDbObjectPointer<AcDbBlockTableRecord> spBlkRec(blkRecId,McDb::kForRead); if(spBlkRec.openStatus() == Acad::eOk) { McDbBlockTableRecordIterator* pIterator = NULL; spBlkRec->newIterator(pIterator); if(pIterator != NULL) { std::auto_ptr<McDbBlockTableRecordIterator> spIterator(pIterator); for(;!pIterator->done();pIterator->step()) { AcDbObjectId entId; pIterator->getEntityId(entId); AcDbObjectPointer<McDbAttributeDefinition> spAttribDef(entId,AcDb::kForRead); if(spAttribDef.openStatus() != Acad::eOk) { continue; } if(spAttribDef->isInvisible() ) { continue; } McDbAttribute* pAttrib = new McDbAttribute; pAttrib->setPosition(spAttribDef->position() ); pAttrib->setAlignmentPoint(spAttribDef->alignmentPoint()); pAttrib->setOblique(spAttribDef->oblique() ); pAttrib->setRotation(spAttribDef->rotation() ); pAttrib->setHeight(spAttribDef->height() ); pAttrib->setColor(spAttribDef->color() ); pAttrib->setLayer(spAttribDef->layerId() ); pAttrib->setTextStyle(spAttribDef->textStyle()); pAttrib->setWidthFactor(spAttribDef->widthFactor() ); pAttrib->setTextString(spAttribDef->textStringConst() ); pAttrib->setHorizontalMode(spAttribDef->horizontalMode() ); pAttrib->setVerticalMode(spAttribDef->verticalMode() ); pAttrib->setTag(spAttribDef->tagConst() ); pAttrib->setInvisible(Adesk::kFalse); pAttrib->transformBy(blkMat); spBlkRef->appendAttribute(pAttrib); pAttrib->close(); } } } spBlkRef->close(); spBlkRef.release(); } }