Author Topic: standard lisp method from this:  (Read 2660 times)

0 Members and 1 Guest are viewing this topic.

daron

  • Guest
standard lisp method from this:
« 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.

whdjr

  • Guest
standard lisp method from this:
« Reply #1 on: July 19, 2005, 04:14:20 PM »
Try this for starters.  You can read the whole post for more info.

LE

  • Guest
Re: standard lisp method from this:
« Reply #2 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)

daron

  • Guest
standard lisp method from this:
« Reply #3 on: July 20, 2005, 07:35:51 AM »
Thanks LE. That's simple and very close to what I had.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
standard lisp method from this:
« Reply #4 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. :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

whdjr

  • Guest
standard lisp method from this:
« Reply #5 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.

LE

  • Guest
standard lisp method from this:
« Reply #6 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?

:)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
standard lisp method from this:
« Reply #7 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.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
standard lisp method from this:
« Reply #8 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.