Hi everyone,
I'm trying to program a routine that creates a list of points between the start point and the end point of a curve.
The routine prompts users to choose two vertical lines and the curve between them.
Then it creates an x coordinate array with the same space. How can I get a list that includes elements in the x coordinate array between the start point and end point of the curve
For example: the distance between two red lines is 10000 mm and the space is 500 mm.
The x coordinate array is (0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 ... 10000) (green circles).
The startpoint point and endpoint of the green curve are 3319 and 7195 (the red circles).
The list I desired to get is (3500 4000 5500 6000 6500 7000).
And with the yellow curve that has startpoint coincident with the first element of the x coordinate array, how can I do it?
Thank you and excuse for my English.
(defun c:testing () ; Move the Current UCS to World UCS (command "ucs" "w") ; Get current setting of System Variables (setq oldsnap (getvar "osmode")) ; Switch off System Variables (setvar "osmode" 0) (setq obj1 (car(entsel "\nSelect vertical line 1\n"))) (setq obj2 (car(entsel "Select vertical line 2\n"))) (setq obj3 (car(entsel "Select curve\n"))) (setq pt1 (vlax-curve-getStartPoint obj1)) (setq pt2 (vlax-curve-getStartPoint obj2)) (setq pt2_ucs (polar pt1 0 100)) (setq pt3_ucs (polar pt1 (/ pi 2) 100)) ; Move the World UCS to User UCS (command "ucs" "3" pt1 pt2_ucs pt3_ucs) ; The start point of the curve repsectively User UCS (setq sp_curve (trans(vlax-curve-getStartPoint obj3) 0 1)) ; The end point of the curve repsectively User UCS (setq ep_curve (trans(vlax-curve-getEndPoint obj3) 0 1)) (setq n 20) (setq l (/ (distance pt1 pt2) n)) (setq array '()) (setq count 0) (while (< count 21) (princ count) (setq array (append array (list(* l count)))) (setq count (1+ count)) );while ; Switch on System Variables (setvar "osmode" oldsnap) (princ l) (princ) )
Solved! Go to Solution.
Solved by marko_ribar. Go to Solution.
Maybe something like this :
(untested)
(defun c:testing ( / *error* osm obj1 obj2 obj3 pt1 pt2 n l c d p dpl dl ) (vl-load-com) (defun *error* ( msg ) (if osm (servar 'osmode osm)) (if msg (prompt msg)) (princ) ) (setq osm (getvar 'osmode)) (setvar 'osmode 0) (setq obj1 (car (entsel "\nSelect vertical line 1"))) (setq obj2 (car (entsel "\nSelect vertical line 2"))) (setq obj3 (car (entsel "\nSelect curve\n"))) (setq pt1 (vlax-curve-getStartPoint obj1)) (setq pt2 (vlax-curve-getStartPoint obj2)) (setq n 20) (setq l (/ (distance pt1 pt2) n)) (setq c -1) (repeat (1+ n) (setq d (* l (setq c (1+ c)))) (setq p (polar pt1 (angle pt1 pt2) d)) (setq dpl (cons (list d p) dpl)) ) (setq dpl (reverse dpl)) (foreach dp dpl (if (vlax-curve-getClosestPointToProjection obj3 (cadr dp) (polar '(0.0 0.0 0.0) (+ (* pi 0.5) (angle pt1 pt2)) 1.0)) (setq dl (cons (car dp) dl)) ) ) (princ (reverse dl)) (*error* nil) )
HTH, M.R.
Sorry, disregard my previous post... This one is tested...
(defun c:testing ( / *error* osm obj1 obj2 obj3 pt1 pt2 n l c d p dpl pt dl ) (vl-load-com) (defun *error* ( msg ) (if osm (setvar 'osmode osm)) (if msg (prompt msg)) (princ) ) (setq osm (getvar 'osmode)) (setvar 'osmode 0) (setq obj1 (car (entsel "\nSelect vertical line 1"))) (setq obj2 (car (entsel "\nSelect vertical line 2"))) (setq obj3 (car (entsel "\nSelect curve\n"))) (setq pt1 (vlax-curve-getStartPoint obj1)) (setq pt2 (vlax-curve-getStartPoint obj2)) (setq n 20) (setq l (/ (distance pt1 pt2) n)) (setq c -1) (repeat (1+ n) (setq d (* l (setq c (1+ c)))) (setq p (polar pt1 (angle pt1 pt2) d)) (setq dpl (cons (list d p) dpl)) ) (setq dpl (reverse dpl)) (foreach dp dpl (if (and (setq pt (vlax-curve-getClosestPointToProjection obj3 (cadr dp) (polar '(0.0 0.0 0.0) (+ (* pi 0.5) (angle pt1 pt2)) 1.0))) (or (equal (angle (cadr dp) pt) (if (> (+ (angle pt1 pt2) (* pi 0.5)) (* 2 pi)) (- (+ (angle pt1 pt2) (* pi 0.5)) (* 2 pi)) (+ (angle pt1 pt2) (* pi 0.5)) ) 1e-10 ) (equal (angle (cadr dp) pt) (if (minusp (- (angle pt1 pt2) (* pi 0.5))) (+ pi pi (- (angle pt1 pt2) (* pi 0.5))) (- (angle pt1 pt2) (* pi 0.5)) ) 1e-10 ) ) ) (setq dl (cons (car dp) dl)) ) ) (princ (reverse dl)) (*error* nil) )
HTH, M.R.
Many thanks for your reply.
Can I ask you a question? I run the routine and I don't know how to get exactly the list I desire from all the variables. The list is [3000 3500 4000 ... 7000].
Thanks again Sir.
@maikhanhmst wrote:Many thanks for your reply.
Can I ask you a question? I run the routine and I don't know how to get exactly the list I desire from all the variables. The list is [3000 3500 4000 ... 7000].
Thanks again Sir.
I don't understand, you want list of integers to be output? If that's the case just change last line from : (princ (reverse dl)) to : (princ (mapcar 'fix (reverse dl)))
Thank you so much.
It works great except one thing that when I choose the curve that has x coordinate of the start point and the end point are 0 and 10000. The result is shown [0 500 1000 1500 2000 .... 9500]. It's missing the one element (element with value 10000)
Great thanks Sir.