Jump to content

Recommended Posts

Posted

Hi

 

I would like to create a cummulative list of lengths (from the start) between an open polyline vertices.

So for example if I have a pline with 5 vertices then from the first vertice to the second

vertice I would have say a length of 20 then the second to the third 12 then third to fourth 18, then fourth to fifth 25.

So my list would look like something :

 

x = (20,32,50,75)

 

I can only get as far as making a points lists! Thanks any help is sincerely appreciated!

 

SF

Posted

Two methods I can think of:

 

(defun c:test1 ( / e i m l )
 (if
   (and
     (setq e (car (entsel "\nSelect LWPline: ")))
     (eq "LWPOLYLINE" (cdr (assoc 0 (entget e))))
   )
   (progn
     (setq i 0 m (vlax-curve-getendparam e))
     (while (<= (setq i (1+ i)) m)
       (setq l (cons (- (vlax-curve-getdistatparam e i) (vlax-curve-getdistatparam e (1- i))) l))
     )
   )
 )
 (reverse l)
)

 

(defun c:test2 ( / e p l )
 (if
   (and
     (setq e (car (entsel "\nSelect LWPline: ")))
     (eq "LWPOLYLINE" (cdr (assoc 0 (setq e (entget e)))))
   )
   (progn
     (while (setq p (assoc 10 e))
       (setq l (cons (cdr p) l) e (cdr (member p e)))
     )
     (setq l (reverse l))
     (mapcar 'distance l (cdr l))
   )
 )
)

 

The second assumes only straight polyline segments.

Posted

Thanks Lee that's great

- however - sorry I forgot to say 3d polylines.

I just changed LWPOLYLINE to POLYLINE

many thanks

Posted

3D Polylines will require a change to the second method:

 

(defun c:test2 ( / e l )
 (if
   (and
     (setq e (car (entsel "\nSelect Polyline: ")))
     (eq "POLYLINE" (cdr (assoc 0 (entget e))))
   )
   (progn
     (while (eq "VERTEX" (cdr (assoc 0 (entget (setq e (entnext e))))))
       (setq l (cons (cdr (assoc 10 (entget e))) l))
     )
     (setq l (reverse l))
     (mapcar 'distance l (cdr l))
   )
 )
)

Posted

thanks - it seems both of your methods work. The only problem is that the distances given are not cummulative.

From the start I want the list values to get larger until the last one equals that total length of the 3d - pline.

Posted

Oops! Forgot about the cumulative part - well, that simplifies things:

 

(defun c:test1 ( / e i m l )
 (if
   (and
     (setq e (car (entsel "\nSelect Polyline: ")))
     (eq "POLYLINE" (cdr (assoc 0 (entget e))))
   )
   (progn
     (setq i 0 m (vlax-curve-getendparam e))
     (while (<= (setq i (1+ i)) m)
       (setq l (cons (vlax-curve-getdistatparam e i) l))
     )
   )
 )
 (reverse l)
)

 

Or even just:

 

(defun c:test1 ( / e i l )
 (if
   (and
     (setq e (car (entsel "\nSelect Polyline: ")))
     (eq "POLYLINE" (cdr (assoc 0 (entget e))))
   )
   (progn
     (setq i 0)
     (while (car (setq l (cons (vlax-curve-getdistatparam e (setq i (1+ i))) l))))
   )
 )
 (reverse (cdr l))
)

Posted

Or, using the other method:

 

(defun c:test2 ( / e l x )
 (if
   (and
     (setq e (car (entsel "\nSelect Polyline: ")))
     (eq "POLYLINE" (cdr (assoc 0 (entget e))))
   )
   (progn
     (while (eq "VERTEX" (cdr (assoc 0 (entget (setq e (entnext e))))))
       (setq l (cons (cdr (assoc 10 (entget e))) l))
     )
     (setq l (reverse l) x 0)
     (mapcar '(lambda ( a b ) (setq x (+ x (distance a b)))) l (cdr l))
   )
 )
)

Posted

Perfect many thanks Lee

Posted

Lee - Sorry for asking again but I wonder if you could tweak your "Test2" so that only horizontal lengths (plan lengths) are given? I have tried for a couple of hours to amend your code, but with no luck.

Posted

Do you mean 2D lengths? (i.e. Points projected to the XY-plane)

Posted

Do you mean 2D lengths? (i.e. Points projected to the XY-plane)

 

Yes I do

Posted
(defun c:test2 ( / e l x )
 (if
   (and
     (setq e (car (entsel "\nSelect Polyline: ")))
     (eq "POLYLINE" (cdr (assoc 0 (entget e))))
   )
   (progn
     (while (eq "VERTEX" (cdr (assoc 0 (entget (setq e (entnext e))))))
       (setq l (cons (cdr (assoc 10 (entget e))) l))
     )
     (setq l (reverse l) x 0)
     (mapcar
      '(lambda ( a b )
         (setq x (+ x (distance (list (car a) (cadr a)) (list (car b) (cadr b)))))
       )
       l (cdr l)
     )
   )
 )
)

Posted

Do you mean 2D lengths? (i.e. Points projected to the XY-plane)

 

Yes I do

Posted

sorry about the double posting.

thanks Lee yes that works well. So that's how it's done. My attempt was not even close.

Posted

Have a read of the documentation on the distance function.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...