AutoCAD/AutoCAD lisp.
Expert: J. B. Borge - 2/14/2006
QuestionRecently I've had to do several volume calculations for piping that we're doing. I have set up an excel sheet so all I have to do is enter the length of the piping and it will give me volume.
I have had little c++ and MATLAB experience and could write a simple program if I knew the syntax for lisps.
What I need the program to do: let me select several lines at a time; then it takes the length of those lines and adds them to give me total length(in x'-x"). That way I don't have to add up all the lines one by one.
If you could help me on this it would be much appreciated. Thanks!
PS. This is AutoCAD 2006
AnswerNathan,
Here's a lisp function i use to calculate perimeters & areas & can be easily edited to your needs. The caveat, autocad can't add line lengths unless they are converted in polylines first.
;;;Start Copy Here
(defun c:CTA (/ a ss n du)
(setq a 0
b 0
;du (getvar "dimunit")
ss (ssget '((0 . "*POLYLINE")))
)
(if ss
(progn
(setq n (1- (sslength ss)))
(while (>= n 0)
(command "_.area" "_o" (ssname ss n))
(setq a (+ a (getvar "area"))
b (+ b (getvar "perimeter"))
n (1- n)
)
)
(setq SQFT (strcat (rtos a 2 3) " Sq. Ft.")
SQYD (strcat (rtos (/ a 9) 2 3) " Sq. Yd.")
ACRE (strcat (rtos (/ a 43560) 2 3) " Acres")
PERI (strcat (rtos b 2 3) " Ln. Ft.")
)
(princ "\nThe total area: ")(princ SQFT) (terpri)
(princ " ")(princ SQYD) (terpri)
(princ " ")(princ ACRE) (terpri)
(princ " ")(princ PERI) (terpri)
)
(alert "\nNo Polylines selected!")
)
(princ)
)
;;;End Copy Here
Load the routine & type CTA to run it. Hope this points to the right direction. Let me know!
Regards,
JB