Author Topic: Polyline Length?  (Read 4244 times)

0 Members and 1 Guest are viewing this topic.

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Polyline Length?
« on: May 26, 2004, 04:15:13 PM »
I've been looking and looking, etc., but as of yet haven't figured out how to get the length of a polyline in lisp.

How would I go about doing this?

I know it can be done, as when you list a polyline, you get a length.

Please help.

Thanks.
I drink beer and I know things....

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Polyline Length?
« Reply #1 on: May 26, 2004, 04:35:40 PM »
Ill give you a hint:

"Explode"
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Anonymous

  • Guest
Polyline Length?
« Reply #2 on: May 26, 2004, 04:39:14 PM »
Like this......
Code: [Select]

(defun getlength (ent / objPoly len)
  (if (wcmatch (strcase (cdr (assoc 0 (entget (car ent))))) "*LINE,ARC")
    (setq objPoly (vlax-ename->vla-object (car ent))
 len   (vlax-curve-getdistAtParam objPoly
 (vlax-curve-getEndParam objPoly))
 )
    )
  )

(defun c:length ( / ent)
  (if (setq ent (entsel "\nSelect object to obtain length for: "))
    (if (setq len (getlength ent))
      (princ (strcat "\nObject length is: " (rtos len)))
      (princ "\nObject doesn't have a length.")
      )
    (princ "\nNothing selected, exiting...")
    )
  (princ)
  )


Jeff

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Polyline Length?
« Reply #3 on: May 26, 2004, 04:42:59 PM »
Se7en Thanks for that, we'll see where we go from there.
I drink beer and I know things....

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Polyline Length?
« Reply #4 on: May 26, 2004, 04:43:15 PM »
or like that ^. LoL
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Polyline Length?
« Reply #5 on: May 26, 2004, 04:45:15 PM »
Ya sure, that's the ticket. :D
I drink beer and I know things....

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Polyline Length?
« Reply #6 on: May 26, 2004, 04:55:51 PM »
Well, I forgot which board I was viewing and didn't realize that I was just a Guest when I posted that solution. Now I'm all logged in and official and will state for the record that the masked Guest above was, in fact, I.  :lol:

Jeff

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Polyline Length?
« Reply #7 on: May 26, 2004, 04:56:55 PM »
Thank You much, Jeff :D
I drink beer and I know things....

SMadsen

  • Guest
Polyline Length?
« Reply #8 on: May 28, 2004, 10:25:19 AM »
Here's one that reports all plines on a specific layer (inspired from a discussion on the CADTutor forum):

Code: [Select]
(defun c:PLLEN (/ a ar cl cn i l la le obj ss)
  (cond ((setq ss (entsel "\nPick any object on the required layer: "))
         (setq la (cdr (assoc 8 (entget (car ss)))))
         (mapcar 'set '(ar le cn i)'((0 0)(0 0) 0 0))
         (cond ((setq ss (ssget "X" (list '(0 . "*POLYLINE") (cons 8 la)
                                        '(-4 . "<") '(70 . 8)))
                )
                (repeat (sslength ss)
                  (setq obj (vlax-ename->vla-object (ssname ss i))
                        a   (vlax-curve-getArea obj)
                        l   (vlax-curve-getDistAtParam obj
                                 (vlax-curve-getEndParam obj))
                        cl  (vlax-curve-isClosed obj)
                        ar  (mapcar '+ ar (if cl (list a 0)(list 0 a)))
                        le  (mapcar '+ le  (if cl (list l 0)(list 0 l)))
                        cn  (+ cn (if cl 1 0))
                        i   (1+ i)
                  )
                )
                (mapcar 'princ (list "\nTotal length: " (apply '+ le) " (closed: " (car le)
                                     ")\nTotal area: " (apply '+ ar) " (closed: " (car ar)
                                     ")\n" (sslength ss) " plines on layer " la " (closed: " cn ")")
                )
               )
               ((princ "\nNone found"))
         )
        )
  )
  (princ)
)

Slim©

  • Needs a day job
  • Posts: 6566
  • The Dude Abides...
Polyline Length?
« Reply #9 on: May 28, 2004, 10:42:58 AM »
Very Nice I like it. THX :D
I drink beer and I know things....

SMadsen

  • Guest
Polyline Length?
« Reply #10 on: May 28, 2004, 11:15:19 AM »
Great. You're welcome