TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: daron on July 19, 2005, 03:32:55 PM
-
(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:
(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.
(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.
-
Try this (http://www.theswamp.org/phpBB2/viewtopic.php?p=70149#70149) for starters. You can read the whole post for more info.
-
See if this helps:
(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)
-
Thanks LE. That's simple and very close to what I had.
-
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. :)
-
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.
-
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?
:)
-
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.
-
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.