下面为OBJECT-ARX创建多行文本的代码,记录
McDbMText* Mx::AddMText(IN McDbBlockTableRecord* pBlkRec,
IN LPCTSTR pszContents,
IN McGePoint3d pos,
IN double width,
IN double textHeight,
IN double rotation /*= 0.0*/,
IN McGeVector3d direction /*= McGeVector3d::kXAxis*/,
IN int attachment /*= McDbMText::kTopLeft*/,
IN int flowDirection /*= McDbMText::kLtoR*/,
IN double dFactor /*= 1.0*/,
IN McDb::LineSpacingStyle style /* = McDb::kAtLeast*/
)
{
McDbObjectId retId;
McDbMText* pMText = new McDbMText;
pMText->setContents(pszContents);
pMText->setLocation(pos);
pMText->setWidth(width);
pMText->setTextHeight(textHeight);
pMText->setRotation(rotation);
pMText->setDirection(direction);
pMText->setAttachment(McDbMText::AttachmentPoint(attachment) );
pMText->setFlowDirection(McDbMText::FlowDirection(flowDirection) );
pMText->setLineSpacingFactor(dFactor);
pMText->setLineSpacingFactor(style);
pBlkRec->appendAcDbEntity(retId,pMText);
return pMText;
}
实例:
前期准备
Acad::ErrorStatus es;
AcDbDatabase * pDatabase;
AcDbBlockTable *pBlockTable;
McDbBlockTableRecord * pBTableRec1;
pDatabase = MxDraw::GetDatabase(MxDraw::GetCurOcxHandle());
es = pDatabase->getBlockTable(pBlockTable,McDb::kForRead);
if(es != Acad::eOk){
AfxMessageBox(_T("获得块表失败"));
}
es = pBlockTable->getAt(MCDB_MODEL_SPACE, pBTableRec1,McDb::kForWrite);
if(es != Acad::eOk){
AfxMessageBox(_T("获得块记录失败"));
}
McGePoint3d pos(0,0,0);
AcDbObjectId textStyleId=CadDiyFunc::CreateTextStyle(_T("wzbzTextStyle"), _T("宋体"), 1);
方法一
McDbMText* mText = Mx::AddMText(pBTableRec1,_T("登鹳雀楼\P白日依山尽\P \P黄河入海流\P欲穷千里目\P更上一层楼"),pos,100,300,0,McGeVector3d::kXAxis,McDbMText::kTopCenter,McDbMText::kLtoR,1.0,McDb::kAtLeast);
mText->setTextStyle(textStyleId);
mText->close();
方法二
McDbObjectId retId;
McDbMText* pMText = new McDbMText;
pMText->setContents(_T("登鹳雀楼\P白日依山尽\P黄河入海流\P欲穷千里目\P更上一层楼"));
pMText->setLocation(pos);
pMText->setWidth(100);
pMText->setTextHeight(30);
pMText->setRotation(0);
pMText->setAttachment(McDbMText::AttachmentPoint(McDbMText::kTopCenter) );
pMText->setTextStyle(textStyleId);
pBTableRec1->appendAcDbEntity(retId,pMText);
pMText->close();
善后
pBTableRec1->close();
pBlockTable->close();
注:\P为换行 \P空格\P 换两行