Author Topic: TOTAL LENGTH OF LINE FOR MULTIPLE LINES  (Read 12335 times)

0 Members and 1 Guest are viewing this topic.

mdsadiq1508

  • Guest
TOTAL LENGTH OF LINE FOR MULTIPLE LINES
« on: September 05, 2014, 07:23:54 AM »
Dear All,
I want to know how to get Total Length of a multiple (separate) lines in one command.
Ex; when I enter LIST command and select the multiple line I will get separate lengths, But I want Total length at a Time with a one command.


Please give the reply..


ronjonp

  • Needs a day job
  • Posts: 7531
Re: TOTAL LENGTH OF LINE FOR MULTIPLE LINES
« Reply #1 on: September 05, 2014, 09:01:18 AM »
There are many solutions to this but here is another one. Welcome to TheSwamp.  :)
Code - Auto/Visual Lisp: [Select]
  1. (defun c:addlengths (/ _getlength i n ss)
  2.   (defun _getlength (ename / ep)
  3.     (if (vl-catch-all-error-p (setq ep (vl-catch-all-apply 'vlax-curve-getendparam (list ename))))
  4.       0.0
  5.       (vlax-curve-getdistatparam ename ep)
  6.     )
  7.   )
  8.   (if (setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE"))))
  9.     (progn (setq n 0)
  10.            (repeat (setq i (sslength ss)) (setq n (+ n (_getlength (ssname ss (setq i (1- i)))))))
  11.            (alert (vl-princ-to-string n))
  12.     )
  13.   )
  14.   (princ)
  15. )
« Last Edit: September 08, 2014, 09:16:23 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: TOTAL LENGTH OF LINE FOR MULTIPLE LINES
« Reply #2 on: September 05, 2014, 09:12:51 AM »
Another, using the same method as Ron: Total Length & Area Programs.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: TOTAL LENGTH OF LINE FOR MULTIPLE LINES
« Reply #3 on: September 05, 2014, 09:23:41 AM »
Another, using the same method as Ron: Total Length & Area Programs.
Your site looks awesome Lee  8) . You might want to add REGION to your selection set filter for you TAREA routine.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: TOTAL LENGTH OF LINE FOR MULTIPLE LINES
« Reply #4 on: September 05, 2014, 05:45:32 PM »
Another, using the same method as Ron: Total Length & Area Programs.
Your site looks awesome Lee  8) .

Cheers Ron! - That means a lot coming from you  :-)

You might want to add REGION to your selection set filter for you TAREA routine.

I thought about adding an extra condition for querying the area of REGIONs (since vlax-curve-getarea will not work on REGIONs of course), but I preferred to keep the program simplified & succinct and so opted not to  :|

Thanks for the cheese though :)

bilançikur

  • Newt
  • Posts: 82
Re: TOTAL LENGTH OF LINE FOR MULTIPLE LINES
« Reply #5 on: September 08, 2014, 05:08:08 AM »

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: TOTAL LENGTH OF LINE FOR MULTIPLE LINES
« Reply #6 on: September 08, 2014, 09:05:15 AM »
I'll throw one more in that I use and have pointed others to for many years:    TLEN.LSP at http://www.turvill.com/t2/free_stuff/



HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: TOTAL LENGTH OF LINE FOR MULTIPLE LINES
« Reply #7 on: September 10, 2014, 01:53:17 AM »
Try this
Code: [Select]
;;;---------------------------------------------------------------------------;
;;;
;;; lengths.lsp
;;;
;;; By Jimmy Bergmark
;;; Copyright (C) 1997-2007 JTB World, All Rights Reserved
;;; Website: www.jtbworld.com
;;; E-mail: info@jtbworld.com
;;;
;;; 1998-03-31 - First release
;;; 2000-05-11 - Fixed for LWPOLYLINES and for A2k
;;; 2003-06-10 - Tested on 2004 and fixed a minor bug
;;; 2004-03-18 - Added (vl-load-com)
;;; 2007-09-24 - Shows the result in the active unit
;;; Tested on AutoCAD 2000, 2004, 2005, 2008
;;; should be working on older versions too with minor modifications.
;;;  exchange bom-code-old with bom-code
;;;
;;;---------------------------------------------------------------------------;
;;;  DESCRIPTION
;;;
;;;  BILL OF LENGTHS. Get the accumulated sum length of multiple objects.
;;;  c:lengths - length of lines, arcs, polylines and splines and total.
;;;  c:bom_lines - length of lines and total.
;;;  c:bom_arcs - length of arcs, and total.
;;;  c:bom_polylines - length of polylines and total.
;;;  c:bom_splines - length of splines and total.
;;;---------------------------------------------------------------------------;

(defun dxf (n ed) (cdr (assoc n ed)))

(defun bom-code (ssfilter        /       errexit undox   restore
                 *error* olderr  oldcmdecho      %l      %t
                 sset    %i      en      ed      p1      p2
                 ot      a1      a2      r
                )
  (defun errexit (s)
    (princ)
    (restore)
  )

  (defun undox ()
    (command "._undo" "_E")
    (setvar "cmdecho" oldcmdecho)
    (setq *error* olderr)
    (princ)
  )

  (setq olderr  *error*
        restore undox
        *error* errexit
  )
  (setq oldcmdecho (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (command "._UNDO" "_BE")
  (setq %i 0
        %t 0
  )
  (vl-load-com)
  (setq sset (ssget ssfilter))
  (if sset
    (progn
      (princ "\nLengths:")
      (repeat (sslength sset)
(setq en (ssname sset %i))
(setq ed (entget en))
(setq ot (dxf 0 ed))
(setq curve (vlax-ename->vla-object en))
(if (vl-catch-all-error-p
      (setq len (vl-catch-all-apply
  'vlax-curve-getDistAtParam
  (list curve
(vl-catch-all-apply
  'vlax-curve-getEndParam
  (list curve)
)
  )
)
      )
    )
  nil
  len
)
(setq %l len)

(setq %i (1+ %i)
      %t (+ %l %t)
)
(terpri)
;(princ %l )
(princ (rtos %l (getvar "lunits")(getvar "luprec")))
      )
      (princ "\nTotal = ")
      ;(princ %t)
      (princ (rtos %t (getvar "lunits")(getvar "luprec")))
      (textpage)
    )
  )
  (restore)
)

(defun bom-code-old (ssfilter        /       errexit undox   restore
                 *error* olderr  oldcmdecho      %l      %t
                 sset    %i      en      ed      p1      p2
                 ot      a1      a2      r
                )
  (defun errexit (s)
    (princ)
    (restore)
  )

  (defun undox ()
    (command "._undo" "_E")
    (setvar "cmdecho" oldcmdecho)
    (setq *error* olderr)
    (princ)
  )

  (setq olderr  *error*
        restore undox
        *error* errexit
  )
  (setq oldcmdecho (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (command "._UNDO" "_BE")
  (setq %i 0
        %t 0
  )
  (setq sset (ssget ssfilter))
  (if sset
    (progn
      (princ "\nLengths:")
      (repeat (sslength sset)
        (setq en (ssname sset %i))
        (setq ed (entget en))
        (setq ot (dxf 0 ed))
        (cond
          ((= ot "LINE")
           (setq p1 (dxf 10 ed)
                 p2 (dxf 11 ed)
                 %l (distance p1 p2)
           )
          )
          ((= ot "ARC")
           (setq a1 (dxf 50 ed)
                 a2 (dxf 51 ed)
                 r  (dxf 40 ed)
                 %l (* r (abs (- a2 a1)))
           )
          )
          (t
           (command "._area" "_obj" en)
           (setq %l (getvar "perimeter"))

          )
        )
        (setq %i (1+ %i)
              %t (+ %l %t)
        )
        (terpri)
        (princ %l)
      )
      (princ "\nTotal = ")
      (princ %t)
      (textpage)
    )
  )
  (restore)
)

(defun c:lengths ()
  (initget "Lines Arcs Polylines Splines ALL")
  (setq ans (getkword
              "Enter an option [Lines/Arcs/Polylines/Splines] <ALL>: "
            )
  )
  (cond
    ((= ans "Lines") (c:bom_lines))
    ((= ans "Arcs") (c:bom_arcs))
    ((= ans "Polylines") (c:bom_polylines))
    ((= ans "Splines") (c:bom_splines))
    (t
     (bom-code '((-4 . "<OR")
                 (0 . "LINE")
                 (0 . "ARC")
                 (0 . "POLYLINE")
                 (0 . "LWPOLYLINE")
                 (0 . "SPLINE")
                 (-4 . "OR>")
                )
     )
    )
  )
  (princ)
)

(defun c:bom_lines ()
  (bom-code '((0 . "LINE")))
  (princ)
)

(defun c:bom_arcs ()
  (bom-code '((0 . "ARC")))
  (princ)
)

(defun c:bom_polylines ()
  (bom-code '((-4 . "<OR")
              (0 . "POLYLINE")
              (0 . "LWPOLYLINE")
              (-4 . "OR>")
             )
  )
  (princ)
)

(defun c:bom_splines ()
  (bom-code '((0 . "SPLINE")))
  (princ)
)



owenwengerd

  • Bull Frog
  • Posts: 451
Re: TOTAL LENGTH OF LINE FOR MULTIPLE LINES
« Reply #8 on: September 10, 2014, 11:29:45 AM »
When you post copyrighted code, please include a statement explaining that you have permission from the copyright owner.

;;; Copyright (C) 1997-2007 JTB World, All Rights Reserved



DuanJinHui

  • Guest
Re: TOTAL LENGTH OF LINE FOR MULTIPLE LINES
« Reply #11 on: May 27, 2015, 11:48:57 PM »
many many example ... Thx for sharing.