几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » ObjectARX(C++)
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-04-16, 10:37 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】objectarx&dummies教程(三)——application overview

objectarx&dummies教程(三)——application overview
objectarx&dummies教程(三)——application overview
class 3 - application overview
introduction
as i mentioned before, the objectarx is actually a dll. it can be linked with or without mfc extensions. most of times you would like to link with mfc. autodesk provides a pretty handy wizard to allow users to quickly create objectarx applications with minimun code effort.
before we can proceed i would like to clarify the main differences between objectarx and objectdbx applications. the main idea is to separate interface and object classes to allow the called "object enablers". this is not a mandatory but it is a good programming practice and autodesk made this separation to provide great things like, for instance, open an adt drawing inside autocad, download the proper enabler and then show those adt entities correctly inside autocad.
suppose you need to create an application with a bunch of custom entities and objects. the drawings created with this application will contains these custom objects and if another users try to open this drawing inside autocad and without your applications they will see only proxy entities. if you would like to allow these users to see your custom entities but don't perform any commands over them you just need to ship de dbx part of your application. this way the user will be able to see your custom entities and perform some limited operations.
when the drawing is saved autocad preserve the custom entity information using the called proxy entities. this will happen even if the dbx module is not available. the proxy entities stores the binary data of your custom object and keep that until your application come back.
in other hand, the arx module of your application will be responsible for the interface. there you should register your commands, create your dialogs, customize menus, etc.
application structure
both arx and dbx modules must implement an entry point function. this function is responsible to perform messages exchange between autocad and your application. for those who are familiar with old c language it is the substitute of main() function.
this entry point function has a signature as follow:
extern "c" acrx::appretcode acrxentrypoint(acrx::appmsgcode msg, void* pkt);
a simple implementation of this function is:
extern "c" acrx::appretcode
acrxentrypoint(acrx::appmsgcode msg, void* pkt)
{
switch(msg) {
case acrx::kinitappmsg:
break;
case acrx::kunloadappmsg:
break;
default:
break;
}
return acrx::kretok;
}
this function is automatically implemented by the wizard as you will see later. the first parameter (msg) is the message sent from autocad to your application telling you what is happening. you may receive a "new drawing" message, a "init application" message among many others. these messages are very important to your application and to allow you to react to each desired event to monitor. the second parameter (pkt) is a data package that can be useful in some situations that i would avoid to discuss now (remeber, our course is for dummies). this function must return a value to autocad using appretcode which can be kretok (common value) or even kreterror which will force autocad to unload your application.
the most relevant point here is to remember that this function is very important and is where your application will begin to execute.
registering commands
probably your application will implement several commands. you can register your commands from the acrxentrypoint() function when receiving the kinitappmsg message that represents the event fired by autocad when it loads your application (this can be done by several ways that we will discuss later). once this message is received, you can call the appropriate methods to register each desired command.
registered commands must have a group name, a global name, a local name, some flags, a void function pointer and, optionally, some other parameters. basically the registered command will fire the function you specified. this function must be a void function without any parameters. when the user inside autocad call your command, autocad seek its command stack, find your command and fire your function. that's it!
it is very important that you preceed your commands with a 3 or 4 letters prefix to avoid command colision with other third-party applications. regarding to the main parameters:
group name: allows you to group your common commands to make easier to unload and manage them;
global name: your command untranslated name. you should use english names here that is the most used language;
local name: your localized command name which represents the translated name;
flags: can be a combination of several types. the two most important flags are acrx_cmd_transparent and acrx_cmd_modal. they establishes your command behavior that can be transparent (like zoom) or modal (like major commands);
void function pointer: here you pass the name of the void function you would like to link with the command. this function will be fired by autocad when the command is invoked.
once you register your commands you need obviously to unregister when leaving autocad or when your application is unloaded. this can be easily done unregistering all commands by the group name. when you recieve the kunloadappmsg message is time to remove your commands.
running your application
supposing you already compiled your application successfully it is time to load it inside autocad and test your commands. my preferable method to load / unload objectarx applications is through the appload command. it opens a very handy dialog that allows you to browse for the application and load it. it comes also with a startup suite briefcase that allows you to automatically load a list of applications when autocad starts.
once your application is loaded, just fire your commands and enjoy!
i have posted a simple application made by arxwizard and visual studio.net 2 (7.0) and objectarx 4. it is called simpleline and it was posted to our file sharing web site as mentioned before. i would like you to download it and pay attention to the code that we have discussed on class 2. see that i have mapped a command to a function and inside this function the routing to create a line is performed. go ahead, give a try! compile this code and open the result arx file inside autocad.
next class i will show how to build this application from scratch using the arxwizard.
stay tuned!
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
Unicode、UCS、UTF、BMP、BOM huangyhg vc编程 2 2007-01-22 05:43 PM


所有的时间均为北京时间。 现在的时间是 08:07 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多