![]() |
【转帖】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! |
所有的时间均为北京时间。 现在的时间是 12:00 PM. |