AutoCAD/AutoCAD lisp.

Advertisement


Question
Recently 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

Answer
Nathan,

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

AutoCAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


J. B. Borge

Expertise

I can answer general questions about Autocad & Solid Works.

Experience

I've been in the 3D/2D CAD industry for over 16 yrs. & also had the opportunity/exposure to work with several mainstream design platforms including Helix Design Systems to Solid Works to Civil 3D.

Education/Credentials
Austin College, Tarrant County College, ITT

Awards and Honors
AUGI Top Dawg Dallas 2004

Past/Present Clients
Freightliner, Mac Trucks, Arctic Cat, Walmart, & Sam's Club

©2012 About.com, a part of The New York Times Company. All rights reserved.