Monday, October 6, 2008

Exploring AutoCAD Field Capabilities by Developing a Simple Field Calculator

We extensively use FIELD object these days for several purposes like creating a custom plot stamp or printing the filename in the title block etc. When we dig in depth, FIELD object will provide us with a lot of possibilities. Here is a simple calculator application using the 'Formula' inside the 'Object' category of field.

We are going to develop the calculator as an attributed block reference where you can modify the attribute values to get the result in another attribute. For this purpose, create on block with attributes FIRST_NUMBER,OPERATOR,SECOND_NUMBER and RESULT attributes and insert it into the drawing.

Insert the block and edit attributes in the Edit Attributes dialog. Leave the first three attributes as we are not going to do any field operations over there. Right click on the last attribute (RESULT) and select 'Insert Field' option as shown in the picture.


You will be provided with field dialog box. Select 'Objects' field category and choose 'Formula' from the field names. Now right click on the 'Formula' text box and choose 'Insert Field' option once again (See the picture).



Now an additional field dialog will show up. This time select 'Object' field name from the 'Objects' category. Select the inserted block using the small button located near the 'Object type' text box. Once selected, the block properties including the attributes will be shown up in the properties list box. Select the FIRST_NUMBER attribute from the list and click 'Ok'.



Repeat the steps 3 and 4 to include the attributes OPERATOR and SECOND_NUMBER in the formula text box as shown in the picture. That's it. Press ok to finish the procedure.


Try changing the FIRST_NUMBER, OPERATOR and SECOND_NUMBER values. if the FIELDEVAL system variable is properly set, you will see the result soon after the next regen.

If you want to know how to create 'Live Fields' inside a drawing, see the AutoClock post.

10 comments:

JTB World said...

Nice trick! I like it.

Josh Jones said...

Man you are a genius! Thank you for sharing your tips. I look forward to reading more posts from you.

Anonymous said...

I would love to use this, we have many applications for it, only one problem. Every time I right click in the formula box and pick formula the second time I get an Fatal Error: Unhandeled Access Violation Reading.... I'm using Land Desktop 2006.

Anonymous said...

I have the same problem with the fatal error. How do I get around this?

myfuad said...

I Want to know. how made formula refering to cell but number in cell not actual number to calculate.
such 2=3m, 3=4.9m.

hupjack said...

I found your post VERY helpful... I'm attempting to do a calc inside a block and insert the block a number of times in my single line diagram.. can you take a look?

http://forums.autodesk.com/t5/Dynamic-Blocks/Can-I-do-a-little-subtraction-or-addition-inside-a-block/

Jimmy Bergmark - JTB World said...

I tried to access the link but got some error.

har!s said...

Jimmy,
Here is the proper link. I would appreciate if you could provide some guidance.

Link to Autodesk discussion group post

Ethan,
Sorry that I can't help you much with the above problem.

Thanks.

Jimmy Bergmark - JTB World said...

hupjack, I don't have an answer ready for you and don't have spare time to investigate your problem.

cialis said...

I, of course, a newcomer to this blog, but the author does not agree