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 contain 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.
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.
A simple implementation of this function is:
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
The most relevant point here is to remember that this function is very important and is where your application will begin to execute.
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 2002 (7.0) and ObjectARX 2004. 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.