05-ObjectArx-创建文字

元气小坏坏 提交于 2020-03-01 10:17:30

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.实现效果

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!