NYATI Posted September 14, 2010 Share Posted September 14, 2010 Hi All I am writing a lisp routine and want to create IF and COND functions where the first argument is a range i.e. > 5.75947 radians (330°) but > 1.04718 radians (60°) but > 2.61794 radians (150°) but > 4.18870 radians (240°) but I have tried the following and can't seem to get it to work (setq p1 (cdr (assoc 10 a2))) (setq p2 (cdr (assoc 11 a2))) (setq a3 (angle p1 p2)) (cond ((or (> a3 1.04718) ( ((or (> a3 5.75947) ( ((or (> a3 2.61794) ( ((or (> a3 4.18870) ( ) or (if (or (> a3 4.18870) ( ) What is the correct syntax? Thanks in advance Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 14, 2010 Share Posted September 14, 2010 If filtering for more than two potential outcomes, then cond is your friend, else I would use if. (Brian, did you see what I did just there!? - Stewie Griffin) It appears you're missing some parens; are you using the VLIDE? Try this: (cond ((or (> a3 1.0471[color=red][b])[/b][/color] (< a3 2.09435)) (progn . . . . . . . . .)) ((or (> a3 5.75947) (< a3 0.52359)) (progn . . . . . . . . .)) ((or (> a3 2.61794) (< a3 3.66512)) (progn . . . . . . . . .)) ((or (> a3 4.18870) (< a3 5.2358)[color=red][b])[/b][/color] (progn . . . . . . . . .))) Hope this helps! Quote Link to comment Share on other sites More sharing options...
NYATI Posted September 14, 2010 Author Share Posted September 14, 2010 Thanks Render man. Oops, the missing parens are typos in the thread, they are in program though. I am not using VLIDE, I am creating in notepad. Probably should try VLIDE. Typos aside the cond syntax should be ok? Maybe I need to look else where in my routine for not working? Thanks again Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 14, 2010 Share Posted September 14, 2010 You're welcome. Oops, the missing parens are typos in the thread, they are in program though. I am not using VLIDE, I am creating in notepad. Probably should try VLIDE. I would highly suggest that you start using the Visual LISP Integrated Development Environment (VLIDE) if you're going to be coding for AutoCAD using LISP. To begin, at the command line type in VLIDE, then hit enter. You can start with the Developer Documentation by hitting the F1 button. Typos aside the cond syntax should be ok? Maybe I need to look else where in my routine for not working? Not sure. What I provided you could be wrong, as I do not know what else you're doing within your code. The simplest thing to do in this case might be to post your code. If you could include some additional detail about what it is you trying to do overall, that may be helpful. Quote Link to comment Share on other sites More sharing options...
alanjt Posted September 14, 2010 Share Posted September 14, 2010 eg. (defun foo (v) (cond ((< 0. v (/ pi 2.)) (alert "1")) ((< (/ pi 2.) v pi) (alert "2")) ((< pi v (* 1.5 pi)) (alert "3")) ((< (* pi 2.) v (* 1.5 pi)) (alert "4")) ((alert "NADA")) ) ) I would suggest you use fractions instead of approximations. Quote Link to comment Share on other sites More sharing options...
NYATI Posted September 14, 2010 Author Share Posted September 14, 2010 Hi Render Without making this reply to wordy, here is what I am trying to do!! I have created 2 routines to square lines to the current UCS if within acceptable tolerance. VA.lsp is for verticle lines and HA.lsp for horizontal lines. I have tested these for a while and now want to: 1. Combine to one routine that "detects" whether the HA or VA needs to be run 2. Runs on a multiple lines instead of a single. 3. Sets up variable for tolerance, if under 10 mm OK program continues but if above 11mm checks if OK to proceed. I haven't completed this yet, just set the variable. 4. Resets current layer, osmode and osnaps if program at end or terminates midway through. 5. Checks if entities are "Lines" and if not warns of poly lines and moves onto next entity and/or terminates program cleanly. Ultimately I would like this routine to work on poly lines too, but need to walk before running!!! I have written in couple check variable but not complete IF function, currently REM statement. The orginal HA and VA included in HaVa and renamed HA2/VA2. Some lines have are now REM statements as not needed for the combined program. Any thoughts you may have would be greatly appreciated. Again many thanks for help and input. HaVa.lsp Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 14, 2010 Share Posted September 14, 2010 You're welcome. I appreciate your initial post not being a wish list for an entire tailored routine; I can see that you've put some work into this, and that is always appreciated. I am pretty busy with work right now, but I will check back with this thread when I can. Quote Link to comment Share on other sites More sharing options...
David Bethel Posted September 15, 2010 Share Posted September 15, 2010 You should be able to condense the process some: [b][color=BLACK]([/color][/b]initget 7[b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]setq tolerance [b][color=FUCHSIA]([/color][/b]getreal [color=#2f4f4f]"\nEnter acceptable tolerance > : "[/color][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [b][color=BLACK]([/color][/b]and [b][color=FUCHSIA]([/color][/b]setq i -1 ss1 [b][color=NAVY]([/color][/b]ssget '[b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]0 . [color=#2f4f4f]"LINE"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq a1 [b][color=MAROON]([/color][/b]ssname ss1 [b][color=GREEN]([/color][/b]setq i [b][color=BLUE]([/color][/b]1+ i[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq a2 [b][color=MAROON]([/color][/b]entget a1[b][color=MAROON])[/color][/b] p1 [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 10 a2[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] p2 [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 11 a2[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] a3 [b][color=MAROON]([/color][/b]angle p1 p2[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]cond [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]or [b][color=BLUE]([/color][/b]> 2.09435 a3 1.04718[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]> 5.23588 a3 4.18870[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]VA2[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]or [b][color=BLUE]([/color][/b]> 0.52359 a3 5.75947[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]> 3.66512 a3 2.61794[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]HA2[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David Quote Link to comment Share on other sites More sharing options...
NYATI Posted September 20, 2010 Author Share Posted September 20, 2010 David Thanks for the code and I apologise for delay in replying to your post. I will work it in with my original routines and see how it goes. Quote Link to comment Share on other sites More sharing options...
NYATI Posted September 21, 2010 Author Share Posted September 21, 2010 Hi David I worked in your code and managed to get it all working Only had to make slight change to your line 4 of the cond program didn't like the range argument I think because it was straddling zero degrees so just split the argument from 0° to 30° and 330° to 359.9999° (cond ((or (> 2.09435 a3 1.04718) (> 5.23588 a3 4.18870)) (VA2)) ((or (> 0.52359 a3 0.00000) (> 6.28305 a3 5.75947) (> 3.66512 a3 2.61794)) (HA2))))) Many thanks for your input and to Renderman and Alanjt for their responses too. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted September 21, 2010 Share Posted September 21, 2010 Nyati, in the future... please use code brackets. Quote Link to comment Share on other sites More sharing options...
David Bethel Posted September 22, 2010 Share Posted September 22, 2010 I'd suggest something like this as an alternate for a bit more tolerance: [b][color=BLACK]([/color][/b]defun RtoA [b][color=FUCHSIA]([/color][/b]r[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]/ [b][color=NAVY]([/color][/b]* r 180.0[b][color=NAVY])[/color][/b] pi[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [color=#8b4513];Radian To Angle[/color] [b][color=BLACK]([/color][/b]defun AtoR [b][color=FUCHSIA]([/color][/b]a[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]* pi [b][color=NAVY]([/color][/b]/ a 180.0[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] [color=#8b4513];Angle To Radian[/color] [b][color=BLACK]([/color][/b]and [b][color=FUCHSIA]([/color][/b]setq i -1 ss1 [b][color=NAVY]([/color][/b]ssget '[b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]0 . [color=#2f4f4f]"LINE"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq a1 [b][color=MAROON]([/color][/b]ssname ss1 [b][color=GREEN]([/color][/b]setq i [b][color=BLUE]([/color][/b]1+ i[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq a2 [b][color=MAROON]([/color][/b]entget a1[b][color=MAROON])[/color][/b] p1 [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 10 a2[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] p2 [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 11 a2[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] a3 [b][color=MAROON]([/color][/b]angle p1 p2[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]cond [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]or [b][color=BLUE]([/color][/b]>= [b][color=RED]([/color][/b]ator 120[b][color=RED])[/color][/b] a3 [b][color=RED]([/color][/b]ator 60[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]<= [b][color=RED]([/color][/b]ator 330[b][color=RED])[/color][/b] a3[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]>= [b][color=RED]([/color][/b]ator 30[b][color=RED])[/color][/b] a3[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]VA2[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b][b][color=GREEN]([/color][/b]or [b][color=BLUE]([/color][/b]>= [b][color=RED]([/color][/b]ator 210[b][color=RED])[/color][/b] a3 [b][color=RED]([/color][/b]ator 150[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]>= [b][color=RED]([/color][/b]ator 300[b][color=RED])[/color][/b] a3 [b][color=RED]([/color][/b]ator 240[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]HA2[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David 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.