#include "AcDrawManage.h"
#include "AcDbPlotSettings.h"
void AppBowen::create2dDraw()
{
// draw 2d
AfxMessageBox("draw 2d");
// 获取当前活动的Draw
AcDrawManage* pDraw = AppClient::GetActiveDrawing();
// 清屏
pDraw->ClearViewport();
// 获取当前活动的db
AcDbDatabase*pDb=pDraw->getActiveDb();
// 设置布局
AcDbBlockTableRecord* pRecord = pDb->getLayoutManage()->getBlockRecordAt(1);
// 设置打印信息
{
AcDbPlotSettings* pSetting = pRecord->getPlotSettings();
pSetting->m_mashineName = "Fax";
pSetting->m_paperName = "A0";
}
// 创建线条
{
// 标记撤销起点
pDraw->StartUndo();
// AcDb3DPolyline* pPloy = new AcDb3DPolyline(DPoint(0,0,0), DPoint(1,0,0));// 绘制简单的线条
AcDb3DPolyline* pPloy = new AcDb3DPolyline(); // 绘制一个复杂线条,多边形
// 对该线条设置样式
// 精度0.1,四舍五入
pPloy->m_lineGloableWidth = 0.2765;
pPloy->setColor(RGB(255, 0, 0)); // RGB颜色模式
// AcGePolyVertix 顶点信息 参数1:点信息,参数2:曲率,0为直线,>0为曲率,参数3:属性,字符串
pPloy->m_pList.push_back(AcGePolyVertix(DPoint(0, 0, 0), 2, "大头兵"));
pPloy->m_pList.push_back(AcGePolyVertix(DPoint(0, 10, 0), 0.5));
pPloy->m_pList.push_back(AcGePolyVertix(DPoint(10, 10, 0), 0));
// 获取该db的块表记录,并向其添加新Entity,参数1:要添加的AcDbEntity,参数2:是否支持撤销
pDb->getModelSpaceRecord()->addNewEntity(pPloy, true);
// 创建的对象需要close才能正常显示
pPloy->close();
}
// 创建文字
{
AcDbText* pText = new AcDbText(); // 绘制一个复杂线条
pText->m_alignmentPoint = DPoint(0, 0, 0); // 文字插入点信息
pText->m_height = 10;// 文字高度
pText->m_widthFactor = 2;// 宽度
pText->m_textString = "普罗米修斯";// 文字字符串
pDb->getModelSpaceRecord()->addNewEntity(pText, true);
pText->close();
}
// 填充图案
{
AcDbHatch* pHatch = new AcDbHatch(); // 绘制一个填充图案
pHatch->m_patternName = "我是粉刷匠,把这里填充一个好看的图案";
pHatch->appendPoint2D(DPoint(0, 0, 0));
pHatch->appendPoint2D(DPoint(100, 0, 0));
pHatch->appendPoint2D(DPoint(100, 100, 0));
pHatch->appendPoint2D(DPoint(0, 100, 0));
pHatch->appendPoint2D(DPoint(0, 0, 0));
pHatch->setPatternDefinitionByName("ANGLE");// 设置图案,参数字符串,来自/resource/pat/acadiso.pat
//pDb->getModelSpaceRecord()->addNewEntity(pHatch, true);
pRecord->addNewEntity(pHatch, true);// 将图案绘制到布局1
pHatch->close();
}
// 这个Update加不加没什么区别,但教程说是要加
pDraw->Update();
}
标签:DPoint,pHatch,示例,代码,pDb,pDraw,pText,图元,pPloy
From: https://www.cnblogs.com/SpringBreath/p/16965835.html