TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: daron on July 19, 2005, 03:32:55 PM

Title: standard lisp method from this:
Post by: daron on July 19, 2005, 03:32:55 PM
Code: [Select]
(vla-get-length (vlax-ename->vla-object (car (entsel))))
In the most simple explanation I need to get the length of a polyline. More complexly, I need to add up all the distances of coordinate points in a list. I have a list like this:
Code: [Select]
(10 861.923 1002.4 0.0)
(1019.92 994.396 0.0)
 (1011.92 1077.9 0.0)
 (1101.92 1061.9 0.0)
 (1093.92 1129.15 0.0)
 (1125.92 1121.15 0.0)
 (1117.92 1173.15 0.0)
 (1101.92 1181.15 0.0)

I need the length of that. Here's what I came up with, but it's not quite right.
Code: [Select]
(defun linedistance (obj / dis culmin distan)
     (setq dis nil
  culmin 0
     )
     (foreach item obj
 (setq dis (append dis (list (cdr item))))
     )
     (while (> (length dis) 1)
 (setq distan (distance (nth 0 dis) (nth 1 dis))
culmin (+ culmin distan)
dis    (cdr dis)
 )
     )
     culmin
)

Anybody want to point me in the right direction of offer up something better. I appreciate it. Thanks.
Title: standard lisp method from this:
Post by: whdjr on July 19, 2005, 04:14:20 PM
Try this (http://www.theswamp.org/phpBB2/viewtopic.php?p=70149#70149) for starters.  You can read the whole post for more info.
Title: Re: standard lisp method from this:
Post by: LE on July 19, 2005, 04:45:25 PM
See if this helps:

Code: [Select]

(defun get_total  (lst / cont)
  (setq total 0
cont 0)
  (while (< cont (length lst))
    (if (and (nth cont lst) (nth (1+ cont) lst))
      (setq total (+ (distance (nth cont lst)
      (nth (1+ cont) lst))
    total)))
    (setq cont (1+ cont)))
  total)
Title: standard lisp method from this:
Post by: daron on July 20, 2005, 07:35:51 AM
Thanks LE. That's simple and very close to what I had.
Title: standard lisp method from this:
Post by: CAB on July 20, 2005, 08:25:37 AM
Daron,
 I'm sure you are aware but for those lurking, if the pline is closed you must add another point to the list for the final segment.
Also arcs within the pline are not addressed in this length method. vlax-curve-getdistatpoint sure makes life easier. :)
Title: standard lisp method from this:
Post by: whdjr on July 20, 2005, 11:27:50 AM
Quote from: CAB
Daron,
 I'm sure you are aware but for those lurking, if the pline is closed you must add another point to the list for the final segment.
Also arcs within the pline are not addressed in this length method. vlax-curve-getdistatpoint sure makes life easier. :)

To add to what CAB is saying the link I posted earlier has some code to find the length of a 'curve object' (whether curved or not) even if it is closed.
Title: standard lisp method from this:
Post by: LE on July 20, 2005, 11:39:02 AM
One more time my lost in translation thing....

The topic said:

"Standard lisp method for this"

I was assuming no use of any vlisp function no?

Or I am in another hole?

:)
Title: standard lisp method from this:
Post by: CAB on July 20, 2005, 12:00:30 PM
LE,
I think you got it right.
I was just commenting on how vlax-curve made life easier, even though Daron specifically
asked for the routine not to use vlisp.
Title: standard lisp method from this:
Post by: daron on July 20, 2005, 12:24:58 PM
Thank you. I will keep in mind all thoughts as I do have to deal with arcs, rarely. I have an old routine that I could probably put in to take care of the arcs problem. So, if I have a closed pline, I should add the first element to the end of the list? I had forgottrn that.