PDA

View Full Version : Calculations from results of the Area Command



alan.hoeweler
2005-03-02, 03:42 PM
We have a large amount of 2D drawings to complete, which are simply shapes for Aluminum extrusions.
The problem which greatly slows us down is a simple calculation of weight per foot.
We use the “Area” tool to get the area of the shape, but we want to take that calculation and multiply the area x 1.2 which gives the weight per foot of aluminum. This number is than divided into the perimeter calculation, also from “Area” tool, to come up with a degree of difficulty factor. We then want to place these results in our title block at specific locations. All calculations are currently being done by hand.

1. How do we do simple calculations from the results of the Area Command?
2. Can we transfer the results of the Area command to a physical location on the title block?
3. Is there any way we can, with the result of the Area command, automatically do the calculations and place the results at specific locations on the title block?

Can any one help?

Glenn Pope
2005-03-02, 03:58 PM
Hi alan.hoeweler

Please note that I have moved this thread from the AutoCAD Tips & Tricks forum to this one. I believe it would be better suited here.

Welcome to AUGI

lance.81922
2005-03-02, 04:04 PM
This certainly sounds like a fairly straightforward AutoLISP routine to me. Since AREA is stored as a system variable, doing the arithmetic, saving the result and swapping the result in as a new attribute value shouldn't be too hard.

alan.hoeweler
2005-03-02, 04:17 PM
Unfortunately we have no one here who has any experience with AutoLISP programing, do you have any suggestions as to where we can go from here?

lance.81922
2005-03-02, 04:55 PM
This ought to do the job for you. Let me know if this is not exactly what you want:


;;; AREACALC Command
;;; Performs arithmetic operation on AREA system variable and
;;; places value into an attribute
;;; L. Gordon 2005
(defun c:areacalc (/ o ol a ax as att attlist)
(setq o (car
(entsel "\nSelect closed polyline for Area calculation: ")
)
)
(if o
(progn
(setq ol (entget o))
(if (and (or (= (cdr (assoc 0 ol)) "LWPOLYLINE")
(= (cdr (assoc 0 ol)) "PLINE")

)
(= (logand (cdr (assoc 70 ol)) 1) 1)
)
(progn
(setvar "CMDECHO" 0)
(command "_AREA" "A" "O" o "" "")
(setvar "CMDECHO" 1)
(setq a (getvar "AREA")
ax (* a 1.2)
as (rtos ax)
)
(while
(not
(setq att (car (nentsel "\Select attribute to change: ")))
)
)
(if (= (cdr (assoc 0 (setq attlist (entget att)))) "ATTRIB")
(progn
(setq
attlist (subst (cons 1 as) (assoc 1 attlist) attlist)
)
(entmod attlist)
(entupd att)
)
)
)
(alert "Object must be a closed polyline.")
)
)
)
(princ)
)

The program prompts you for a closed polyline, runs the "AREA" command, multiplies the result by 1.2, converts the answer to a text string, and replaces the current value of a title block attribute with the answer. Load it and run with "areacalc".

arcadia_x27
2005-03-02, 04:57 PM
You could always try your Reseller (although I'm sure there'd be a cost involved) but if your reseller has someone who's competent in AutoLISP I'm sure it wouldn't be that hard to write a routine to accomplish this.

You might also want to try a search in the AutoLISP forum and see if anyone has asked for or written a routine to do this already.

I'd be more than happy to write you a routine to do this, but I know little of AutoLISP as well and never seem to have the time to sit down and learn it. Maybe theres another fellow AUGI member out there who could help you out. :-) Any takers?

arcadia_x27
2005-03-02, 04:58 PM
Looks like someone has already helped you out :-)

alan.hoeweler
2005-03-04, 06:41 PM
Lance;
Thank you for your help. I am a bit confused. I copied your Lisp to my notepad, then saved it to a new Support file named "areacalc.lsp" . Which loads areacalc during startup. I then drew a new shape in a new drawing. I made sure it was a Polyline object, and ran "areacalc.lsp". It asks for the attribute to change. Do I define the text in the title block as an attribute? How do I attach the proper text to the polyline?

alan.hoeweler
2005-03-04, 06:48 PM
Lance

I have attached our title block with a shape drawn on it. As you can see in the lower right corner is the location of the text we need to change with each shape. Will your Lisp do this?

lance.81922
2005-03-05, 01:12 AM
Hi, Alan -- I wrote the program assuming certain things, based upon what you said in your previous email. For instance, because you said you want to
transfer the results of the Area command to a physical location on the title block I assumed that you wanted to place the area number into the title block as an ATTRIBUTE. That's because I also assumed that your title block would be a BLOCK, and the text in it would actually be ATTRIBUTES. If this is not the way you do it at your company, then it would not be difficult to put the area info into TEXT form. What I'm saying is that a custom AutoLISP routine like what I've given you should be made to work the way you work, not the way the programmer wants you to work.

BTW I could not figure out exactly which text you want to change. Again, to do the best job I'd need to know exactly what you want to change. If it will be the same in every drawing, it might be possible to update it automatically rather than by requiring the user to select it. This is case where an attribute might make the job easier (for the programmer), because all text "looks" the same to a program, while attributes are generally all different.

Let me know what you need.......

Lance Gordon, President
Lance Gordon Custom Software
http://www.lgcad.com

alan.hoeweler
2005-03-07, 02:33 PM
Lance;
I would like to know what it would take to write a proper Lisp program. I can compose a routine we need and send you a copy of our Titleblock, for your examination. If you feel we need to change any thing we well.

lance.81922
2005-03-07, 03:14 PM
Hello, Alan -- It's a little hard to know how to answer your question ("what it would take to write a proper Lisp program") without knowing something about your experience, BUT I have written thousands of them over the years since Release 11. You can email me privately about this if you wish, or we can do it here. I'd be happy to help you out.

I have already modified the code I originally created for you to deal with selecting text instead of attributes, but as I said, to do the best job for you means knowing exactly how you work.