MarcoW Posted July 21, 2009 Share Posted July 21, 2009 Hi, This is a piece of code I want to use to place text in a drawing. It is put behind a lisp routine, so if that routine is finished this last part should be carried out. (setq height (getdist "\nHeight in mm: ") Len 1000 power (getreal "\nPower: ") opt (getstring "\nOptionnal text: ") type (getstring "\nType: ") tho (getvar "textsize") sch (getvar "dimscale") thn (* 2.5 sch) location (getpoint "\nGive insertion point: ") loc1 (polar location 0 500) loc2 (polar location pi 500) ss1 (ssadd) textstring (strcat (rtos height) "-" type "-" (rtos len) "\n" (rtos power) " W " opt) colo (getvar "cecolor") coln 2 ) (setvar "textsize" thn) (command "_.cecolor" coln) (command "_.mtext" location "j" "mc" location textstring "") (ssadd (entlast) ss1) (command "_.line" loc1 loc2 "") (ssadd (entlast) ss1) (setvar "textsize" tho) (command "_.cecolor" colo) (setvar "orthomode" 0 ) (setvar "osmode" 0 ) (princ "Move text if you want…") (command "_.move" ss1 "" location pause) Problem is that all prompted filds must be filled out in order to work properly. I.e. if prompted “Type: “ and I give only an error occurs. I am doing something wrong I guess with the rtos thingy. Can someone help me? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
ollie Posted July 21, 2009 Share Posted July 21, 2009 (if (eq (setq type (getstring "\nType: ")) nil) (setq type "") ) That should work Quote Link to comment Share on other sites More sharing options...
MarcoW Posted July 21, 2009 Author Share Posted July 21, 2009 Oops... I tried to fit it in my code but it don't work. Do I have to erase the line type (getstring "\nType: ") and add your lines somewhere in the routine or must it be replaced? Funny (not funny) that I've come this far and don't get this last part running... Quote Link to comment Share on other sites More sharing options...
techjunkie09 Posted July 21, 2009 Share Posted July 21, 2009 yes replace your type (getstring "\nType: ") with (if (eq (setq type (getstring "\nType: ")) nil) (setq type "") ) not sure but it'd probably work as (if (= (getstring "\nType:") nil) (setq type "")) as well, so feel free to try that if the top doesn't work Quote Link to comment Share on other sites More sharing options...
MarcoW Posted July 21, 2009 Author Share Posted July 21, 2009 I keep getting this: <!> Error: bad argument type: stringp nil <!> This occurs just before giving the insertion point for text placement. Quote Link to comment Share on other sites More sharing options...
Commandobill Posted July 21, 2009 Share Posted July 21, 2009 Hi, Problem is that all prompted fields must be filled out in order to work properly. I.e. if prompted “Type: “ and I give only an error occurs. I am doing something wrong I guess with the rtos thingy. Can someone help me? Thanks in advance. hmm are you sure it doesnt work if you leave "type" out? i could see it having an issue with location or power or anything you are trying to convert but with getstring it will automatically return "" if you hit enter. Quote Link to comment Share on other sites More sharing options...
Commandobill Posted July 21, 2009 Share Posted July 21, 2009 Also do not use "type" as a variable as it is also an autolisp function Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 21, 2009 Share Posted July 21, 2009 Marco, use a code editor, (maybe Visual LISP Editor in ACAD) so that protected symbols such as functions show up in Blue, and you know then not to use them Lee Quote Link to comment Share on other sites More sharing options...
MarcoW Posted July 22, 2009 Author Share Posted July 22, 2009 Hi again, @ Lee: you are right, I should use the lisp editor. Can you please explain to me how to get the code in the same colour here on the forum as in the vlide editor? Or do you always manually modify the colours? I have tried several things but I keep getting errors. Example error: ; error: bad variable name in SETQ: (IF (= (GETSTRING "\nType:") nil) (SETQ TYP "")) So, what is the problem.... Maybe if I tell you what I would like the program to do we can all together solve this thing. When giving command "test" it should ask for height, power etc. Whatever is filled in or whenever nothing is filled in, it should work. I mean, if I do not enter a value in the "Specify height: " part, it errors and stops. I am not that great explainer I realize but try the code and skip one or more values. It don't work. Any help is apreciated. Here is my last attempt: (defun c:test () (setq height (getdist "\nSpecify height: ") power (getint "\nSpecify power: ") opt (getstring "\nOptional text: ") typ (getint "\nType box: ") len 1500 ; this is a preset for now tho (getvar "textsize") sca (getvar "dimscale") thn (* 2.5 sca) ; so my text allways appears in height 2.5 * the dimscale location (getpoint "\nOrigin of text placement: ") loc1 (polar location 0 500) loc2 (polar location pi 500) ss1 (ssadd) textstring (strcat (rtos height) "-" (rtos typ) "-" (rtos len) "\n" (rtos power) " " opt ) colo (getvar "cecolor") coln 2 ) (setvar "textsize" thn) (command "_.cecolor" coln) (command "_.mtext" loc1 "j" "mc" loc2 textstring "") (ssadd (entlast) ss1) (command "_.line" loc1 loc2 "") (ssadd (entlast) ss1) (setvar "textsize" tho) (command "_.cecolor" colo) (setvar "orthomode" 0) (setvar "osmode" 0) (princ "Move the text if you like:") (command "_.move" ss1 "" location pause) (princ) ) (My feeling says that it has something to do with the strcat function, thats why I "rtossed" the numeric values to strings values. Also there must be a sort of "big if" function: whenever 1 ore more values are nil it should be something else like "". But that I do not seem to manage. Quote Link to comment Share on other sites More sharing options...
Commandobill Posted July 22, 2009 Share Posted July 22, 2009 Trying to stay as close to your original code as possible. Untested (defun c:test ( / height power opt typ location loc1 loc2 ss1 textstring colo tho) ;always localize your variables (setq height (if (setq height (getdist "\nSpecify height: ")) (rtos height);if true make string ""));if nil make it a string of nothing (setq power (if (setq power (getint "\nSpecify power: ")) (itoa power);if true make string ""));if nil make it a string of nothing (setq opt (getstring "\nOptional text: ")) (setq typ (if (setq typ (getint "\nType box: ")) (itoa typ);if true make string ""));if nil make it a string of nothing (while (not (setq location (getpoint "\nOrigin of text placement: ")))) (setq loc1 (polar location 0 500) loc2 (polar location pi 500) ss1 (ssadd) textstring (strcat (rtos height) "-" typ "-" "1500" "\n" power " " opt ) colo (getvar "cecolor") ) (setvar "textsize" (* 2.5 (setq tho (getvar "dimscale")))) (command "_.cecolor" 2) (command "_.mtext" loc1 "j" "mc" loc2 textstring "") (ssadd (entlast) ss1) (command "_.line" loc1 loc2 "") (ssadd (entlast) ss1) (setvar "textsize" tho) (command "_.cecolor" colo) (setvar "orthomode" 0) (setvar "osmode" 0) (princ "Move the text if you like:") (command "_.move" ss1 "" location pause) (princ) ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 22, 2009 Share Posted July 22, 2009 @ Lee: you are right, I should use the lisp editor. Can you please explain to me how to get the code in the same colour here on the forum as in the vlide editor? Or do you always manually modify the colours? I have written myself a LISP to add the correct colour tags to the code before I post it Example error: ; error: bad variable name in SETQ: (IF (= (GETSTRING "\nType:") nil) (SETQ TYP "")) I can't find this section in your code, this must be caused elsewhere... EDIT: I see that CommmandoBill has provided another option Quote Link to comment Share on other sites More sharing options...
MarcoW Posted July 23, 2009 Author Share Posted July 23, 2009 @ Commandobill: Tnx for your reply. Just tried the code, but it won't work. Don't have the time now to get in to it but I will. Trying to stay as close to your original code as possible. Untested (defun c:test ( / height power opt typ location loc1 loc2 ss1 textstring colo tho) ;always localize your variables (setq height (if (setq height (getdist "\nSpecify height: ")) (rtos height);if true make string ""));if nil make it a string of nothing (setq power (if (setq power (getint "\nSpecify power: ")) (itoa power);if true make string ""));if nil make it a string of nothing (setq opt (getstring "\nOptional text: ")) (setq typ (if (setq typ (getint "\nType box: ")) (itoa typ);if true make string ""));if nil make it a string of nothing (while (not (setq location (getpoint "\nOrigin of text placement: ")))) (setq loc1 (polar location 0 500) loc2 (polar location pi 500) ss1 (ssadd) textstring (strcat (rtos height) "-" typ "-" "1500" "\n" power " " opt ) colo (getvar "cecolor") ) (setvar "textsize" (* 2.5 (setq tho (getvar "dimscale")))) (command "_.cecolor" 2) (command "_.mtext" loc1 "j" "mc" loc2 textstring "") (ssadd (entlast) ss1) (command "_.line" loc1 loc2 "") (ssadd (entlast) ss1) (setvar "textsize" tho) (command "_.cecolor" colo) (setvar "orthomode" 0) (setvar "osmode" 0) (princ "Move the text if you like:") (command "_.move" ss1 "" location pause) (princ) ) Quote Link to comment Share on other sites More sharing options...
Commandobill Posted July 23, 2009 Share Posted July 23, 2009 sorry i forgot to remove some thing. this should work (defun c:test ( / height power opt typ location loc1 loc2 ss1 textstring colo tho) ;always localize your variables (setq height (if (setq height (getdist "\nSpecify height: ")) (rtos height);if true make string ""));if nil make it a string of nothing (setq power (if (setq power (getint "\nSpecify power: ")) (itoa power);if true make string ""));if nil make it a string of nothing (setq opt (getstring "\nOptional text: ")) (setq typ (if (setq typ (getint "\nType box: ")) (itoa typ);if true make string ""));if nil make it a string of nothing (while (not (setq location (getpoint "\nOrigin of text placement: ")))) (setq loc1 (polar location 0 500) loc2 (polar location pi 500) ss1 (ssadd) textstring (strcat height "-" typ "-" "1500" "\n" power " " opt ) colo (getvar "cecolor") ) (setvar "textsize" (* 2.5 (setq tho (getvar "dimscale")))) (command "_.cecolor" 2) (command "_.mtext" loc1 "j" "mc" loc2 textstring "") (ssadd (entlast) ss1) (command "_.line" loc1 loc2 "") (ssadd (entlast) ss1) (setvar "textsize" tho) (command "_.cecolor" colo) (setvar "orthomode" 0) (setvar "osmode" 0) (princ "Move the text if you like:") (command "_.move" ss1 "" location pause) (princ) ) Quote Link to comment Share on other sites More sharing options...
MarcoW Posted July 24, 2009 Author Share Posted July 24, 2009 I'm sorry but I have entered some comments in the code, not very handy (defun c:test ( / height power opt typ location loc1 loc2 ss1 textstring colo tho) ;always localize your variables [color=red] ;; Well of course, I now see I forgot to post the "defun" line...[/color] (setq height (if (setq height (getdist "\nSpecify height: ")) (rtos height);if true make string [color=red];rtos converts any number (integer or real) to a string for getint requires integer OR real[/color] ""));if nil make it a string of nothing (setq power (if (setq power (getint "\nSpecify power: ")) (itoa power);if true make string [color=red] ;itoa converts integer to string)[/color] [color=red] ;am I right to say that rtos could be used as well?[/color] ""));if nil make it a string of nothing (setq opt (getstring "\nOptional text: "))[color=red] ; nothing to convert[/color] (setq typ (if (setq typ (getint "\nType box: ")) (itoa typ);if true make string ""));if nil make it a string of nothing (while (not (setq location (getpoint "\nOrigin of text placement: ")))) [color=red] ; what's with the wile + not ?[/color] [color=red] ; okay i figured -> it expects a point, if hit enter it still does, escape = end.[/color] (setq loc1 (polar location 0 500) loc2 (polar location pi 500) ss1 (ssadd) textstring (strcat height "-" typ "-" "1500"; [color=red]I'll turn it into "length" if routine runs[/color] "\n" power " " opt ) colo (getvar "cecolor") ) (setvar "textsize" (* 2.5 (setq tho (getvar "dimscale")))) (command "_.cecolor" 2) (command "_.mtext" location "j" "mc" location textstring "") (ssadd (entlast) ss1) [color=red] ; next part don't work the first time the routine runs in NEW drawing[/color] [color=red] ; if run for the second time it works... why..?[/color] (command "_.line" loc1 loc2 "") [color=red]; if I leave out 1 value it runs...[/color] [color=red] ;; until here[/color] (ssadd (entlast) ss1) (setvar "textsize" tho) (command "_.cecolor" colo) (setvar "orthomode" 0) (setvar "osmode" 0) (princ "Move the text if you like:") (command "_.move" ss1 "" location pause) (princ) ) Pff... Quote Link to comment Share on other sites More sharing options...
Commandobill Posted July 24, 2009 Share Posted July 24, 2009 you can use rtos on integers but then why wouldnt you just ask for a real to begin with. im not sure y it doesnt run for you it runs for me everytime.... anyone else having problems with it? 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.