1. acutPrintf(_T("\nHello World!"));在命令行中输出Hello World!
一般使用acedGetXXX();来获得一个用户输入的值。
int nReturn;
nReturn = acedGetInt(_T("请输入一个整数然后回车:"),&nCountNode);
if(nReturn == RTNORM)
{
CString str;
str.Format(_T("%d"),nCountNode);
AfxMessageBox(_T("你输入了:") + str);
}
class CCreateEnt:public AcDb
{
public:
CCreateEnt();
//单行文字
static AcDbObjectId CreateText(const AcGePoint3d& ptInsert, const ACHAR* text //ptInsert为文字的3维空间坐标点 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);
~CCreateEnt();
static AcDbObjectId PostToModelSpace(AcDbEntity *pEnt); //投影至模型空间
};
AcDbObjectId CCreateEnt::PostToModelSpace(AcDbEntity *pEnt)
{
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead); //获取可读的块表对象
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); //获取模型空间中可写的块表记录
AcDbObjectId entId;
Acad::ErrorStatus es = pBlockTableRecord->appendAcDbEntity(entId, pEnt); //将AcDb对象加入该块表记录中。并可显示出来
pBlockTable->close();
pBlockTableRecord->close();
pEnt->close();
return entId;
}
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 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 PostToModelSpace(pMText);
}
static void Demo_Test3(); //具体命令行函数,此处声明
private:
};
void CZrxTemplate1App::Demo_Test3() //具体命令行函数
{
//创建单行文字
AcGePoint3d ptInsert(0, 4, 0);
CCreateEnt::CreateText(ptInsert, _T("abck中文"));
//创建多行文字
ptInsert.set(0, 0, 0);
CCreateEnt::CreateMText(ptInsert, _T("http://www.weiqi9d.com"));
}
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CZrxTemplate1App)
ACED_ARXCOMMAND_ENTRY_AUTO(CZrxTemplate1App, Demo, _Test3, Test3, ACRX_CMD_MODAL, NULL) //在此处注册命令
AcDbObjectId CCreateEnt::CreateLine(AcGePoint3d ptStart,AcGePoint3d ptEnd)
{
AcDbLine * pLine = new AcDbLine(ptStart,ptEnd);
// 将实体添加到图形数据库
AcDbObjectId lineId;
lineId = PostToModelSpace(pLine);
return lineId;
}
// 创建圆
AcDbObjectId CCreateEnt::CreateCircle(AcGePoint3d ptCenter,AcGeVector3d vec, double radius)
{
AcDbCircle * pCircle = new AcDbCircle(ptCenter,vec,radius);
// 将实体添加到图形数据库
AcDbObjectId circleId;
circleId = PostToModelSpace(pCircle);
return circleId;
}
#include " StdAfx.h "
class CModifyEnt
{
public :
CModifyEnt( void );
~ CModifyEnt( void );
static Acad::ErrorStatus ChangeColor(AcDbObjectId entId,Adesk::UInt16 colorIndex);
static Acad::ErrorStatus ChangeLayer(AcDbObjectId entId,CString strLayerName);
};
.cpp文件:
#include " ModifyEnt.h "
// 修改实体颜色
Acad::ErrorStatus CModifyEnt::ChangeColor(AcDbObjectId entId,Adesk::UInt16 colorIndex)
AcDbEntity * pEntity;
// 打开图形数据库中的可写对象
acdbOpenObject(pEntity,entId,AcDb::kForWrite);
// 修改实体的颜色
pEntity -> setColorIndex(colorIndex);
// 用完之后,及时关闭
pEntity -> close();
return Acad::eOk;
}
// 改变实体所在层
Acad::ErrorStatus CModifyEnt::ChangeLayer(AcDbObjectId entId,CString strLayerName)
{
AcDbEntity * pEntity;
// 打开图形数据库中的对象
acdbOpenObject(pEntity,entId,AcDb::kForWrite);
// 修改实体的图层
pEntity -> setLayer(strLayerName);
// 用完之后,及时关闭
pEntity -> close();
return Acad::eOk;
}