CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz] ARKANCE | CONTACT - CZ | SK | EN | DE
RSS channel - CAD tips RSS tips
RSS discussions

Discussion Discussion forum

?
CAD discussions, advices, exchange of experience

CAD Forum - Homepage CAD discussion forum - ask any CAD-related questions here, share your CAD knowledge on AutoCAD, Inventor, Revit and other Autodesk software with your peers from all over the world. To start a new topic, choose an appropriate forum.

Please abide by the rules of this forum.
This is a peer-to-peer forum. The forum doesn't replace the official direct technical support provided by ARKANCE for its customers.
How to post questions: register or login, go to the specific forum and click the NEW TOPIC button.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedHow to obtain a sum total of a list of lines

 Post Reply Post Reply
Author
jmontesmx View Drop Down
Senior Member
Senior Member


Joined: 28.Jan.2008
Location: Mexico
Using: AutoCad2017
Status: Offline
Points: 113
Direct Link To This Post Topic: How to obtain a sum total of a list of lines
    Posted: 28.Aug.2009 at 19:28
Thanks a lot .
Back to Top
jorgeanjos View Drop Down
Newbie
Newbie


Joined: 18.Aug.2009
Location: Portugal
Status: Offline
Points: 4
Direct Link To This Post Posted: 28.Aug.2009 at 15:05
Originally posted by jmontesmx jmontesmx wrote:

Excuse me, can you explain me more, I'm trying to use your directions but I can't do it.  I'm using Autocad 2007 may be this is the reason.

Thanks.

Are you using the LT?

AutoCAD LT doesn't support AutoLISP, unless you have some "add-on".
 
The file I recomended should work with AutoCAD 2007, but try this one:
http://www.cadtom.com/Arquivo/AutoLISP/Sumper.zip
You must download and unzip de file Sumper.zip first.

After unzip copy the file Sumper.lsp and paste in any place of AutoCAD drawing area.
 
Is the easiest way but you can load any AutoLISP application using the command Appload.
If the AutoLISP file was successfully loaded, you'll see in prompt

“»» Type 'SUMPER' to start applicationâ€

> Type SUMPER and press the ENTER Key

> Select the objects to calculate the length

> The total length of all selected entities will appear in Subtotal =


> For add more objects type A and press ENTER or just press ENTER to see the Total.

Hope That Helps



Edited by jorgeanjos - 28.Aug.2009 at 15:28
Jorge Anjos
Portugal
http://www.cadtom.com
Back to Top
msplcdykee69 View Drop Down
Senior Member
Senior Member


Joined: 15.Dec.2008
Location: United States
Using: Civil 3D, Map, Inventor, Mechanical, & Electrical
Status: Offline
Points: 163
Direct Link To This Post Posted: 27.Aug.2009 at 22:53

Here is a lisp that collects the lengths of lines or polylines on selected layers:

;;; LENLYR.LSP a program to find the length of all
;;; entities on any selected layer
;;;
(defun err (s)
  (if (= s "Function cancelled")
    (princ "\nLENLYR - cancelled: ")
    (progn (princ "\nLENLYR - Error: ") (princ s)
    (terpri))
  ); if
  (resetting)
  (princ "SYSTEM VARIABLES have been reset\n")
  (princ)
); err
(defun setv (systvar newval)
   (setq x (read (strcat systvar "1")))  
   (set x (getvar systvar))
   (setvar systvar newval)
); setv
(defun setting ()
   (setq oerr *error*)
   (setq *error* err)
   (setv "CMDECHO" 0)
   (setv "BLIPMODE" 0)
); end of setting
(defun rsetv (systvar)
   (setq x (read (strcat systvar "1")))
   (setvar systvar (eval x))
); restv
(defun resetting ()
   (rsetv "CMDECHO")
   (rsetv "BLIPMODE")
   (setq *error* oerr)
); end of resetting

(defun dxf (code ename)
  (cdr (assoc code (entget ename)))
); dxf

(defun lenlyr ( / LayerList EntityList EntityLengths)
  (setq LayerList (get-lyrs)
        EntityList (get-ents LayerList)
        EntityLengths (do-len EntityList)
  ) ; setq
  (prin1 (read (rtos EntityLengths 2 2)))
); lenlyr

(defun get-lyrs ( / isent lyr-list ss i lname)
  (setq isent nil lyr-list nil)
  (prompt
       "\nSelect object(s) on required layer(s): ")
  (setq ss nil)
  (while (not ss)
    (setq ss (ssget))
    (if (not ss)
        (prompt "\nNo entities were selected.")
    ); if
  ); while
  (setq i (- 1))
  (repeat (sslength ss)
    (setq lname (dxf 8 (ssname ss (setq i (1+ i)))))
    (if (not (member lname lyr-list)) 
      (setq lyr-list (append lyr-list (list lname)))
    ); if
  ); repeat
  lyr-list
); get-lyrs

(defun get-ents (LayerList / lstr lst lyr str
      filtlist i ss ename elist)
  (setq lstr (strcat (car LayerList) ","))
  (setq lst (cdr LayerList))
  (foreach lyr lst
    (setq str (strcat lyr ",")
          lstr (strcat lstr str)
    ); setq
  ); foreach
  (setq lstr (substr lstr 1 (1- (strlen lstr))))
  (setq filtlist (list
       (cons 8 lstr)
        '(-4 . "<or")
          '(0 . "LINE")
          '(0 . "ARC")
          '(0 . "CIRCLE")
          '(0 . "POLYLINE")
          '(0 . "LWPOLYLINE")
        '(-4 . "or>")
    ); list
  ); setq
  (setq i (- 1) elist nil ss nil)
  (setq ss (ssget "X" filtlist))
  (if ss
    (progn
      (repeat (sslength ss)
        (setq ename (ssname ss (setq i (1+ i))))
        (setq elist (append elist (list ename)))
      ); repeat
      (princ (strcat "\nTotal length of all "
            "entities on layer(s) " lstr ": ")
      ); print
     ); progn
     (progn
       (alert (strcat "No eligible entities on "
                "layer(s) \n" lstr "\naborting."))
       (exit)
     ); progn
   ); if
  elist
); get-ents

(defun do-len (EntityList / TotalLength ent len)
  (setq TotalLength 0 len 0)
  (foreach ent EntityList
    (setq len (ent-len ent))
    (if len
      (setq TotalLength (+ len TotalLength))
    ); if
  ); foreach
); do-len

(defun ent-len (en / elength)
  (setq elength
    (cond
      ((= (dxf 0 en ) "LINE") (do-line en))
      ((= (dxf 0 en ) "ARC") (do-arc en))
      ((= (dxf 0 en ) "CIRCLE") (do-circle en))
      ((= (dxf 0 en ) "POLYLINE") (do-pline en))
      ((= (dxf 0 en ) "LWPOLYLINE") (do-lwpline en))
    ); cond
  ); setq
  elength
); ent-len

(defun do-line (en / p10 p11 len)
  (setq p10 (dxf 10 en)
        p11 (dxf 11 en)
        len (distance p10 p11)
  ); setq
  len
); do-line

(defun do-arc (en / rad sang eang theta len)
  (setq rad (dxf 40 en)
        sang (dxf 50 en)
        eang (dxf 51 en)
        theta (- eang sang)
  ); setq
  (if (minusp theta)
    (setq theta (+ theta pi pi))
  ); if
  (setq len (* rad theta))
); do-arc

(defun do-circle (en / rad len)
  (setq rad (dxf 40 en)
        len (* rad pi 2)
  ); setq
  len
); do-circle

(defun do-pline (en / is-closed vlist vvlist len)
  (setq is-closed (dxf 70 en))
  (if (/= is-closed 100)
    (progn
      (setq en (entnext en))
      (setq vlist nil
            vvlist nil
      ); setq
      (while (/= "SEQEND" (dxf 0 en))
        (setq vlist (dxf 10 en)
              vlist (reverse vlist)
              vlist (cdr vlist)
              vlist (list (reverse vlist))
        ); setq
        (setq vlist
          (append vlist (list (dxf 42 en))))
        (setq vvlist (append vvlist (list vlist)))
        (setq en (entnext en))
      ); while
    ); progn
  ); if
  (setq len (do-polylen vvlist is-closed))
); do-pline

(defun do-lwpline (en / num-vert is-closed elist
     vlist vvlist len)
  (setq num-vert (dxf 90 en)
        is-closed (dxf 70 en)
        elist (entget en)
        elist (member (assoc 10 elist) elist)
        vlist nil
        vvlist nil
  ); setq
  (repeat num-vert
    (setq vlist (list (cdr (assoc 10 elist))))
    (setq vlist
       (append vlist (list (cdr (assoc 42 elist)))))
    (setq vvlist (append vvlist (list vlist)))
    (setq elist (cdr elist)
          elist (member (assoc 10 elist) elist)
    ); setq
  ); repeat
  (setq len (do-polylen vvlist is-closed))
); do-lwpline

(defun do-polylen (vvlist is-closed / closed seglen
     plen first p10 p11 bulge)
  (setq closed (logand is-closed 1)
        seglen 0
        plen 0
  ); setq
  (if (= closed 1)
    (progn
      (setq first (car vvlist)
            vvlist (append vvlist (list first))
      ); setq
    ); progn
  ); if
  (repeat (1- (length vvlist))
    (setq p10 (caar vvlist)
          p11 (caadr vvlist)
          bulge (cadar vvlist)
    ); setq
    (setq seglen (do-seg p10 p11 bulge))
    (setq plen (+ plen seglen))
    (setq vvlist (cdr vvlist))
  ); repeat
  plen
); do-polylen

(defun do-seg (p1 p2 bulg / seglen ang4 ang dis rad)
  (if (= bulg 0.0)
    (progn
       (setq seglen (distance p1 p2))
    ); progn
    (progn
      (setq ang4 (atan bulg)
            ang (* 4.0 ang4)
            dis (distance p1 p2)
            rad (/ (/ dis 2.0) (sin (/ ang 2.0)))
            seglen (* rad ang)
       ); setq
    ); progn
  ); if
  seglen
); do-seg

(defun c:lnl ()
   (setting)
   (lenlyr)
   (resetting)
   (princ)
); c:lnl

(prompt "\nEnter LNL to start")



Edited by msplcdykee69 - 27.Aug.2009 at 22:54
Engineering Manufacturing Medical Cables/Adjunct Instructor Engineering Graphics/Engineering Computations and Careers

msplcdykee69@yahoo.com

Shawn
Back to Top
jmontesmx View Drop Down
Senior Member
Senior Member


Joined: 28.Jan.2008
Location: Mexico
Using: AutoCad2017
Status: Offline
Points: 113
Direct Link To This Post Posted: 27.Aug.2009 at 16:33

Excuse me, can you explain me more, I'm trying to use your directions but I can't do it.  I'm using Autocad 2007 may be this is the reason.

Thanks.
Back to Top
jorgeanjos View Drop Down
Newbie
Newbie


Joined: 18.Aug.2009
Location: Portugal
Status: Offline
Points: 4
Direct Link To This Post Posted: 27.Aug.2009 at 12:08

Olá,

I have some AutoLISP applications (written in portuguese and not translated yet) in my site  that return the total of perimeters, areas and volumes (3dsolids).
Some have the possibility to put the result in text, but you can just try the somaper.lsp (http://www.cadtom.com/Arquivo/AutoLISP/Somaper.zip). It shows on commands line the total length of select AutoCAD entities.
Write somaper in the commands line.

Jorge Anjos
Portugal
http://www.cadtom.com
Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

Arkance Systems CZ

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 2124
Direct Link To This Post Posted: 27.Aug.2009 at 09:38
You can use the Report Lengths function in LT Extension - it sums up line lenghts (by layers).
Vladimir Michl (moderator)
ARKANCE - https://arkance.world - Autodesk Platinum Partner
Back to Top
jmontesmx View Drop Down
Senior Member
Senior Member


Joined: 28.Jan.2008
Location: Mexico
Using: AutoCad2017
Status: Offline
Points: 113
Direct Link To This Post Posted: 27.Aug.2009 at 02:18

Sometimes I choose some lines with a list command to obtain the lenght of them, but this is so bored when take a lot of lines , curves, etc. , I will apreciatte if somebody can help me to obtain the sum total of them more quickly

Back to Top

Related CAD tips:


 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0,164 seconds.