ObjectARX & Dummies

Course Index

*Course support: Click here!
*Course and User samples: Download here!

Sunday, May 08, 2005

Lab 3 - Creating a custom object

Hello,

Our third Lab will cover custom objects. You will need to create a custom object, its properties, functions and Dictionary related methods.

Requirements:

* Class 1 to 12;
* AutoCAD 2004/2005/2006 or compatible vertical installed;
* Visual Studio .NET 2002 installed;
* ObjectARX Wizard installed.

Objectives:

The main idea is to create the first part of a complete custom shape application. This part consist of building the custom object which will represent the shape form with properties that allows you to completely define it.

The second step will be the custom entity which will refer to its associated shape. As several entities may use the same shape it is not a good idea to repeat the shape information inside each entity. Exactly due that we will create this custom object which will store de shape information and share this information with all custom entities related to it.

It will be an "I" shape with equal top and bottom flanges and it will need to store the following information:

-web height (d) - double;
-web thickness (tw) - double;
-flange width (bf) - double;
-flange thickness (tf) - double;
-shape name (desig) - CString;

Instructions:

- You will create two projects. The first, called ShapesUi (which will be the ObjectARX module) and the second called ShapesObj (which will be the ObjectDBX module) using ObjectARX Wizard;
- Enable Using MFC option in both projects;
- After created both projects, open the Autodesk View toolbar , select the ShapesObj project and create the custom object called ShapeObject;
- Override filling functions (dwgOutFields / dwgInFields);
- Implement all necessary properties to this object and provide is persistence through DWG filling functions;
- Create two functions. One to create the object and stored it inside NOD and other to list all existing objects. Use your custom Dictionary as ShapeApp;
- Use "*" as the key name of each shape inside ShapeApp Dictionary;
- Create a research function which will receive the shape information and will lookup an existing shape that matches with the information. If it is found, return it's ObjectId instead of create a duplicated shape. If it is not found, create a new shape and return its brand new ObjectId;
- Don't forget to create a == operator for your class to make easy to compare shapes when researching the Dictionary;

Tips:

- Use the class 12 code fragment to help you with this project;
- Add properties using ARXWizard because it will create the access methods and will put the filling line at dwgInFields() and dwgOutFields() functions;
- Be careful about code flow inside Dictionary manipulation functions;
- Double check your open / close scopes;
- Test SAVE and OPEN the DWG to assert that the custom objects are successfully saved and loaded;
- Use ARXDBG to verify if your custom objects are placed into the right place;
- Use the ObjectARX documentation when necessary;

Support:

If you have any questions please post your issue on this article to share with others.

Expected time:

- I will give you 7 days to accomplish this Lab;
- After this period, I will post my suggested solution for this.

5 Comments:

  • Hi,
    Its really very good for you to create this site.I am a civil engineer myself, but for the previous 8 years ive been into software development myself also just like you. Ive done Autocad programming, but into Active X Automation in Visual Basic 6, Iam into my new job now and they are more into Java and C++,they have a requirement for AutoCAD programming and so am really looking into Object ARX, and its really very helpful to find your site, which made me really appreciate the power of using C++ and Object ARX.In fact through your site i was able to understand how object ARX works which really helped a lot expecially doing Custom objects. One thing that really confused a little to me is on this lab 3. In your objectives above you mentioned to two things to be done, one is to create custom objects which will represent the shape form with properties, and the second step will be the custom entity which will refer to its associated shape. As i go through the solution that you have, i analyze it to be just doing the first objective, am i right? If this is right, can i suggest that you made that clear in the above objective, or create another lab to show how a custom entity can make use of the custom shape object that you created in this lab. Ive used enxtensively extended entity data in the previous autocad applications using active automation which repeats the same information on entities of the same type, which is actually inefficient, but through your example here i was able to understand the power of creating custom objects which would really helped a lot.

    By the way, in your solution, i noticed one thing which is probably an error, or it is actually how it is. And that is in the ShapesUI.Arx particularly in createOneShapeObject function which is called everytime a new shape is created in CShape command. In that function where you add the Shape in the dictionary, "pDict->setAt("*PS",pShape, id);", as i understand it right in ObjectARX documentation, the first parameter for each record which is the keyname in the dictionary should be unique for each object. Is my understanding right? if it is i guess the keyname in this case should be "*" + temp which is the unique description of each the I flange. I would really appreciate your clarification on this one.

    Thank you very much for your help.

    Chris Serrano

    By Anonymous Christian Serrano, at 12:23 AM  

  • Hello Christian,

    Yes, the Lab3 is only the first part of a "supposed" complete application. As the objective saids, its only the FIRST PART:

    "The main idea is to create the first part of a complete custom shape application..."

    Maybe I will create the SECOND PART on a near future...

    Regarding to your question about the dictionary key name, we are using "*" because we want an arbitrary entry because its name is not important to this application.

    Imagine you need to share the shape information among several beams inside your drawing. The first beam to be created also creates a corresponding shape inside Dictionary. If the second beam is created you could make a search function to look inside Dictionary to find an exact shape match. This search don't care about the entry name but it is all about the shape properties.

    If the corresponding shape is found you just get its AcDbObjectId and store into the new beam. If it is not found, create a new arbitrary entry.

    Of course your Dictionary will be organized depending on what types of shape you will deal: I, C, U, etc.

    Hope this help you.
    Regards,
    Fernando Malard.

    By Blogger Fernando Malard, at 8:24 AM  

  • The site is a great help as it is, much more your immediate response on this one. Thank you very much for your help. I really salute you for creating this great site.Hope i could be of service to you also in the near future. Thank you

    By Anonymous Christian Serrano, at 8:26 PM  

  • Hello!
    Extremely usefully this site!
    The main gap is the SECOND PART. It is possible to post the project for the second part, the link between the custom object and the custom entities?
    I understand what are custom objects, but what about custom entities and the link with objects!
    Kind regards!
    Ioan

    By Blogger Bordei, at 8:00 PM  

  • Hello Bordei,

    In fact the second part was not created due its complexity.

    I plan to update this Blog soon with some new articles and will cover the subject you want.

    Stay tuned.
    Best Regards,

    By Blogger Fernando Malard, at 10:51 PM  

Post a Comment

<< Home