Tharwat Posted July 21, 2010 Posted July 21, 2010 Hello, I have made this small Lisp to draw a small arrow, But it does not work with vertical or angular directions. So any ideas to force that this Lisp to work properly at all directions ?. (defun c:arrow (/ p1 Len Alen p2 p3) (setq p1 (getpoint "\nSpecify Start point of Arrow:") p2 (getpoint p1 "\nSpecify End point of Arrow:") dist (distance p1 p2) vrt (/ dist 3) p3 (list (car p2)(- (cadr p2) vrt)) p4 (list (car p3) (+ (cadr p3)(* vrt 2))) ) (setq old (getvar 'osmode) new (setvar 'osmode 0)) (vl-cmdf "_.pline" p1 "_w" 0 0 p3 p4 "_c" ) (vl-cmdf "_.-hatch" "_s" (entlast) "" "_p" "_solid" "" "") (setvar 'osmode old) (princ)) Tharwat Quote
Tharwat Posted July 21, 2010 Author Posted July 21, 2010 Actually the ORTHOMODE can't affect on my Lisp due to the (cadr value) or I can call it the predesigned or precast Lisp. Tharwat Quote
jammie Posted July 21, 2010 Posted July 21, 2010 You may need to introduce a few extra calcs to get it to work. The functions POLAR & ANGLE should be useful Just a s sample, working with your code (setq dist (distance p1 p2) vrt (/ dist 3)) (setq pickAngle (angle p1 p2)) (setq p3 (polar p2 (+ pickAngle (/ pi 2)) vrt)) (setq p4 (polar p2 (- pickAngle (/ pi 2)) vrt)) )) There could be some additional considertaions possibly, ANGDIR setvar Quote
Michaels Posted July 21, 2010 Posted July 21, 2010 You may need to introduce a few extra calcs to get it to work. The functions POLAR & ANGLE should be usefulJust a s sample, working with your code There could be some additional considertaions possibly, ANGDIR setvar Thank you jammie, That's really helpful. Quote
Tharwat Posted July 21, 2010 Author Posted July 21, 2010 You may need to introduce a few extra calcs to get it to work. The functions POLAR & ANGLE should be useful Just a s sample, working with your code Thanks jammie, very nice. My best regards Tharwat Quote
alanjt Posted July 21, 2010 Posted July 21, 2010 Why not just draw an LWPolyline with a width, rather than a closed one with hatch? Quick and dumb example... (defun c:TEst (/ p1 p2) (if (and (setq p1 (getpoint "\nSpecify first point: ")) (setq p2 (getpoint p1 "\nSpecify next point: ")) ) (progn (command "_.pline" "_non" p1 "_w" 0. (/ (distance p1 p2) 3.) "_non" p2 "") (setvar 'plinewid 0.) ) ) (princ) ) Quote
Tharwat Posted July 21, 2010 Author Posted July 21, 2010 Why not just draw an LWPolyline with a width, rather than a closed one with hatch? I have thought of that once before, but I wanted to hit tow birds with one shout.:wink: First, to know the principle of following the direction of the GETPOINT for my future routines. Second, my drawings are in different scales, so the LWPolyline needs to specify the second width of it manually. Tharwat Quote
alanjt Posted July 21, 2010 Posted July 21, 2010 I have thought of that once before, but I wanted to hit tow birds with one shout.:wink: First, to know the principle of following the direction of the GETPOINT for my future routines. Second, my drawings are in different scales, so the LWPolyline needs to specify the second width of it manually. Tharwat OK. I just followed similar principals to your above routine. Quote
Tharwat Posted July 21, 2010 Author Posted July 21, 2010 Why not just draw an LWPolyline with a width, rather than a closed one with hatch? Quick and dumb example... (defun c:TEst (/ p1 p2) (if (and (setq p1 (getpoint "\nSpecify first point: ")) (setq p2 (getpoint p1 "\nSpecify next point: ")) ) (progn (command "_.pline" "_non" p1 "_w" 0. (/ (distance p1 p2) 3.) "_non" p2 "") (setvar 'plinewid 0.) ) ) (princ) ) HA HA I believe that your codes were not posted from the first time. when I wrote my last reply. Right..... ? Quote
alanjt Posted July 21, 2010 Posted July 21, 2010 HA HA I believe that your codes were not posted from the first time. when I wrote my last reply. Right..... ? COrrect....... Quote
alanjt Posted July 21, 2010 Posted July 21, 2010 BTW, you should post your completed/fixed routine for completeness and it might help someone else down the line.:wink: Quote
Tharwat Posted July 21, 2010 Author Posted July 21, 2010 Here it goes with no hesitation at all to all my dear members ....... enjoy it. (defun c:arrow (/ p1 p2 dist vrt pickangle p3 p4 old new) (setq p1 (getpoint "\nSpecify Start point of Arrow:") p2 (getpoint p1 "\nSpecify End point of Arrow:") dist (distance p1 p2) vrt (/ dist 3) pickAngle (angle p1 p2) p3 (polar p2 (+ pickAngle (/ pi 2)) vrt) p4 (polar p2 (- pickAngle (/ pi 2)) vrt)) (setq old (getvar 'osmode) new (setvar 'osmode 0)) (vl-cmdf "_.pline" p1 "_w" 0 0 p3 p4 "_c" ) (vl-cmdf "_.-hatch" "_s" (entlast) "" "_p" "_solid" "" "") (setvar 'osmode old) (princ)) Tharwat Quote
alanjt Posted July 21, 2010 Posted July 21, 2010 See revisions... (defun c:arrow (/ p1 Len Alen p2 p3) (if (and (setq p1 (getpoint "\nSpecify Start point of Arrow:")) (setq p2 (getpoint p1 "\nSpecify End point of Arrow:")) ) (progn (setq dist (distance p1 p2) vrt (/ dist 3) pickAngle (angle p1 p2) p3 (polar p2 (+ pickAngle (/ pi 2)) vrt) p4 (polar p2 (- pickAngle (/ pi 2)) vrt) ) (vl-cmdf "_.pline" "_non" p1 "_w" 0 0 "_non" p3 "_non" p4 "_c") (vl-cmdf "_.-hatch" "_s" (entlast) "" "_p" "_solid" "") ) ) (princ) ) Quote
Tharwat Posted July 21, 2010 Author Posted July 21, 2010 Really strong and faster. certainlly. No comments . And what's made it that strong in implementing the routine ? Is it the IF function ? Thanks Quote
alanjt Posted July 21, 2010 Posted July 21, 2010 Really strong and faster. certainlly.No comments . And what's made it that strong in implementing the routine ? Is it the IF function ? Thanks See notes... (defun c:arrow (/ p1 Len Alen p2 p3) (if (and (setq p1 (getpoint "\nSpecify Start point of Arrow:")) ; notice these are broken up to avoid error if the first is not defined, etc. (setq p2 (getpoint p1 "\nSpecify End point of Arrow:")) ; only if these two variables are filled, will the routine continue ) (progn (setq dist (distance p1 p2) vrt (/ dist 3) pickAngle (angle p1 p2) p3 (polar p2 (+ pickAngle (/ pi 2)) vrt) p4 (polar p2 (- pickAngle (/ pi 2)) vrt) ) (vl-cmdf "_.pline" "_non" p1 "_w" 0 0 "_non" p3 "_non" p4 "_c") ; if you add "_non" before defining a point in any command, it will ignore any running OSnaps. Thus, you don't have to worry with osmode (vl-cmdf "_.-hatch" "_s" (entlast) "" "_p" "_solid" "") ) ) (princ) ) Quote
Tharwat Posted July 21, 2010 Author Posted July 21, 2010 I am Speechless. you did convinced me well. Thanks Alan My best regards Tharwat Quote
jammie Posted July 21, 2010 Posted July 21, 2010 Thank you jammie, That's really helpful. Your welcome Michaels, glad you found it helpful Quote
jammie Posted July 21, 2010 Posted July 21, 2010 Thanks jammie, very nice. My best regards Tharwat No problem, your welcome tharwat313 Quote
alanjt Posted July 21, 2010 Posted July 21, 2010 I am Speechless. you did convinced me well. Thanks Alan My best regards Tharwat Enjoy. ...... 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.