totzky Posted January 5, 2009 Share Posted January 5, 2009 This is my code: ;; Shortcut command for circle(defun c:ctd (/ a) (setq a (/ (getreal "\nd:") 2)) (command "circle" "_ttr" pause pause a) (princ) ) At present this is what appears on my command line,Command: ctd d:100 circle Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: _ttr Specify point on object for first tangent of circle: Specify point on object for second tangent of circle: Specify radius of circle: 50.00000000000000 Command: Command: And this if I press ESCAPE at prompt, Command: CTD d: ; error: bad argument type: numberp: nil What I want to achieve is something like this, Command: ctd d:100 circle Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: _ttr Specify point on object for first tangent of circle: Specify point on object for second tangent of circle: Specify radius of circle: 50.00000000000000 Command: Command: And when I press ENTER, Command: ctd d: ( press ENTER key at this point) circle Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: _ttr Specify point on object for first tangent of circle: Specify point on object for second tangent of circle: Specify radius of circle : 50.00000000000000 Command: Command: How will I do that? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2009 Share Posted January 5, 2009 Perhaps this? ;; Shortcut command for circle (defun c:ctd (/ a) (or (getenv "DIAM") (setenv "DIAM" "0")) (if (setq a (/ (getreal (strcat "\nd<" (getenv "DIAM") ">: ")) 2)) (setenv "DIAM" (rtos (* 2 a))) ) ;_ end if (command "_circle" "_ttr" pause pause (getenv "DIAM")) (princ) ) ;_ end defun Quote Link to comment Share on other sites More sharing options...
totzky Posted January 5, 2009 Author Share Posted January 5, 2009 Thanks Lee Mac! That was pretty quick. How can I fix this error when I press escape? Command: ctd d: *Cancel* ; error: Function cancelled Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2009 Share Posted January 5, 2009 I thought maybe this, but it doesn't really get around it. ;; Shortcut command for circle (defun c:ctd (/ a) (defun *error* (msg) (if (= msg "") (princ "\nFunction Complete.") (princ (strcat "\n" (strcase msg))) ) ;_ end if (princ) ) ;_ end defun (or (getenv "DIAM") (setenv "DIAM" "0")) (if (setq a (/ (getreal (strcat "\nd<" (getenv "DIAM") ">: ")) 2)) (setenv "DIAM" (rtos (* 2 a))) ) ;_ end if (command "_circle" "_ttr" pause pause (getenv "DIAM")) (princ) ) ;_ end defun Plus, if I hit enter when the default is there it says, bad argument, numerp nil. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2009 Share Posted January 5, 2009 Sorry, haven't got much time today Quote Link to comment Share on other sites More sharing options...
totzky Posted January 5, 2009 Author Share Posted January 5, 2009 Ok, thanks, I'll wait for others... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2009 Share Posted January 5, 2009 Looked over it again - stupid mistake really. Can't quite sort your error problem though: ;; Shortcut command for circle (defun c:ctd (/ a) (defun *error* (msg) (if (= msg "") (princ "\nFunction Complete.") (princ (strcat "\n" (strcase msg))) ) ;_ end if (princ) ) ;_ end defun (or (getenv "DIAM") (setenv "DIAM" "0")) (if (setq a (getreal (strcat "\nd<" (getenv "DIAM") ">: "))) (setenv "DIAM" (rtos a)) ) ;_ end if (command "_circle" "_ttr" pause pause (rtos (/ (atof (getenv "DIAM")) 2))) (princ) ) ;_ end defun Quote Link to comment Share on other sites More sharing options...
David Bethel Posted January 5, 2009 Share Posted January 5, 2009 totzky, You need a lot of trapping on something like this to insure the command call is complete. I take the approach of having all of the values before calling CIRCLE: [b][color=BLACK]([/color][/b]defun c:ctd [b][color=FUCHSIA]([/color][/b]/ olderr oldsnp lent dia pt1 pt2[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq olderr *error* *error* [b][color=NAVY]([/color][/b]lambda [b][color=MAROON]([/color][/b]e[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]> [b][color=BLUE]([/color][/b]getvar [color=#2f4f4f]"CMDACTIVE"[/color][b][color=BLUE])[/color][/b] 0[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]command[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]and [b][color=GREEN]([/color][/b]/= e [color=#2f4f4f]"quit / exit abort"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]princ [b][color=BLUE]([/color][/b]strcat [color=#2f4f4f]"\nError: *** "[/color] e [color=#2f4f4f]" *** "[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] oldsnp [b][color=NAVY]([/color][/b]getvar [color=#2f4f4f]"OSMODE"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setvar [color=#2f4f4f]"OSMODE"[/color] 512[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setvar [color=#2f4f4f]"CMDECHO"[/color] 0[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq lent [b][color=NAVY]([/color][/b]entlast[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]initget 7[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq dia [b][color=NAVY]([/color][/b]getdist [color=#2f4f4f]"\nDiameter: "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not pt1[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq pt1 [b][color=MAROON]([/color][/b]osnap [b][color=GREEN]([/color][/b]getpoint [color=#2f4f4f]"\nSelect 1st TANGENT Point: "[/color][b][color=GREEN])[/color][/b] [color=#2f4f4f]"_TAN"[/color][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]not pt2[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq pt2 [b][color=MAROON]([/color][/b]osnap [b][color=GREEN]([/color][/b]getpoint [color=#2f4f4f]"\nSelect 2nd TANGENT Point: "[/color][b][color=GREEN])[/color][/b] [color=#2f4f4f]"_TAN"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]command [color=#2f4f4f]"_.CIRCLE"[/color] [color=#2f4f4f]"_TTR"[/color] pt1 pt2 [b][color=NAVY]([/color][/b]/ dia 2.[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]eq lent [b][color=MAROON]([/color][/b]entlast[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ [color=#2f4f4f]"\nCommand Failed..."[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setvar [color=#2f4f4f]"OSMODE"[/color] oldsnp[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq *error* olderr[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] Good Luck -David Quote Link to comment Share on other sites More sharing options...
totzky Posted January 5, 2009 Author Share Posted January 5, 2009 Test your code David and this is what happens, Command: ctd Diameter: 100 Select 1st TANGENT Point: Select 1st TANGENT Point: Select 1st TANGENT Point: Select 1st TANGENT Point: *Cancel* (At this point I pressed ESCAPE) Error: *** Function cancelled *** Quote Link to comment Share on other sites More sharing options...
David Bethel Posted January 5, 2009 Share Posted January 5, 2009 Kinda lost me there ? Did you pick a valid tangent point? -David Quote Link to comment Share on other sites More sharing options...
ASMI Posted January 5, 2009 Share Posted January 5, 2009 One more: (defun c:ctd(/ oldOsm oldDia pt1 pt2 *error*) (defun *error* (msg) (setvar "CMDECHO" 1)(setvar "OSMODE" oldOsm) (princ "\nCTD command aborted by user... ") (princ) ); end of *error* (if(not ctd:diameter)(setq ctd:diameter 1000.0)) (setq oldOsm(getvar "OSMODE") oldDia ctd:diameter ctd:diameter(getdist(strcat "\nDiameter <" (rtos ctd:diameter) ">: "))) (if(null ctd:diameter)(setq ctd:diameter oldDia)) (setvar "OSMODE" 768) (if (and (setq pt1(getpoint "\nSpecify first tangent point: ")) (setq pt2(getpoint "\nSpecify second tangent point: ")) ); end and (progn (setvar "CMDECHO" 0)(setvar "OSMODE" 0) (vl-cmdf "_.circle" "_ttr" pt1 pt2 (/ ctd:diameter 2.0)) (setvar "OSMODE" oldOsm)(setvar "CMDECHO" 1) ); end progn ); end if (princ) ); end of c:ctd Who is next? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2009 Share Posted January 5, 2009 Nice one ASMI - I considered putting the point input separately from the command call to avoid the error - but I couldn't work out how to snap it.... obviously 768 does the trick Also, would you need to use setenv to set the default? Quote Link to comment Share on other sites More sharing options...
ASMI Posted January 5, 2009 Share Posted January 5, 2009 I considered putting the point input separately from the command call to avoid the error - but I couldn't work out how to snap it.... obviously 768 does the trick 768 equals "_tan" + "_nea" Also, would you need to use setenv to set the default? I think yes, but "DIAM" is too common name and some another user (or you) can repeat it in other program. Use for example "CTD_DIAMETER" or some like it. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2009 Share Posted January 5, 2009 Ok ASMI, thanks thanks for the explanation. Much appreciated. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 5, 2009 Share Posted January 5, 2009 So I suppose this? ; CTD by ASMI, modified slightly by Lee Mac (defun c:ctd (/ *error* oldOsm cdia pt1 pt2) (defun *error* (msg) (setvar "CMDECHO" 1) (setvar "OSMODE" oldOsm) (princ "\nCTD command aborted by user... ") (princ) ) ; end of *error* (or (getenv "ctd:diameter") (setenv "ctd:diameter" "0.0")) (setq oldOsm (getvar "OSMODE")) (if (setq cdia (getdist (strcat "\nDiameter <" (getenv "ctd:diameter") ">: "))) (setenv "ctd:diameter" (rtos cdia)) ) ;_ end if (setvar "OSMODE" 768) (if (and (setq pt1 (getpoint "\nSpecify first tangent point: ")) (setq pt2 (getpoint "\nSpecify second tangent point: ")) ) ; end and (progn (setvar "CMDECHO" 0) (setvar "OSMODE" 0) (vl-cmdf "_.circle" "_ttr" pt1 pt2 (rtos (/ (atof (getenv "ctd:diameter")) 2.0))) (setvar "OSMODE" oldOsm) (setvar "CMDECHO" 1) ) ; end progn ) ; end if (princ) ) ; end of c:ctd Quote Link to comment Share on other sites More sharing options...
totzky Posted January 6, 2009 Author Share Posted January 6, 2009 Kinda lost me there ? Did you pick a valid tangent point? -David Your idea of using nearest as object snap was the same one used by others. Thanks David. Well, as always ASMI's code worked like magic. Thanks! there's more to come. I'll bet my penny on it! Ofcourse Lee Mac's code worked too. Get me some time to use the code and report back to you. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 6, 2009 Share Posted January 6, 2009 Nice one Totzky, thanks for your compliments. Hope it all works out for you. Quote Link to comment Share on other sites More sharing options...
totzky Posted January 11, 2009 Author Share Posted January 11, 2009 Here is the development of this LISP so far. (defun c:ctd(/ oldOsm oldDia pt1 pt2 *error*) (defun *error* (msg) (setvar "CMDECHO" 1)(setvar "OSMODE" oldOsm) (alert " CTD command aborting...\n\nClick OK or press ENTER to continue.") (princ "\nCTD command aborted by user...") (princ) ); end of *error* (if(not ctd:diameter)(setq ctd:diameter 10.0)) (setq oldOsm(getvar "OSMODE") oldDia ctd:diameter ctd:diameter(getdist(strcat "\nDiameter : "))) (if(null ctd:diameter)(setq ctd:diameter oldDia)) (if ( (progn (alert "Value must be positive and nonzero. Diameter will be reset to 10.0.\n") (setq ctd:diameter 10.0) (quit)));end if (setvar "OSMODE" 768 ) (if (and (setq pt1(getpoint "\nSpecify first tangent point: ")) (setq pt2(getpoint "\nSpecify second tangent point: ")) ); end and (progn (setvar "CMDECHO" 0)(setvar "OSMODE" 0) (vl-cmdf "_.circle" "_ttr" pt1 pt2 (/ ctd:diameter 2.0)) (setvar "OSMODE" oldOsm)(setvar "CMDECHO" 1) ); end progn ); end if (princ) ); end of c:ctd And my question: Is it possible to force Autocad to show tangent autosnap marker always? Quote Link to comment Share on other sites More sharing options...
ASMI Posted January 11, 2009 Share Posted January 11, 2009 And my question: Is it possible to force Autocad to show tangent autosnap marker always? You can include 256 in OSMODE variable value but nearest marker has priority over all other markers. You can restrict zero and negative user input with INITGET function. It works for the first (get... function after (initget ...) only. (defun c:ctd(/ oldOsm oldDia pt1 pt2 *error*) (defun *error* (msg) (setvar "CMDECHO" 1)(setvar "OSMODE" oldOsm) (alert " CTD command aborting...\n\nClick OK or press ENTER to continue.") (princ "\nCTD command aborted by user...") (princ) ); end of *error* (if(not ctd:diameter)(setq ctd:diameter 10.0)) [color="SeaGreen"](initget 6)[/color] (setq oldOsm(getvar "OSMODE") oldDia ctd:diameter ctd:diameter(getdist(strcat "\nDiameter <" (rtos ctd:diameter) ">: "))) (if(null ctd:diameter)(setq ctd:diameter oldDia)) [color="Red"];;;(if (<= ctd:diameter 0.0) ;;;(progn ;;;(alert "Value must be positive and nonzero. Diameter will be reset to 10.0.\n") ;;;(setq ctd:diameter 10.0) ;;;(quit)));end if[/color] (setvar "OSMODE" 768) (if (and (setq pt1(getpoint "\nSpecify first tangent point: ")) (setq pt2(getpoint "\nSpecify second tangent point: ")) ); end and (progn (setvar "CMDECHO" 0)(setvar "OSMODE" 0) (vl-cmdf "_.circle" "_ttr" pt1 pt2 (/ ctd:diameter 2.0)) (setvar "OSMODE" oldOsm)(setvar "CMDECHO" 1) ); end progn ); end if (princ) ); end of c:ctd Quote Link to comment Share on other sites More sharing options...
totzky Posted January 11, 2009 Author Share Posted January 11, 2009 I have run an initial test run of your code with initget 6 and this solves the problem of less than or equal zero user input. The problem of autosnap marker remains. Guess I just have to settle for this one. Well ladies and gentlemen presenting Circle Diameter Tan Tan command. Cadtutor Version 1! 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.