RyanGC Posted June 4, 2010 Share Posted June 4, 2010 Hi all, First post, but straight to it! When using the following code, the mtext editor is suppressed, and instead the text entry is moved to the command line (see screenshot). I've noticed this before in another lisp routine (not written by myself, nor is it available to me review). Can my routine be modified to prevent the mtext editor from being suppressed? (defun c:MTR (/ mtang1 mtang2) (setq oldcmd (getvar "cmdecho")) (setvar "cmdecho" 0) (setq mtang1 (getvar "viewtwist")) (setq mtang2 (/ (* mtang1 180) pi)) (command "mtext" pause "r" mtang2 pause) (setvar "cmdecho" oldcmd) (princ) ) Please forgive me if my coding disagrees with your own sensibilities, but this only my second day of writing AutoLISP! I'm a tidy person, and I'm sure that in time my nesting, and parenthesis placement, etc, will look pleasing to all you neat programmers. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 4, 2010 Share Posted June 4, 2010 Hi Ryan, Welcome to CADTutor Give this a try: (defun c:MTR ( / *error* oldcmd mtang ) (defun *error* ( msg ) (and oldcmd (setvar "CMDECHO" oldcmd)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (setq oldcmd (getvar "cmdecho")) (setvar "cmdecho" 0) (setq mtang (/ (* (getvar "viewtwist") 180.) pi)) (initdia) (command "mtext" pause "r" mtang pause) (setvar "cmdecho" oldcmd) (princ) ) I have added an Error handler so that the CMDECHO is restored should the user hit Esc. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted June 4, 2010 Share Posted June 4, 2010 (defun c:MTR (/ mtang1 mtang2) (setq oldcmd (getvar "cmdecho")) (setvar "cmdecho" 0) (setq mtang1 (getvar "viewtwist")) (setq mtang2 (/ (* mtang1 180) pi)) (setq mtang3 (rtos mtang2 2 2)) (command "mtext" pause pause mtang3 "" "") (setvar "cmdecho" oldcmd) (princ "Enjoy the codes RyanGC") (princ) ) Hi , I would be happy if this reached your needs. if not, I could remodify it for you. Tharwat Professional Autocad Draftsman Quote Link to comment Share on other sites More sharing options...
alanjt Posted June 4, 2010 Share Posted June 4, 2010 (initdia) usage: initdia(initdia [dialogflag]) Currently, the following commands make use of the initdia function: ATTDEF, ATTEXT, BHATCH, BLOCK, COLOR, IMAGE, IMAGEADJUST, INSERT, LAYER, LINETYPE, MTEXT, PLOT, RENAME, STYLE, TOOLBAR, and VIEW. Arguments dialogflag An integer. If this argument is not present or is present and nonzero, the next use (and next use only) of a command will display that command's dialog box rather than its command line prompts. If dialogflag is zero, any previous call to this function is cleared, restoring the default behavior of presenting the command line interface. Quote Link to comment Share on other sites More sharing options...
RyanGC Posted June 7, 2010 Author Share Posted June 7, 2010 Hi Ryan, Welcome to CADTutor Give this a try: (defun c:MTR ( / *error* oldcmd mtang ) (defun *error* ( msg ) (and oldcmd (setvar "CMDECHO" oldcmd)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (setq oldcmd (getvar "cmdecho")) (setvar "cmdecho" 0) (setq mtang (/ (* (getvar "viewtwist") 180.) pi)) (initdia) (command "mtext" pause "r" mtang pause) (setvar "cmdecho" oldcmd) (princ) ) I have added an Error handler so that the CMDECHO is restored should the user hit Esc. Hi Lee, This worked perfectly. Thank you. My original attempt was quite a bit off the mark! Steep learning curve ahead for me, huh... Quote Link to comment Share on other sites More sharing options...
alanjt Posted June 7, 2010 Share Posted June 7, 2010 Hi Lee, This worked perfectly. Thank you. My original attempt was quite a bit off the mark! Steep learning curve ahead for me, huh... You were closer than you think. Minus the error handler, the only thing you needed was (initdia). Quote Link to comment Share on other sites More sharing options...
RyanGC Posted June 7, 2010 Author Share Posted June 7, 2010 (defun c:MTR (/ mtang1 mtang2)(setq oldcmd (getvar "cmdecho")) (setvar "cmdecho" 0) (setq mtang1 (getvar "viewtwist")) (setq mtang2 (/ (* mtang1 180) pi)) (setq mtang3 (rtos mtang2 2 2)) (command "mtext" pause pause mtang3 "" "") (setvar "cmdecho" oldcmd) (princ "Enjoy the codes RyanGC") (princ) ) Hi , I would be happy if this reached your needs. if not, I could remodify it for you. Tharwat Professional Autocad Draftsman Hi there Tharwat, This didn't work, for reasons I haven't established just yet. As I want to leanr about what's going under the "lisp" hood, I'm going to have a close look at this and perhaps I can attempt to explain why this did not achieve the results I am looking for. In all cases Lee Mac's edit to my original worked perfectly. Thanks, all the same. R Quote Link to comment Share on other sites More sharing options...
RyanGC Posted June 7, 2010 Author Share Posted June 7, 2010 You were closer than you think. Minus the error handler, the only thing you needed was (initdia). And you have kindly posted some details on (initdia) for me, thanks. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 7, 2010 Share Posted June 7, 2010 You're welcome Ryan, as Alan said, you were pretty close - I just wanted to make sure your routine was watertight :wink: Quote Link to comment Share on other sites More sharing options...
alanjt Posted June 7, 2010 Share Posted June 7, 2010 You could use getpoint for the first pick, but sadly, getcorner won't match the current UCS, so the process can't be completely seamless. (defun c:MTR (/ *error* oldcmd pt) (defun *error* (msg) (and oldcmd (setvar "CMDECHO" oldcmd)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **")) ) (princ) ) (setq oldcmd (getvar "cmdecho")) (setvar "cmdecho" 0) (initdia) (if (setq pt (getpoint "\nSpecify first corner: ")) (command "_.mtext" "_non" pt "_r" (/ (* (getvar "viewtwist") 180.) pi) pause) ) (setvar "cmdecho" oldcmd) (princ) ) I also put the viewtwist conversion within the command expression (just to show it could be done). Quote Link to comment Share on other sites More sharing options...
RyanGC Posted June 7, 2010 Author Share Posted June 7, 2010 There are a couple of quirks I wanted to ask about... (defun c:MTR ( / *error* oldcmd mtang ) (defun *error* ( msg ) (and oldcmd (setvar "CMDECHO" oldcmd)) (or (wcmatch (strcase msg) "[color=Red]*BREAK[/color],*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (setq oldcmd (getvar "cmdecho")) (setvar "cmdecho" 0) (setq mtang (/ (* (getvar "viewtwist") [color=Blue]180.[/color]) pi)) (initdia) (command "mtext" pause "r" mtang pause) (setvar "cmdecho" oldcmd) (princ) ) Why does BREAK have only one * surrounding it, as opposed to the two * surrounding CANCEL and EXIT? Is there a reason for placing the decimal point after 180? Why not simply write it as 180, and only add a decimal if it be necessary? Thanks again... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 7, 2010 Share Posted June 7, 2010 With regards to the BREAK*, I'm using a Wildcard filter to catch 'Console Break', Whereas, the others catch 'Function Cancelled' and 'Quit / Exit Abort'... As for the decimal point, try these at the command line: (/ 1 2 ) (/ 1. 2 ) (/ 1 2.) (/ 1. 2.) :wink: Quote Link to comment Share on other sites More sharing options...
RyanGC Posted June 7, 2010 Author Share Posted June 7, 2010 With regards to the BREAK*, I'm using a Wildcard filter to catch 'Console Break', Whereas, the others catch 'Function Cancelled' and 'Quit / Exit Abort'... Okay. I'll need to absorb this for awhile. As for the decimal point, try these at the command line: (/ 1 2 ) (/ 1. 2 ) (/ 1 2.) (/ 1. 2.) :wink: Okay. All, apart from the first line (which resulted in 0), resulted in 0.5. Unfortunately, I'm not quite clever enough to see the significance of this right now... I tested the mtext lisp from this thread with, and without, the decimal, and the results "appeared" to be identical. So is it simply a "good" programming habit to include the decimal, just in case one has a scenario similar to (/ 1 2 )? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 7, 2010 Share Posted June 7, 2010 Exactly, its a really difficult bug to catch if you miss it.. When I want a real answer, I almost always deal in reals - else, if all arguments are integer, the answer may not be what is expected. 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.