flowerrobot Posted February 3, 2009 Posted February 3, 2009 Hello again. hope all is well. whilst my abstance. Im currectly trying to get the points from a "getdist". (initget 7 ) (setq DI1 (getdist "WHAT IS THE I/D OF THE LARGER CIRCLE? : "))(terpri) (setq t2 (first point)) (setq t3 lastpoint) (if (not (= t2 nil)) (progn (setq t4 (/(+(car t2)(car t3))2)) (setq t5 (/(+(cdr t2)(cdr t3))2)) (cond ((and (> t4 0.5) (> t5 0.5)) (princ "you screwed up")) ((> t4 0.5) (setq t6 t4)) ((> t5 0.5) (setq t6 t5)) ) ) ) (initget 7) (setq DI2 (getdist "WHAT IS THE I/D OF THE SMALLER CIRCLE? : "))(terpri) (setq t7 (first point)) (setq t8 lastpoint) (if (not (= t7 nil)) (progn (setq t7 (/(+(car t7)(car t8))2)) (setq t8 (/(+(cdr t7)(cdr t8))2)) (cond ((and (> t7 0.5) (> t8 0.5)) (princ "you screwed up")) ((> t7 0.5) (setq t9 t7)) ((> t8 0.5) (setq t9 t8)) ) ) ) (if (and (= t2 nil) (= t7 nil)) (progn (initget 7) (setq CVH (getdist "WHAT IS THE HEIGHT BETWEEN THESE POINTS?: ")) ) (setq cvh (getdist t6 t9)) ) this is a bascily the layout so far. thanks for the help Quote
CarlB Posted February 3, 2009 Posted February 3, 2009 1. Getdist is designed to return just a distance. If you want 2 points I suggest; (setq t2 (getpoint "\nSelect first point:" )) (setq t3 (getpoint t2 "\nNow another point:" )) 2. (setq t4 (\(+(car t2)(car t3))) did you leave out the divisor, I assume a 2 as in..oh yeah divide sign is incorrect.. (setq t4 (/ (+ (car t2) (car t3)) 2) 3. what are you doing with this routine Quote
flowerrobot Posted February 3, 2009 Author Posted February 3, 2009 Sorry mate, didnt expect such a quick reply, i posted it, then thought, mmm thats some terrible on the fly coding, i need my note pad. ive updated. I was aware of that method, but i want to leave the option of the user still being able to put in the distance if they now that it is. I hope you can understand what im trying to acheive. work of the center point of the two circles. thus the distance between the two points give the height. Quote
ASMI Posted February 3, 2009 Posted February 3, 2009 Example of distance and midpoint calculation: (defun c:diss(/ pt1 pt2 mPt di) (and (setq pt1(getpoint "\nSpecify first point: ")) (setq pt2(getpoint pt1 "\nSpecify second point: ")) (setq mPt(mapcar '/ (mapcar '+ pt1 pt2) '(2 2 2))) (setq di(distance pt1 pt2)) (alert(strcat "Point 1 = " (vl-princ-to-string pt1) "\nPoint 2 = " (vl-princ-to-string pt1) "\nMidpoint = " (vl-princ-to-string mPt) "\nDistance = " (rtos di) ); end stracat ); end alert ); end and (princ) ); end c:diss Quote
flowerrobot Posted February 3, 2009 Author Posted February 3, 2009 Indeed. sorry if im unclear im quite good at doing that. but that dosnt let the user put in "68" in the command line. aswell as pt1 & pt2 that are 68 apart. this is the problem im facing. Quote
Lee Mac Posted February 3, 2009 Posted February 3, 2009 How about this arrangement: (defun c:test (/ pt1 pt2) (initget 128) (setq pt1 (getpoint "\nSpecify Distance or Select First Point > ")) (if (eq (type pt1) 'LIST) (setq pt2 (getpoint pt1 "\nSelect Second Point > "))) (alert (vl-princ-to-string pt1)) (princ)) Quote
CAB Posted February 3, 2009 Posted February 3, 2009 You should test for a null response, [ENTER] key as nil will return true for (listp x) or (eq (type pt1) 'LIST) (defun c:test (/ pt1 pt2) (initget 128) (setq pt1 (getpoint "\nSpecify Distance or Select First Point > ")) (cond ((null pt1) (alert "Nothing entered.")) ((and (listp pt1) (setq pt2 (getpoint pt1 "\nSelect Second Point > "))) (alert (vl-princ-to-string (distance pt1 pt2))) ) ((alert (vl-princ-to-string pt1))) ) (princ) ) Quote
Lee Mac Posted February 3, 2009 Posted February 3, 2009 Good point CAB - thanks for tweaking it Quote
CAB Posted February 3, 2009 Posted February 3, 2009 This one catched a bad 2nd point when user picks a 1st point. (defun c:test (/ pt1 pt2) (initget 128) (setq pt1 (getpoint "\nSpecify Distance or Select First Point > ")) (cond ((null pt1) (alert "Nothing entered.")) ((and (listp pt1) (setq pt2 (getpoint pt1 "\nSelect Second Point > "))) (alert (vl-princ-to-string (distance pt1 pt2))) ) ((and (listp pt1) (null pt2)) (alert "Bad 2nd point.")) ((alert (vl-princ-to-string pt1))) ) (princ) ) Quote
CAB Posted February 3, 2009 Posted February 3, 2009 Yes, the user will test your code. More fun. (defun c:test (/ p1 p2 gr num) (initget 128) (setq p1 (getpoint "\nSpecify Distance or Select First Point > ")) (cond ((null p1) (alert "Nothing entered.")) ((and (listp p1) (setq p2 (getpoint p1 "\nSelect Second Point > "))) (alert (strcat "Distance picked " (vl-princ-to-string (distance p1 p2)) "\nFirst point is " (vl-princ-to-string p1)))) ((and (listp p1) (null p2)) (alert "Bad 2nd point.")) ((setq num (txt2num p1)) (setq gr (grread t 1)) ; get point, will not be exact (alert (strcat "Distance entered " (vl-princ-to-string num) "\nFirst point would be " (vl-princ-to-string (cadr gr))))) ((alert "Invalid entry.")) ) (princ) ) ;;+++++++++++++++++++++++++++++++ ;; convert the text to a number ;;+++++++++++++++++++++++++++++++ ;; return number or nil (defun txt2num (txt / num) (or (setq num (distof txt 5)) (setq num (distof txt 2)) (setq num (distof txt 1)) (setq num (distof txt 4)) (setq num (distof txt 3)) ) (if (numberp num) num) ) Quote
Lee Mac Posted February 3, 2009 Posted February 3, 2009 Very nice CAB, but I do have a few questions (I bet you knew that was coming!)... I see that you account for another condition, using the grread function, tracking set and bit 1 used. According to the help file on grread, this accounts for the user dragging the cursor across the screen instead of typing an input or clicking. The return of such is said to be a list in which the first member is a "type 5" return value, and second member is the co-odinates of the pointing device. I understant that the type 5 return means a 3D Point. But, my question is... why the text to number conversion? and what exactly are you accounting for here? (probably already answered that myself) - I didn't think there were any other possibilities for error Thanks as always Lee Quote
CAB Posted February 3, 2009 Posted February 3, 2009 The grread is just to show that you could still get a point from the user even when they entered text. May be of no real use here. The text to number is so that a user entering a string like 2-1/2" could still return a real number & not just text. That conversion routine accounts for all valid forms of number entries. 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.