1.实体类中添加文字和多行文字
CwEntity.h
static AcDbObjectId CreateText(const AcGePoint3d &ptInsert,const ACHAR *text,AcDbObjectId style=AcDbObjectId::kNull,double height=3.0,double rotation=0);
static AcDbObjectId CreateMText(const AcGePoint3d &ptInsert,const ACHAR *text,AcDbObjectId style=AcDbObjectId::kNull,double height=3.0,double width=20);
CwEntity.cpp
AcDbObjectId CwEntity::CreateText(const AcGePoint3d &ptInsert,const ACHAR *text,AcDbObjectId style/*=AcDbObjectId::kNull*/,double height/*=3.0*/,double rotation/*=0*/)
{
AcDbText *pText=new AcDbText(ptInsert,text,style,height,rotation);
return CwDatabase::PostToModelSpace(pText);
}
AcDbObjectId CwEntity::CreateMText(const AcGePoint3d &ptInsert,const ACHAR *text,AcDbObjectId style/*=AcDbObjectId::kNull*/,double height/*=3.0*/,double width/*=10*/)
{
AcDbMText *pMText=new AcDbMText();
//设置多行文字特性
pMText->setTextStyle(style);
pMText->setContents(text);
pMText->setLocation(ptInsert);
pMText->setTextHeight(height);
pMText->setWidth(width);
pMText->setAttachment(AcDbMText::kTopLeft);
return CwDatabase::PostToModelSpace(pMText);
}
2.添加实现效果
Commands.h
void CreateText();
Commands.cpp
void CreateText()
{
//单行文字
AcGePoint3d pt(0,5,0);
CwEntity::CreateText(pt,_T("床前明月光"));
//多行文字
pt.set(0,0,0);
CwEntity::CreateMText(pt,_T("床前明月光,疑是地上霜,举头望明月,低头思故乡。"));
}
注册命令
CwEditor::AddCommand(_T("CreateText"),ACRX_CMD_MODAL,CreateText);
3.实现效果
来源:oschina
链接:https://my.oschina.net/u/3876440/blog/3182733