CAD开发小结1
2016-07-25 13:50
375 查看
1.
acutPrintf(_T("\nHello World!"));在命令行中输出Hello
World!
一般使用acedGetXXX();来获得一个用户输入的值。
int nCountNode = 3;
int nReturn;
nReturn = acedGetInt(_T("请输入一个整数然后回车:"),&nCountNode);
if(nReturn == RTNORM)
{
CString str;
str.Format(_T("%d"),nCountNode);
AfxMessageBox(_T("你输入了:") + str);
}
2. 向模型空间添加文字:
CreateEnt.h 头文件中
#pragma once
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); //投影至模型空间
};
CreateEnt.cpp
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);
}
调用文件AcrxEntryPoint.cpp中
class CZrxTemplate1App::XXXXX
{
public:
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) //在此处注册命令
3.
//创建直线
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;
}
4. 修改类modifyEnt
头文件中:
#pragma once
#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 "StdAfx.h"
#include "ModifyEnt.h"
//修改实体颜色
//在CCreateEnt中定义的图形,在CModifyEnt类中只能通过AcDbObjectId来识别并修改
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;
}
acutPrintf(_T("\nHello World!"));在命令行中输出Hello
World!
一般使用acedGetXXX();来获得一个用户输入的值。
int nCountNode = 3;
int nReturn;
nReturn = acedGetInt(_T("请输入一个整数然后回车:"),&nCountNode);
if(nReturn == RTNORM)
{
CString str;
str.Format(_T("%d"),nCountNode);
AfxMessageBox(_T("你输入了:") + str);
}
2. 向模型空间添加文字:
CreateEnt.h 头文件中
#pragma once
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); //投影至模型空间
};
CreateEnt.cpp
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);
}
调用文件AcrxEntryPoint.cpp中
class CZrxTemplate1App::XXXXX
{
public:
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) //在此处注册命令
3.
//创建直线
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;
}
4. 修改类modifyEnt
头文件中:
#pragma once
#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 "StdAfx.h"
#include "ModifyEnt.h"
//修改实体颜色
//在CCreateEnt中定义的图形,在CModifyEnt类中只能通过AcDbObjectId来识别并修改
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;
}
相关文章推荐
- Win7系统CAD字体怎么安装?Win7系统CAD字体安装教程
- win10提示CAD丢失ac1st16.dll两种解决方法
- win10企业版安装CAD Electrical2016提示缺少.net4.5该怎么办?
- DWG and DGN file viewer
- AutoCAD 2007 简体中文版
- 文秀才文档管理系统文档管理,CAD, 图纸管理, 百度文库, 文档在线预览
- cad打印设置横向的解决方法
- 【转载】CAD快捷键
- CAD Import .NET支持AutoCAD DWG 2013
- 近来写一个三维家居软件的历程
- autocad2004的那些基本设计功能 满足基本用户需求
- autocad2004的那些基本设计功能 满足基本用户需求
- WPF中使用WinForm控件预览DWG文件(学习笔记)
- 像风一样自由
- T20调出 “经典模式”,大家可以试试~~
- java平台读写dxf文件
- CAD Import .NET支持AutoCAD DWG 2013
- SAP与CAD图集成
- SAP与CAD图集成
- ICoverageAnnotationFeature注记字符串内容获取