Sweety Posted August 19, 2010 Posted August 19, 2010 Hello everybody. Suppose that I selected two points, and I want to divide the length between them to 6 or 7 pieces by the function (getint). How can I give a name to each point to re-use it once again later on in my routine ? Example. (setq pt1 (getpoint "\n Select First point :") pt2 (getpoint "\n Select second point :") Num (getint "\n Specify number of segments :") ) Thanks. Sweety. Quote
alanjt Posted August 19, 2010 Posted August 19, 2010 Divide the distance between the two points by the number of specified segments. Step through the overall distance and use polar to create points along the way. Quote
Sweety Posted August 19, 2010 Author Posted August 19, 2010 Although that's not clear to me, But how to name them . pt3 pt4 pt5 .... or to be able to use their location at least ?. Quote
alanjt Posted August 19, 2010 Posted August 19, 2010 Use cons to put each polar created point into a list. From there, you'll have a list of points. Quote
JohnM Posted August 19, 2010 Posted August 19, 2010 Like alaljt suggested use the polar function First get the angel of the 2 points Then get the distance Divide the distance to get each step Create an empty list (setq mylst ‘()) Use the repeat function (repeat (- num 1);_example if num = 4 there will be 3 points (setq lstpt (polar pt1 angle distance) );_get first pt (setq mylst (cons lstpt mylst));_add point top list (setq pt1 lstpt);_move point so polar will use last point as start pt );_end repeat Now you have a list of points: example (0.0 0.0 5.0 0.0 10.0 0.0) (setq mylst (reverse mtlst));_flip the list so first point added is at the beginning of the list Now you can use the nth function to retrieve the points Nth 0 mylst will return the first point in the list, nth 1 the second and so on Say you want to insert a block at each point Use the foreach function and a counter (setq cnt 0);_counter (foreach item mylst (command insert myblock (nth cnt mylst)) (setq cnt (1+ cnt));_increase counter by 1 );_foreach Quote
alanjt Posted August 19, 2010 Posted August 19, 2010 I wrote this earlier... (defun AT:DivideSegment (p1 p2 n) ;; Divide Segment ;; p1 - first point ;; p2 - second point ;; n - number of desired segments (must be > 1) ;; Alan J. Thompson, 08.19.10 (if (and (apply (function and) (mapcar (function vl-consp) (list p1 p2))) (> (fix n) 1)) ((lambda (a s i / l) (repeat (1- (fix n)) (setq l (cons (polar p1 a (setq i (+ s i))) l))) (cons p1 (reverse (cons p2 l))) ) (angle p1 p2) (/ (distance p1 p2) (fix n)) 0. ) ) ) Quote
Sweety Posted August 19, 2010 Author Posted August 19, 2010 Thank you johnM. That's a great work appreciated. I would work on it right now, Hope I could do it well . regards Quote
lpseifert Posted August 19, 2010 Posted August 19, 2010 (edited) If you create the points using entmakex, you can save the created points entity names to symbols (e.g. pt3, pt4, pt5 ...) (setq idx 2) (repeat (1- Num) (set (read (strcat "pt" (itoa (setq idx (1+ idx))))) (entmakex (list (cons 0 "point") [color=red][i]rest of entmakex data[/i][/color] ) ) ) ) if you didn't want to create point entities, just need to know the coordinates, you could use polar instead of entmakex (as discussed earlier). Edited August 19, 2010 by lpseifert Quote
Sweety Posted August 19, 2010 Author Posted August 19, 2010 I wrote this earlier... Thank Mr alanjt. I want to learn how to write and to know what to do when I need codes , The information that given by JohnM is what I looking forward to become good at Lisp . Hope you understand my poor knowledge with Lisp many thanks for you. sweety Quote
alanjt Posted August 19, 2010 Posted August 19, 2010 Thank Mr alanjt. I want to learn how to write and to know what to do when I need codes , The information that given by JohnM is what I looking forward to become good at Lisp . Hope you understand my poor knowledge with Lisp many thanks for you. sweety Oh, no problem at all. The only reason I posted what I had was that you were trying to learn and I thought I'd give you my example.Keep plugging at it and ask all the questions you need.:wink: Quote
JohnM Posted August 19, 2010 Posted August 19, 2010 Just remember in lisp there is always many ways to do something but just like anything else it’s best to start simple so you understand the mechanics then when you get more advanced you will have a better knowledge of what’s going on. When I go back and look at some of my first lisps I think wow now I can write it in 3 lines of code instead of the 20 lines I first started with. But to be a decent programmer you have to learn the basics or you will always be fighting with your code. Quote
alanjt Posted August 19, 2010 Posted August 19, 2010 Just remember in lisp there is always many ways to do something but just like anything else it’s best to start simple so you understand the mechanics then when you get more advanced you will have a better knowledge of what’s going on.When I go back and look at some of my first lisps I think wow now I can write it in 3 lines of code instead of the 20 lines I first started with. But to be a decent programmer you have to learn the basics or you will always be fighting with your code. Well spoken. I guess I did post one that was a little complicated. Quote
Sweety Posted August 19, 2010 Author Posted August 19, 2010 Thanks for all. Now I made a list of codes that unfortuntely give a nil value, I mean the created points by repeat . Anybody could check this for me please. (setq pt1 (getpoint "\n Select First point :") pt2 (getpoint "\n Select second point :") num (getint "\n Specify number of segments :") ang (angle pt1 pt2) dist(distance pt1 pt2) step1 (/ dist num) myst '() ) (repeat (- num 1) (setq 1stpt (polar pt1 ang dist)) (setq myst (cons lstpt myst)) (setq pt1 1stpt) ) (setq myst (reverse myst)) Regards Quote
JohnM Posted August 19, 2010 Posted August 19, 2010 a couple of simple mistakes but your on the right track see corrected code below (defun c:test () (setq pt1 (getpoint "\n Select First point :") ;;;_added pt1 to function so you can see the line pt2 (getpoint pt1 "\n Select second point :") num (getint "\n Specify number of segments :") ang (angle pt1 pt2) dist(distance pt1 pt2) step1 (/ dist num) myst '() ) (repeat (- num 1) (setq 1stpt (polar pt1 ang dist)) ;;;_you had lstpt should be 1stpt 1 not L (setq myst (cons 1stpt myst)) (setq pt1 1stpt) ) (setq myst (reverse myst)) );_defun Quote
Sweety Posted August 20, 2010 Author Posted August 20, 2010 *** Thanks for all *** I completed the routine but it's not running good, I want to make lines start from (pt1) and go down vertically according to point (points). but something wrong . can somebody help me with it please ? (defun c:mystart(/ pt1 pt2 num ang dist step1 myst 1stpt count points pt3) (setq pt1 (getpoint "\n Select First point :") pt2 (getpoint pt1 "\n Select second point :") num (getint "\n Specify number of segments :") ang (angle pt1 pt2) dist(distance pt1 pt2) step1 (/ dist num) myst '() ) (repeat (- num 1) (setq 1stpt (polar pt1 ang dist)) (setq myst (cons 1stpt myst)) (setq pt1 1stpt) ) (setq myst (reverse myst)) (setq count 0) (while (/= count nil) (setq points (nth count myst)) (setq pt3 (polar points (dtr 270.0) dist)) (setq count (1+ count)) (command "_.line" pt1 pt3 "") (setq pt1 pt3) ) (princ) ) (defun DTR (myangle)(* pi (/ myangle 180.0))) Thanks. Quote
JohnM Posted August 20, 2010 Posted August 20, 2010 little revisions (defun c:mystart(/ pt1 pt2 num ang dist step1 myst 1stpt count points pt3) (setq pt1 (getpoint "\n Select First point :") pt2 (getpoint pt1 "\n Select second point :") num (getint "\n Specify number of segments :") lnlt(getreal "\nEnter Line Length; ");_add this ang (angle pt1 pt2) dist(distance pt1 pt2) step1 (/ dist num) myst '() ) (repeat (- num 1) (setq 1stpt (polar pt1 ang step1));_change dist to step1 (setq myst (cons 1stpt myst)) (setq pt1 1stpt) ) (setq myst (reverse myst)) (setq llnt (length myst));_added this (setq count 0) (while (< count llnt);_changed this (setq points (nth count myst)) (setq pt3 (polar points (dtr 270.0) lnlt));_changed dist to lnlt (setq count (1+ count)) (command "_.line" points pt3 "");_changed pt1 to points ;;;(setq pt3 points );_dont need this ) (princ) ) (defun DTR (myangle)(* pi (/ myangle 180.0))) Quote
Sweety Posted August 20, 2010 Author Posted August 20, 2010 *** THANK YOU johnM *** You have been very helpful honey. I am sorry, I changed and added things to be short and easy to read for me. Please take a look, Hope you agree. But this is not the end . :lol: (defun c:mystart (/ pt1 pt2 num ang dist step1 myst 1stpt count points pt3) (setq pt1 (getpoint "\n Select First point :") pt2 (getpoint pt1 "\n Select second point :") num (getint "\n Specify number of segments :");; I deleted the length ang (angle pt1 pt2) dist(distance pt1 pt2) step1 (/ dist num) myst '() ) (repeat (- num 1) (setq 1stpt (polar pt1 ang step1)) (setq myst (cons 1stpt myst)) (setq pt1 1stpt) ) (setq myst (reverse myst)) (setq count 0) (setq os (getvar 'osmode));; I added this (setvar 'osmode 0);; I added this (while (< count (1- num));; I changed this (setq points (nth count myst)) (setq pt3 (polar points (+ pi(/ pi 2)) dist));; I changed the dtr to pi (setq count (1+ count)) (entmakex (list(cons 0 "LINE") (cons 10 points) (cons 11 pt3))) ) (setvar 'osmode os);; I added this (princ) ) Sweety Quote
JohnM Posted August 20, 2010 Posted August 20, 2010 even shorter (defun c:mystart (/ pt1 pt2 num ang dist step1 myst 1stpt count points pt3) (setq pt1 (getpoint "\n Select First point :") pt2 (getpoint pt1 "\n Select second point :") num (getint "\n Specify number of segments :");; I deleted the length ang (angle pt1 pt2) dist(distance pt1 pt2) step1 (/ dist num) );_setq (repeat (- num 1) (setq 1stpt (polar pt1 ang step1)) (setq pt3 (polar 1stpt (+ pi(/ pi 2)) dist)) (entmakex (list(cons 0 "LINE") (cons 10 1stpt) (cons 11 pt3))) (setq pt1 1stpt) );_repeat (princ) );_defun Quote
Sweety Posted August 20, 2010 Author Posted August 20, 2010 Waw WAw That's really WONDERFUL . So now we finished the VERTICAL part, and the HORIZONTAL part would start as soon as I could prepare the codes. Thank you so much. I will be back to get your opinion of the last routine . have a nice day. Quote
JohnM Posted August 20, 2010 Posted August 20, 2010 a couple of additions to think about (defun c:mystart (/ pt1 pt2 num ang dist step1 1stpt os pt3) (command "undo" "BE");_begain mark incase of undo (setq pt1 (getpoint "\n Select First point :") pt2 (getpoint pt1 "\n Select second point :") num (getint "\n Specify number of segments :") );_setq (if (not(member 'nil (list pt1 pt2 num)));_added to catch user hitting enter (progn (setq ang (angle pt1 pt2) dist(distance pt1 pt2) step1 (/ dist num) os (getvar 'osmode) );_setq (setvar 'osmode 0) (repeat (- num 1) (setq 1stpt (polar pt1 ang step1)) (setq pt3 (polar 1stpt (+ pi(/ pi 2)) dist)) (entmakex (list(cons 0 "LINE") (cons 10 1stpt) (cons 11 pt3))) (setq pt1 1stpt) );_repeat (setvar 'osmode os) );_progn (alert "Error On Input");_notify user of input error );_if (command "undo" "End");_end mark (princ) );_defun Quote
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.