PDA

View Full Version : AutoLISP routine to calculate the total weight of steel

Robert.Hall
2004-08-16, 05:10 PM
Im not real good with lisp so I am asking to see if anyone can create a really useful, but Im guessing quick to make, lisp routine......what I need is a lisp that takes the
area of a 2d object, asks for a material thickness to be input, and completes this calculation (area) x (thickness/25.4) x (.2833) whereas thickness in in millimeters and .2833 is the density of steel. This would calculate an weight estimation.
Any help would be appreciated :-)

paulmcz
2004-08-18, 01:16 AM
See if this helps.
Paul.

Robert.Hall
2004-08-18, 08:40 PM
That is a neat lisp routine but I am looking for a quick lisp routine
for a flat blank.....ie blank area X thickness X density
My drawings are basically 2d, steel blanks, that sometimes have
cutouts.

paulmcz
2004-08-19, 01:20 AM
...then it must be this one......

Robert.Hall
2004-08-19, 12:36 PM
Not quite,, the area should be from the area command, so I can pick an object on the screen. Density is also a constant, all we use is steel .2833

aaronrumple
2004-08-19, 01:24 PM
You might consider going 3D. Extrude a region to the thicknes needed and you'll have your mass. You can then use the MASSPROP command to list out all sorts of structural properties and even write the data to a text file. All of this is automatic in 3D. No lisp needed.

Robert.Hall
2004-08-19, 01:27 PM
That would take too long........but ok. Im working with flat blanks from a blanking line and creating process drawings.

RobertB
2004-08-19, 05:49 PM
Does the area need to be adjusted to inches also? Or are the objects drawing with units defined as inches?

Robert.Hall
2004-08-19, 06:24 PM
Drawing units are in inches...so its ok to use .2833 in the calculation.

RobertB
2004-08-19, 07:26 PM
Attached is a program that does what I think you want.

Robert.Hall
2004-08-19, 07:35 PM
That is awesome, me likey, me likey....one last quick favor, can you make the output
be in KG. Your a lifesaver, I do this calculation daily.

RobertB
2004-08-19, 07:49 PM
That is awesome, me likey, me likey....one last quick favor, can you make the output
be in KG. Your a lifesaver, I do this calculation daily.

Robert.Hall
2007-06-21, 01:50 PM
I have the command line autohide. Is there a way to display an autocad
text window at the end of this routine? I have to keep checking the
command line after running the routine.

Lions60
2007-06-21, 02:41 PM
At the end of the lisp routine there is a section of code that looks like this

(prompt ; return calculated weight
(strcat "Weight (for "
inpMat
"; density "
(rtos usedDensity 2 4)
") is estimated to be:\n"
(rtos (getvar "UserR2") 2 4)
" pounds, "
(rtos (getvar "UserR3") 2 4)
" kilograms.\n"))))
(princ))

If you change where it says prompt to alert then this will display an autocad message box with the weight calculations. Code should look like below for autocad message box to display.

(strcat "Weight (for "
inpMat
"; density "
(rtos usedDensity 2 4)
") is estimated to be:\n"
(rtos (getvar "UserR2") 2 4)
" pounds, "
(rtos (getvar "UserR3") 2 4)
" kilograms.\n"))))
(princ))

Robert.Hall
2007-06-22, 05:49 PM
At the end of the lisp routine there is a section of code that looks like this

(prompt ; return calculated weight
(strcat "Weight (for "
inpMat
"; density "
(rtos usedDensity 2 4)
") is estimated to be:\n"
(rtos (getvar "UserR2") 2 4)
" pounds, "
(rtos (getvar "UserR3") 2 4)
" kilograms.\n"))))
(princ))

If you change where it says prompt to alert then this will display an autocad message box with the weight calculations. Code should look like below for autocad message box to display.

(strcat "Weight (for "
inpMat
"; density "
(rtos usedDensity 2 4)
") is estimated to be:\n"
(rtos (getvar "UserR2") 2 4)
" pounds, "
(rtos (getvar "UserR3") 2 4)
" kilograms.\n"))))
(princ))

That works, however, if I click ok, then it is gone. I would have to run the routine
again. It is still nice to scroll back through the command line if I want to look
up the numbers again. Is there a way to invoke the Autocad command window?

(while (> (getvar "CMDACTIVE") 0)
(command pause)
)

Could this be used somehow? I am not sure what to do here.

Mike_R
2007-06-25, 01:04 PM

(command "_.textscr")
That will bring up the text screen when the routine finishes.

Edit: Misunderstood the request... Changed from command line to text screen coming up...

Robert.Hall
2007-06-27, 03:35 PM
Thanks. That works out nicely. I will have to remember that for some of my other routines.

jwanstaett
2007-06-28, 06:20 PM
;;John W. Anstaett 06/28/2007
;;Tested in ADT 2007 should work in other rev.
;;command Setth
;; set the Theckness
;;command Startarea
;; start the Weight program
;; it display the weight and theckness on the status line
;; using the last area command you use
;; and change each time you do a area command
;;command endarea
;; set the status line back to the way it was

;;this should be the first line in all program that use ActiveX
;;This function loads the extended AutoLISP functions
;;provided with Visual LISP. The Visual LISP extensions implement
;;ActiveX and AutoCAD reactor support through AutoLISP, and also
;;provide ActiveX utility and data conversion functions,
;;dictionary handling functions, and curve measurement functions.

(DEFUN C:SETTH()
(setvar "userr1" (distof (INPUTBOX "Enter Stell Thickness mm" "John W. Anstaett InputBox")))
)
(defun c:StartArea()
(setvar "MODEMACRO" "\$(*,\$(/,\$(getvar,area), \$(getvar,userr1)) , 0.2833):th=\$(getvar,userr1)")
)
(defun c:EndArea()
(if modemacro
(setvar "modemacro" saveModemacro)
(setvar "modemacro" "")
)
)
;;Functuion inputbox
;;input
;; myprompt is the text for the prompt
;; mytitle is the text for the title
;; system variable users1 is used for the default input
;; return the text enter in the box
;; and system variable users1 is set then the same
(defun inputbox (myprompt mytitle / myapp)
(vla-eval myapp "myappz = ThisDrawing.GetVariable( \"users1\")")
(vla-eval myapp (strcat "myappy = inputbox(\"" myprompt "\",\"" mytitle "\", myappz)"))
(vla-eval myapp "ThisDrawing.SetVariable \"users1\", myappy")
(getvar "users1")
)

Note Some time you need to click to get the status line to up date

CISCO
2012-07-11, 08:07 PM
Hello, I am needing something very similar to this. I copied and pasted into my lsp file and it won't run the command. I need it to calculate steel weight, using inches and pounds. Any help will be greatly appreciated. I am very low level in programming so something simple to your eye I may not be able to catch. When i load the lisp file i get:
Command: ; error: no function definition: POUNDS

Thanks.

jwanstaett
2012-07-17, 01:13 PM
Witch code did you copy and pasted.

If the error come up when you are loading the lisp file the you did not copy and pasted the code right.Try to save the file and load it, no need to copy and past. You my be missing a ( ) or " in the code you copped.

If it was my code to display the weight and theckness on the status line.
The command is Startarea. Then you need to do a area command.
Use the command Setth to set the Theckness
Use the command endarea to set the status line back to the way it was.

If it was the CalcWt.lsp by Written by: R. Robert Bell the command is CalcWt.

CISCO
2012-07-17, 08:10 PM
Witch code did you copy and pasted.

If the error come up when you are loading the lisp file the you did not copy and pasted the code right.Try to save the file and load it, no need to copy and past. You my be missing a ( ) or " in the code you copped.

If it was my code to display the weight and theckness on the status line.
The command is Startarea. Then you need to do a area command.
Use the command Setth to set the Theckness
Use the command endarea to set the status line back to the way it was.

If it was the CalcWt.lsp by Written by: R. Robert Bell the command is CalcWt.

Ok, i tried yours and this is what i got...

Command: SETTH

When i used Roberts, it loaded...but the answer I received is not accurate. It may have to do with the units I imagine. I am using arch units to draw, so I am entering a thickness in inches to get the pounds.
I would like to select the boundary or polyline, enter the thickness (inches) and get the weight in pounds. Thanks.

ccowgill
2012-07-18, 01:27 PM
for VBA to work in 2012, do you have the VBA enabler installed?

CISCO
2012-07-18, 02:25 PM
I don't have the vba enabler. Any suggestions on where I can get it?

BlackBox
2012-07-19, 05:18 AM