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 appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//

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

//-----------------------------------------------------------------------------
#define szRDS _RXST("qxzy")

//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CModifyEntApp : public AcRxArxApp {

public:
	CModifyEntApp () : AcRxArxApp () {}

	virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
		// TODO: Load dependencies here

		// You *must* call On_kInitAppMsg here
		AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;

		// TODO: Add your initialization code here

		return (retCode) ;
	}

	virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
		// TODO: Add your code here

		// You *must* call On_kUnloadAppMsg here
		AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;

		// TODO: Unload dependencies here

		return (retCode) ;
	}

	virtual void RegisterServerComponents () {
	}

public:

	// - qxzyModifyEnt._ChangeColor command (do not rename)
	static void qxzyModifyEnt_ChangeColor(void)
	{
		// 首先创建一条直线,然后修改直线的颜色为红色
		AcDbObjectId lineId;
		lineId = CreateLine();
		ChangeColor(lineId, 1);
	}

	static AcDbObjectId 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;
	}

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

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

		pEntity->close();

		return Acad::eOk;
	}

} ;

//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CModifyEntApp)

ACED_ARXCOMMAND_ENTRY_AUTO(CModifyEntApp, qxzyModifyEnt, _ChangeColor, ChangeColor, ACRX_CMD_TRANSPARENT, NULL)

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

时间: 2024-11-01 06:13:12

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

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,

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