# Thread: AutoLISP routine to calculate the total weight of steel

1. 0 Did you find this post helpful? Yes

## Re: AutoLISP routine to calculate the total weight of steel

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.

2. 0 Did you find this post helpful? Yes

## Re: AutoLISP routine to calculate the total weight of steel

Originally Posted by rhall.72202
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.
I have modified the code. Just download the attachment in this post again.

3. 0 Did you find this post helpful? Yes

## Re: AutoLISP routine to calculate the total weight of steel

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.

4. 0 Did you find this post helpful? Yes

## Re: AutoLISP routine to calculate the total weight of steel

At the end of the lisp routine there is a section of code that looks like this
Code:
```        (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.

Code:
```        (alert                                                                 ; 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))```

5. 0 Did you find this post helpful? Yes

## Re: AutoLISP routine to calculate the total weight of steel

Originally Posted by Lions60
At the end of the lisp routine there is a section of code that looks like this
Code:
```        (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.

Code:
```        (alert                                                                 ; 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))```
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?

Code:
```(while (> (getvar "CMDACTIVE") 0)
(command pause)
)```
Could this be used somehow? I am not sure what to do here.

6. 0 Did you find this post helpful? Yes

## Re: AutoLISP routine to calculate the total weight of steel

Code:
`(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...

7. 0 Did you find this post helpful? Yes

## Re: AutoLISP routine to calculate the total weight of steel

Thanks. That works out nicely. I will have to remember that for some of my other routines.

8. 0 Did you find this post helpful? Yes

## Re: AutoLISP routine to calculate the total weight of steel

Code:
```;;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

9. 0 Did you find this post helpful? Yes

## Re: AutoLISP routine to calculate the total weight of steel

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.

10. 0 Did you find this post helpful? Yes

## Re: AutoLISP routine to calculate the total weight of steel

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.

Page 2 of 3 First 123 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•