CAD二次开发学习笔记七(创建文字)

在CreateEnt.h中添加函数声明
大气象
//单行文字
static AcDbObjectId CreateText(const AcGePoint3d& ptInsert,const ACHAR* text
    ,AcDbObjectId style 
= AcDbObjectId::kNull,double height=2.5,double rotation=0);
//多行文字
static AcDbObjectId CreateMText(const AcGePoint3d& ptInsert,const ACHAR* text
    ,AcDbObjectId style 
= AcDbObjectId::kNull,double height=2.5,double width=10);

 

在CreateEnt.cpp中添加函数实现
大气象
//创建文字
AcDbObjectId CCreateEnt::CreateText(const AcGePoint3d& ptInsert,const ACHAR* text
                                    ,AcDbObjectId style,
double height,double rotation)
{
    AcDbText 
*pText = new AcDbText(ptInsert,text,style,height,rotation);
    
return CCreateEnt::PostToModelSpace(pText);
}
//多行文字
AcDbObjectId CCreateEnt::CreateMText(const AcGePoint3d& ptInsert,const ACHAR* text
                                     ,AcDbObjectId style,
double height,double width)
{
    AcDbMText 
*pMText = new AcDbMText();
    
//设置多行文字的特性
    pMText->setTextStyle(style);
    pMText
->setContents(text);
    pMText
->setLocation(ptInsert);
    pMText
->setTextHeight(height);
    pMText
->setWidth(width);
    pMText
->setAttachment(AcDbMText::kBottomLeft);
    
return CCreateEnt::PostToModelSpace(pMText);
}

 

调用
//创建单行文字
AcGePoint3d ptInsert(0,4,0);
CCreateEnt::CreateText(ptInsert,_T(
"abck中文"));
//创建多行文字
ptInsert.set(0,0,0);
CCreateEnt::CreateMText(ptInsert,_T(
"http://www.weiqi9d.com"));

显示中文的时候可能会显示成????
可以修改文字样式:格式->文字样式
posted @ 2011-02-23 16:31  大气象  阅读(3230)  评论(0编辑  收藏  举报
http://www.tianqiweiqi.com