matthewrussell Posted December 10, 2008 Posted December 10, 2008 Hey guys, I have played around with a lisp that is ran through a button i have made in CAD how ever the routine i have written doesnt work. Im not sure why it doesnt so I have attached it below. ;######## Lisp that runs text buttons ######## ;---3.5 Text--- (defun c:35text (/ oldlay) (setq oldlay (getvar "clayer")) (setvar "clayer" "35TEXT") (setvar "textstyle" "BMD_2009") (command "mtext" PAUSE "H" "3.5" PAUSE) (setvar "clayer" oldlay) (princ) ) ;defun Cheers, Quote
lpseifert Posted December 10, 2008 Posted December 10, 2008 not tested but try putting this after the (command... line (while (> (getvar 'CmdActive) 0) (command pause)) and be sure the layer and text style you call for are present in the dwg. Quote
matthewrussell Posted December 10, 2008 Author Posted December 10, 2008 I added it and made your all styles where there. It worked to begin with then when it was up to the stage where I input the text itself it just repeatedly going like this MText: \ MText: \ MText: \ MText: \ MText: \ MText: \ MText: \ MText: \ MText: \ MText: \ MText: \ MText: Function cancelledMText: sda3e2*Cancel* Not sure what the problem is there. This is what the code looks like now ;######## Lisp that runs text buttons ######## ;---3.5 Text--- (defun c:35text (/ oldlay) (setq oldlay (getvar "clayer")) (setvar "clayer" "35T") (setvar "textstyle" "BMD_2009") (command "mtext" PAUSE "H" "3.5" PAUSE) (while (> (getvar 'CmdActive) 0) (command pause)) (setvar "clayer" oldlay) (princ) ) ;defun Quote
Lee Mac Posted December 11, 2008 Posted December 11, 2008 M-Text is dodgy with LISP - this has what you need: (defun c:m (/ pt txt txt1) (setvar "cmdecho" 0) (while (and (/= (setq pt (getpoint "\nSelect Point for M-Text")) nil) (/= (setq txt (getstring t "\nSpecify Text: ")) "") ) ; end and (setq txt1 (strcat "\\P" txt)) (command "-mtext" pt "@500,-500" txt1 "") ) ; end while (setvar "cmdecho" 1) (princ "\nFunction Complete.") (princ) ) Quote
Lee Mac Posted December 11, 2008 Posted December 11, 2008 Had a bit of time - modified my original posted LISP: (defun c:35text (/ *error* varLst oldVars pt txt txt1) ; --- Error Trap --- (defun *error* (msg) (mapcar 'setvar varLst oldVars) (if (= msg "") (princ "\nFunction Complete.") (princ "\nError or Esc pressed... ") ) ;_ end if (princ) ) ; end of *error* (setq varLst (list "CMDECHO" "CLAYER" "TEXTSTYLE" "TEXTSIZE") oldVars (mapcar 'getvar varLst) ) ; end setq ; --- Error Trap --- (setvar "cmdecho" 0) (if (not (tblsearch "layer" "35T")) (command "-layer" "m" "35T" "") (setvar "clayer" "35T") ) ;_ end if (setvar "textsize" 3.5) (setvar "textstyle" "BMD_2009") (while (/= (setq txt (getstring t "\nSpecify Text: ")) "") (setq txt1 (strcat "\\P" txt)) (command "-mtext" pause pause txt1 "") ) ; end while (setvar "cmdecho" 1) (*error* "") ; reset old variables (princ) ) ;_ end defun May suit your needs better. Quote
matthewrussell Posted December 11, 2008 Author Posted December 11, 2008 how can it be changed to run from a certain textstyle and also set the size. I was looking at making a 5.0 3.5 and 2.5 high text buttons. Can it also be made to dump the text onto a set layer. So say if i clicked the 2.5 button it selects say layer 25T selects my textstyle and then makes the text 2.5 high. Is this possible (defun c:25text (/ pt txt txt1) (setvar "cmdecho" 0) (setq oldlay (getvar "clayer")) (setvar "clayer" "25T") (setvar "textstyle" "BMD_2009") (while (and (/= (setq pt (getpoint "\nSelect Point for M-Text")) nil) (/= (setq txt (getstring t "\nSpecify Text: ")) "") ) ; end and (setq txt1 (strcat "[url="file://\\P"]\\P[/url]" txt)) (command "-mtext" pt "@500,-500" txt1 "") ) ; end while (setvar "cmdecho" 1) (setvar "clayer" oldlay) (princ "\nFunction Complete.") (princ) ) I added that into it and it works but i can get a line to set the height. Also is it possible to change it so i dont have to enter the text in the command line but in the textbox itself? Quote
Lee Mac Posted December 11, 2008 Posted December 11, 2008 Check my other post Something like this: (defun c:25text (/ *error* varLst oldVars pt txt txt1) ; --- Error Trap --- (defun *error* (msg) (mapcar 'setvar varLst oldVars) (if (= msg "") (princ "\nFunction Complete.") (princ "\nError or Esc pressed... ") ) ;_ end if (princ) ) ; end of *error* (setq varLst (list "CMDECHO" "CLAYER" "TEXTSTYLE" "TEXTSIZE") oldVars (mapcar 'getvar varLst) ) ; end setq ; --- Error Trap --- (setvar "cmdecho" 0) (if (not (tblsearch "layer" "25T")) (command "-layer" "m" "25T" "") (setvar "clayer" "25T") ) ;_ end if (setvar "textsize" 2.5) (setvar "textstyle" "BMD_2009") (while (/= (setq txt (getstring t "\nSpecify Text: ")) "") (setq txt1 (strcat "\\P" txt)) (command "-mtext" pause pause txt1 "") ) ; end while (setvar "cmdecho" 1) (*error* "") ; reset old variables (princ) ) ;_ end defun Quote
Lee Mac Posted December 11, 2008 Posted December 11, 2008 As for typing the text in the textbox, not an easy feat with LISP, others may have a solution, but I'm out of ideas I'm afraid. Quote
matthewrussell Posted December 11, 2008 Author Posted December 11, 2008 Yeah i was unable to get that on the screen it just never wanted to work when i tried that out. Thanks for that. Ill play around with and get it to be correct to the companies drafting standards. But it works very well thanks for your help. Quote
matthewrussell Posted December 11, 2008 Author Posted December 11, 2008 ok i got a slight problem Lee, The textsize variable is getting set but however it is not effecting the actual text itself. Anyway around that? Quote
matthewrussell Posted December 11, 2008 Author Posted December 11, 2008 I found out why. I had to have the textstyle which is used in the lisp set as my current one. However this has confused me cause the code itself has (setvar "TEXTSTYLE" BMD-isocp) which is meant to set the style for the command. Quote
matthewrussell Posted December 11, 2008 Author Posted December 11, 2008 I figured it out. So it is working correctly. Only question left is that. Is it possible to make it so that if you want to enter another lot of text in you have to run the command again. So once you have type the text in selected the the points, finish then. Instead of asking for more text. Not sure what to change in your coding for that to be possible. And also it puts the text in the bottom of the textbox for some reason. It does it by like putting blank lines in above the actual test. This is just feedback from people i work with. Who are very happy with the coding you wrote Cheers, Quote
jammie Posted December 11, 2008 Posted December 11, 2008 Maybe this could help, an alternative way for getting the user input and could be incorporated into the above codes (command "mtext" pause "H" "3.5" pause "");<create an empty mtext (command "_mtedit" (entlast)) ;<edit mtext, when completed the function will continue Regards, Jammie Quote
Lee Mac Posted December 11, 2008 Posted December 11, 2008 Nice idea Jammie, Hadn't thought of that one, if you need help incorporating that into the code Matt, just post what you have so far and I'd be happy to help. Quote
matthewrussell Posted December 11, 2008 Author Posted December 11, 2008 Here is it, is im not sure where that coding is to be placed ;---2.5 Text--- (defun c:25text (/ *error* varLst oldVars pt txt txt1) ; --- Error Trap --- (defun *error* (msg) (mapcar 'setvar varLst oldVars) (if (= msg "") (princ "\nFunction Complete.") (princ "\nError or Esc pressed... ") ) ;_ end if (princ) ) ; end of *error* (setq varLst (list "CMDECHO" "CLAYER" "TEXTSTYLE" "TEXTSIZE") oldVars (mapcar 'getvar varLst) ) ; end setq ; --- Error Trap --- (setvar "cmdecho" 0) (if (not (tblsearch "layer" "25T")) (command "-layer" "m" "25T" "") (setvar "clayer" "25T") ) ;_ end if (setvar "textstyle" "BMD-isocp") (setvar "textsize" 2.5) (while (/= (setq txt (getstring t "\nSpecify Text: ")) "") (setq txt1 (strcat "[url="file://\\P"]\\P[/url]" txt)) (command "-mtext" pause pause txt1 "") ) ; end while (setvar "cmdecho" 1) (*error* "") ; reset old variables (princ) ) ;_ end defun cheers Quote
Lee Mac Posted December 11, 2008 Posted December 11, 2008 Like this maybe: ;---2.5 Text--- (defun c:25text (/ *error* varLst oldVars pt) ; --- Error Trap --- (defun *error* (msg) (mapcar 'setvar varLst oldVars) (if (= msg "") (princ "\nFunction Complete.") (princ "\nError or Esc pressed... ") ) ;_ end if (princ) ) ; end of *error* (setq varLst (list "CMDECHO" "CLAYER" "TEXTSTYLE" "TEXTSIZE") oldVars (mapcar 'getvar varLst) ) ; end setq ; --- Error Trap --- (setvar "cmdecho" 0) (if (not (tblsearch "layer" "25T")) (command "-layer" "m" "25T" "") (setvar "clayer" "25T") ) ;_ end if (setvar "textstyle" "BMD-isocp") (setvar "textsize" 2.5) (while (/= (setq pt (getpoint "\nSpecify Point for Text: ")) nil) (command "-mtext" pt pause "") ;<create an empty mtext (command "_mtedit" (entlast)) ) ; end while (setvar "cmdecho" 1) (*error* "") ; reset old variables (princ) ) ;_ end defun Quote
matthewrussell Posted December 11, 2008 Author Posted December 11, 2008 Oh yeah i see what you did. You added the text where the old command was and delete the other lines that went with it and also added user imput line. Thanks for the help again Lee 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.