AutoCAD中的ARX插件一般写法(ObjectARX+C++)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
// MyArxFirst.cpp : 定义 DLL 应用程序的导出函数。
//ObjectArx开发对txt文本文件的操作一例
#pragma once

#include "stdafx.h"
//
#include "Convert.h"
#include "fileSimpleClass.h"
#include "dbSimpleClass.h"

//定义两个函数
void initApp();
void unloadApp();

//定义命令函数
//------------------------------------------
void hello();//打印"Hello world!"在AutoCAD Command上  的命令
void pfvalue();//打印文件内容 的命令
void pdbvalue();//ado连接数据库的方法 的命令
void inputvalue(); //CAD交互操作的方法 的命令
//------------------------------------------

//定义CAD的实体点函数  这个函数是必须的
extern "C"
AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
//void acrxEntryPoint(void* pkt)
{
switch (msg)
{
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(pkt);
acrxRegisterAppMDIAware(pkt);
initApp();
break;
case AcRx::kUnloadAppMsg:
unloadApp();
break;
default:
break;
}
return AcRx::kRetOK;
}

void initApp()
{
//register a command with the AutoCAD command mechanism
//string macro 用法:
//_T("helloworld") or  __T("helloworld")  or ACRX_T("helloworld")
acedRegCmds->addCommand(ACRX_T("HELLOWORLD_COMMANDS"),
ACRX_T("ArxHsgBag"),
ACRX_T("Hello"),
ACRX_CMD_TRANSPARENT,
hello);
acedRegCmds->addCommand(ACRX_T("PFVALUE_COMMANDS"),
ACRX_T("ArxHsgBag"),
ACRX_T("pfvalue"),
ACRX_CMD_TRANSPARENT,
pfvalue);
acedRegCmds->addCommand(ACRX_T("PDBVALUE_COMMANDS"),
ACRX_T("ArxHsgBag"),
ACRX_T("pdbvalue"),
ACRX_CMD_TRANSPARENT,
pdbvalue);
acedRegCmds->addCommand(ACRX_T("INPUTVALUE_COMMANDS"),
ACRX_T("ArxHsgBag"),
ACRX_T("inputvalue"),
ACRX_CMD_TRANSPARENT,
inputvalue);
//
}

void unloadApp()
{
acedRegCmds->removeGroup(ACRX_T("HELLOWORLD_COMMANDS"));
acedRegCmds->removeGroup(ACRX_T("PFVALUE_COMMANDS"));
acedRegCmds->removeGroup(ACRX_T("PDBVALUE_COMMANDS"));
acedRegCmds->removeGroup(ACRX_T("INPUTVALUE_COMMANDS"));
}

//定义两个类变量
fileSimpleClass fsc;
dbSimpleClass dbsc;
Convert cvOp;
//----------------------------------------------------
//实现命令函数
void hello()//hello命令
{
acutPrintf(ACRX_T("\n第一个Arx程序Hello World!"));	
}

void pfvalue()//打印文件内容 命令
{	
acutPrintf(_T("开始输出文件内信息:\n"));
const ACHAR* filepath=ACRX_T("d:\\test.txt");  //OK
acutPrintf(filepath);	//OK
fsc.pfvalue_default(filepath); //OK
fsc.pfvalue2(filepath);  //OK
}

void pdbvalue()//输出数据库表内记录的命令
{
acutPrintf(_T("开始输出数据库表内记录:\n"));
//...
acutPrintf(_T("执行函数:pdbvalue_mdb结果\n"));
dbsc.pdbvalue_mdb();
acutPrintf(_T("执行函数:pdbvalue_mdb结果完毕!\n"));
//
acutPrintf(_T("执行函数:pdbvalue_mdb2结果\n"));
dbsc.pdbvalue_mdb2();
acutPrintf(_T("执行函数:pdbvalue_mdb2结果完毕!\n"));

dbsc.pdbvalue_write(); acutPrintf(_T(“执行函数:pdbvalue_write完毕!\n”));

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
}
void displayvalue(_bstr_t bstrt)
{
ACHAR* tmp=cvOp.GetAcharPtr(bstrt);
acutPrintf(tmp);
}

void inputvalue()
{
int res;
//输入一个整数
acedGetInt(_T("输入一个整数:"),&res);
//显示
displayvalue(_bstr_t(res));acutPrintf(_T("\n"));
/*_bstr_t bstrt(res);
ACHAR* tmp=cvOp.GetAcharPtr(bstrt);
acutPrintf(tmp);*/
//输入一个字符串
ACHAR str;
acedGetString(1,_T("输入一个字符:"),&str);
//displayvalue(_bstr_t(str));acutPrintf(_T("\n"));	
}
//----------------------------------------------------

void inputvalue()
{
int res;
//输入一个整数
acedGetInt(_T("输入一个整数:"),&res);
//显示
displayvalue(_bstr_t(res));acutPrintf(_T("\n"));
/*_bstr_t bstrt(res);
ACHAR* tmp=cvOp.GetAcharPtr(bstrt);
acutPrintf(tmp);*/
//输入一个字符串
wchar_t* str;
str=new wchar_t[4000];
acedGetString(1,_T("输入一个字符:"),str);
displayvalue(_bstr_t(str));
acutPrintf(_T("\n"));
}