Author Topic: cumulated length of several plines  (Read 3573 times)

0 Members and 1 Guest are viewing this topic.

LBC

  • Guest
cumulated length of several plines
« on: April 22, 2004, 09:59:40 AM »
Hi
Does any of you have a lisp that is able to calculate the total length of several plines. Please!!!!

Lars
Bordeaux, France

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
cumulated length of several plines
« Reply #1 on: April 22, 2004, 11:14:05 AM »
I do believe there is a routine in the new Cadlyst mag...lemme find it on their website for ya

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
cumulated length of several plines
« Reply #2 on: April 22, 2004, 11:18:07 AM »
Haven't tested it, but HERE it is.

Here's the code in it for you to look at also...
Code: [Select]

;;CADALYST 04/04 Tip1939:  LL.LSP  Length of Linear Objects    (c) 2004 Will DeLoach

(defun c:ll (/ sset num llen)
  (setq sset (ssget '((0 . "LINE,LWPOLYLINE")))
num  0
llen 0
  )
  (if sset
    (progn
      (repeat (sslength sset)
(setq llen
      (+ llen
 (vla-get-length (vlax-ename->vla-object (ssname sset num)))
      )
)
(setq num (1+ num))
      )
      (setq num (rtos num 2 0)
   llen (rtos llen 4)
      )
      (alert (strcat num " line lengths = " llen))
    )
  )
)

Anonymous

  • Guest
cumulated length of several plines
« Reply #3 on: April 22, 2004, 11:54:56 AM »
thanks a lot  :D
I've been looking all over the web for 2 days now, whith out finding anything. I'll run a test to see if it works. :dood:

ronjonp

  • Needs a day job
  • Posts: 7527
cumulated length of several plines
« Reply #4 on: April 22, 2004, 11:56:20 AM »
This will calculate total length of polylines on a specific layer. First object pick sets layer then select object needed.




Code: [Select]
(defun C:PLEN ( / layname s count len en ed count )

   (setvar "CMDECHO" 0)                     ;0 to hide command echos
   (setq layname (cdr (assoc 8
      (entget (car (entsel "Select entity to define layer totaled: "))))))
   (prompt "\nSelect items to total:")
   (setq
      S (ssget)                            ; Get all entities marked by user
      count 0
      len 0
   )
   (lfeed 3)
   (setvar "OSMODE" 0)

   (repeat (sslength S)
      (setq
         en (ssname S count)
         ed (entget en)
         count (1+ count)
      )
(if (and (= (dxf 8 ed) layname ) (= (dxf 0 ed) "POLYLINE")) (progn
         (command                           ;Get area value
            ".AREA"
            "E"
            en
             )
         (setq len (+ len (getvar "perimeter")))
         ))
(if (and (= (dxf 8 ed) layname ) (= (dxf 0 ed) "REGION")) (progn
         (command                           ;Get area value
            ".AREA"
            "E"
            en
             )
         (setq len (+ len (getvar "perimeter")))
         ))
(if (and (= (dxf 8 ed) layname ) (= (dxf 0 ed) "LWPOLYLINE")) (progn
         (command                           ;Get area value
            ".AREA"
            "E"
            en
             )
         (setq len (+ len (getvar "perimeter")))
         ))
(if (and (= (dxf 8 ed) layname ) (= (dxf 0 ed) "SPLINE")) (progn
         (command                           ;Get area value
            ".AREA"
            "E"
            en
             )
         (setq len (+ len (getvar "perimeter")))
         ))
(if (and (= (dxf 8 ed) layname ) (= (dxf 0 ed) "CIRCLE")) (progn
         (command                           ;Get area value
            ".AREA"
            "E"
            en
             )
         (setq len (+ len (getvar "perimeter")))
         ))
   ); end repeat
   (alert (strcat "\nThe Total Length of Selected Closed Polylines on Layer \""(princ layname)"\" is: "(rtos len (getvar "lunits") 0)))
   (prompt (strcat "\n "(rtos len (getvar "lunits") 0)))
   (princ)
);defun

;;;----------------------------------------------------------
;;;| LFEED                                                  |
;;;| Prints the number of line feeds passed to it.          |
;;;|                                                        |
;;;----------------------------------------------------------

(defun lfeed      (
                  count          ; number of line feeds to print
                  )

   (repeat (1- count) (princ "\n "))
   (princ "\n")

   (princ)
); defun
;;;*
(if debug (princ "lfeed loaded\n"))


;;;----------------------------------------------------------
;;;| DXF                                                    |
;;;| Takes an integer dxf code and an entity or entity data |
;;;| list and returns the data element of the association   |
;;;| pair.                                                  |
;;;|                                                        |
;;;----------------------------------------------------------

(defun dxf        (
                  code           ; DXF code
                  ed             ; Entity name or data list
                  )

                                             ; Turn entity name into entity data
  (if (and (not (listp ed)) ed) (setq ed (entget ed)))
  (cdr (assoc code ed))                      ; Find association pair & strip 1st element
); defun
;;;*
(if debug (princ "dxf loaded\n"))

(C:plen)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
cumulated length of several plines
« Reply #5 on: April 22, 2004, 12:29:54 PM »
Tested out the one I posted from Cadlyst...works just how it sounds you want it to...

ronjonp

  • Needs a day job
  • Posts: 7527
cumulated length of several plines
« Reply #6 on: April 22, 2004, 12:32:48 PM »
Code: [Select]
(alert (strcat "\nThe Total Length of Selected Closed Polylines on Layer

should read (alert (strcat "\nThe Total Length of Selected Polylines on Layer...

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
cumulated length of several plines
« Reply #7 on: April 22, 2004, 12:34:55 PM »
If I were going to write one it might look like this:
Code: [Select]

(defun ss->vla-list (ss lst)
  (cond ((ssname ss 0)
    (setq lst (vl-list*
      (vlax-ename->vla-object (ssname ss 0)) lst))
     (ss->vla-list (ssdel (ssname ss 0) ss) lst)); 1st cond
    ((null (ssname ss 0)) lst); 2nd cond
    ); cond
  )

(defun get-dist (obj)
  (if (vlax-property-available-p obj 'Length)
    (vlax-get-property obj 'Length)
    )
  )

(defun c:pline-length ( / ss vl_lst total_length)
  (vl-load-com)
  (gc)
  (if (setq ss (ssget '((0 . "LWPOLYLINE"))))
    (setq vl_lst (ss->vla-list ss nil))
    )

  (if vl_lst
    (progn
      (setq total_length (apply '+ (mapcar 'get-dist vl_lst)))
      (princ
        (strcat "\nTotal Length of selected Polylines = "
                (rtos total_length)
                )
        )
      )
    )
  (princ)
)


I wonder which one is faster ...............!!
TheSwamp.org  (serving the CAD community since 2003)

lbc

  • Guest
cumulated length of several plines
« Reply #8 on: April 22, 2004, 01:02:14 PM »
Yeps it works beautifully, i only had to change the rtos value to get the metric systeme.
Thanks again


 :D  :D Lars