Our second Lab will cover MFC contents and some interaction with AutoCAD. The main idea is to keep this lab simple to consolidate MFC and user interaction knowledge.
* Class 1 to 10;
* AutoCAD 2004/2005/2006 or compatible vertical installed;
* Visual Studio .NET 2002 installed;
* ObjectARX Wizard installed.
Create a simple ObjectARX module with 1 commands: DLGCOLOR. This command will create a simple MFC dialog with a color combo box and one selection button. As the user clicks on this button it will prompt user to select one or more existing entities. After click Apply it will change the color of all selected entity.
- Create a project called ARXLAB2 using ObjectARX Wizard;
- Enable Using MFC option with AutoCAD MFC Extensions;
- Click on the a> icon at ARXWizard's toolbar to open command dialog;
- Right click on the above portion and select New;
- Change the global an local name for DLGCOLOR and select Modal as command mode;
- Open the Visual Studio Editor and add a new dialog layout. Add a combo box control and a button control;
- Open the Autodesk Class Explorer, right click on the root and select Add MFC Ext. Class. Select CAcUiDialog as the base class;
- In the dialog layout, right click on the combo box and select Add Variable. Choose CAcUiTrueColorComboBox as its class and name it as m_color. Right click on the combo again and select Properties. Set Has Strings = True, Owner Draw = Fixed;
- Now, right click the button and select Add Variable. Choose CAcUiSelectButton as its class and name it as m_select. Right click once more, select Properties. Set Owner Draw = True.
- Add the virtual BOOL OnInitDialog() method. Inside its implementation add the following:
SetWindowText(_T("ObjectARX for Dummies - Lab 2"));
- Map a click event to selection button. Right click on it, select Add Event Handler. Select BN_CLICKED event. Inside the event function, we will need to hide the dialog and switch to AutoCAD screen. As we have derived from CAcUiDialog it already has a couple of functions to do that. So we will need to hide the dialog, select the desired entities and then show the dialog back. Your function outline will be something like this:
// Perform here the user interaction (allow user to select entities)
- Don't forget to switch the resources to your application before open the dialog:
- Don't forget to call close() for all selected entities (use a Transaction if you prefer);
- Explore the code to understand what ARX Wizard has created for you;
- Pay attention to code syntax;
- Use the ObjectARX documentation when necessary;
If you have any questions please post your issue on this article to share with others.
- I will give you 3 days to accomplish this Lab;
- After this period, I will post my suggested solution for this.