Small Fish Posted June 2, 2011 Share Posted June 2, 2011 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 2, 2011 Share Posted June 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
Small Fish Posted June 2, 2011 Author Share Posted June 2, 2011 Thanks Lee that's great - however - sorry I forgot to say 3d polylines. I just changed LWPOLYLINE to POLYLINE many thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 2, 2011 Share Posted June 2, 2011 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)) ) ) ) Quote Link to comment Share on other sites More sharing options...
Small Fish Posted June 2, 2011 Author Share Posted June 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 2, 2011 Share Posted June 2, 2011 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)) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 2, 2011 Share Posted June 2, 2011 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)) ) ) ) Quote Link to comment Share on other sites More sharing options...
Small Fish Posted June 3, 2011 Author Share Posted June 3, 2011 Perfect many thanks Lee Quote Link to comment Share on other sites More sharing options...
Small Fish Posted June 8, 2011 Author Share Posted June 8, 2011 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 8, 2011 Share Posted June 8, 2011 Do you mean 2D lengths? (i.e. Points projected to the XY-plane) Quote Link to comment Share on other sites More sharing options...
Small Fish Posted June 8, 2011 Author Share Posted June 8, 2011 Do you mean 2D lengths? (i.e. Points projected to the XY-plane) Yes I do Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 8, 2011 Share Posted June 8, 2011 (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) ) ) ) ) Quote Link to comment Share on other sites More sharing options...
Small Fish Posted June 8, 2011 Author Share Posted June 8, 2011 Do you mean 2D lengths? (i.e. Points projected to the XY-plane) Yes I do Quote Link to comment Share on other sites More sharing options...
Small Fish Posted June 8, 2011 Author Share Posted June 8, 2011 sorry about the double posting. thanks Lee yes that works well. So that's how it's done. My attempt was not even close. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 8, 2011 Share Posted June 8, 2011 Have a read of the documentation on the distance function. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.