ObjectArx学习笔记-画线并修改颜色改进写法

1、创建工程CreateEnts

2、添加类CCreateEnt,在文件CreateEnt.h中添加函数声明,在CreateEnt.cpp添加函数实现代码:

static AcDbObjectId CreateLine();

AcDbObjectId CCreateEnt::CreateLine()
{
	AcGePoint3d ptStart(0,0,0);
	AcGePoint3d ptEnd(100,100,0);
	AcDbLine *pLine = new AcDbLine(ptStart, ptEnd);

	AcDbBlockTable *pBlockTable;
	acdbHostApplicationServices()->workingDatabase()
		->getBlockTable(pBlockTable,AcDb::kForRead);

	AcDbBlockTableRecord *pBlockTableRocord;
	pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRocord,
		AcDb::kForWrite);

	AcDbObjectId lineId;
	pBlockTableRocord -> appendAcDbEntity(lineId, pLine);

	pBlockTable -> close();
	pBlockTableRocord -> close();
	pLine -> close();

	return lineId;
}

3、添加类CModifyEnt,在文件CModifyEnt.h中添加函数声明,在CModifyEnt.cpp添加函数实现代码:

static Acad::ErrorStatus ChangeColor(AcDbObjectId entId, Adesk::UInt16 colorIndex);

Acad::ErrorStatus CModifyEnt::ChangeColor(AcDbObjectId entId, Adesk::UInt16 colorIndex)
{
	AcDbEntity *pEntity;
	//打开图像数据库中的对象
	acdbOpenObject(pEntity, entId,AcDb::kForWrite);

	//修改实体颜色
	pEntity->setColorIndex(colorIndex);

	pEntity->close();

	return Acad::eOk;
}

4、在ObjectARX中注册新命令_ChangColor。首先应用之前的两个头文件,最后添加命令的实现代码:

#include "CreateEnt.h"
#include "ModifyEnt.h"

// - qxzyCreateEnts._ChangeColor command (do not rename)
	static void qxzyCreateEnts_ChangeColor(void)
	{
		// Add your code for command qxzyCreateEnts._ChangeColor here
		AcDbObjectId lineId;
		lineId = CCreateEnt::CreateLine();
		CModifyEnt::ChangeColor(lineId, 1);
	}

最后编译

转载:http://blog.csdn.net/foreverling/article/details/26587933

时间: 2024-08-31 01:12:06

ObjectArx学习笔记-画线并修改颜色改进写法的相关文章

ObjectArx学习笔记-画线并修改颜色

实现画线和修改颜色全部代码: // (C) Copyright 2002-2005 by Autodesk, Inc. // // Permission to use, copy, modify, and distribute this software in // object code form for any purpose and without fee is hereby granted, // provided that the above copyright notice appe

ObjectArx学习笔记-画线

一.安装vs2005 二.安装AutoCAD2008 三.安装ObjectArx2008 四.建立第一个ObjectArx程序 1.首先用ObjectARX Commands添加一个命令 然后在acrxEntryPoint.cpp中生成如下代码: ACED_ARXCOMMAND_ENTRY_AUTO(CArxProject1App, qxzyArxProject1, _MyCommand1, MyCommand1, ACRX_CMD_TRANSPARENT, NULL) 以及: // - qxz

ObjectArx学习笔记-创建多段线

1.创建一个工具类CTool. Tool.h: static ads_real GetWidth(); static int GetColorIndex(); Tool.cpp ads_real CTool::GetWidth() { ads_real width = 0; if(acedGetReal(_T("\n输入线宽:"), &width)==RTNORM) { return width; } else { return 0; } } int CTool::GetCol

ObjectArx学习笔记-Object 2013 Wizard问题解决

AutoCAD ObjectArx 2013 Wizard 可以到Autodesk的官网下载. 1.安装完成后,在Visual Studio中使用Wizard提供的模版新建工程时,总是提示"编码不正确,无法创建工程".折腾好久,找到问题:  C:\Program Files (x86)\Autodesk\ObjectARX2013 Wizards\Autodesk.arx-2013.props C:\Program Files (x86)\Autodesk\ObjectARX 2013

ObjectArx学习笔记-获取某一图层上所有直线

//----------------------------------------------------------------------------- //----- acrxEntryPoint.h //----------------------------------------------------------------------------- #include "StdAfx.h" #include "resource.h" #include

ObjectArx学习笔记-选择文件及ACHAR用法

ObjectArx中实现文件选择的代码如下: static void qxzyGetFileD_SelectFile(void) { // Add your code for command qxzyGetFileD._SelectFile here const ACHAR* title = L"选择图形文件"; const ACHAR* path = L"C:\\"; struct resbuf *fileName; fileName = acutNewRb(RT

ObjectArx学习笔记-创建标注样式

实现代码: static void qxzyAddDimStyle_AddDimStyle(void) { ACHAR styleName[50]; if(acedGetString(Adesk::kFalse, _T("请输入样式名称:"), styleName) != RTNORM) { return; } AcDbDimStyleTable *pDimStyleTbl; acdbHostApplicationServices()->workingDatabase() -&g

ObjectArx学习笔记-设置字体样式

实现代码: static void qxzyOperateLayer_AddStyle(void) { AcDbTextStyleTable *pTextStyleTbl; acdbHostApplicationServices()->workingDatabase() ->getTextStyleTable(pTextStyleTbl, AcDb::kForWrite); AcDbTextStyleTableRecord *pTextStyleTblRcd; pTextStyleTblRcd

ObjectArx学习笔记-acedGetXXX

acedGetInt函数暂停程序执行,等待用户输入一个整数.该函数定义为: int acedGetInt(const char * prompt, int * result); prompt用于指定显示在命令窗口中的字符串,如果不需要使用可以指定NULL作为该参数的值. acedGetReal函数暂停程序执行,等待用户输入一个实数. acedGetString函数暂停程序执行,等待用户输入一个字符串,该函数定义为: int acedGetString(int cronly, const char