au-s Posted February 3, 2010 Posted February 3, 2010 Hi, I have been trying to acomplish a lisp wich tells me to choose scale I want to type text with. So if I choose to type text (dtext) in a certain chosen scale I get a certain height for it. When I run the command I get "nil". What is wrong? Can that be acomplished in some other way? Maybe with a PopUp list which is more userfriendly and in that popup have those different scales. Here is the lisp: (defun C:test (/ oldlay new_txtsize new_layer scale) (initerr) (setq oldlay (getvar "clayer")) (if (= (getvar "tilemode") 0) (progn (initget "1 2 10 20 50 100 200 400 500 +500") (setq skala (getkword "\nChoose scale [1/2/10/20/50/100/200/400/500/+500]: ")) (cond ((= scale "1") (setq new_layer "A-------T1-------A" new_txtsize 3.2)) ((= scale "2") (setq new_layer "A-------T1-------J" new_txtsize 6.4)) ((= scale "5") (setq new_layer "A-------T1-------J" new_txtsize 16.0)) ((= scale "10") (setq new_layer "A-------T1-------C" new_txtsize 32.0)) ((= scale "20") (setq new_layer "A-------T1-------D" new_txtsize 64.0)) ((= scale "50") (setq new_layer "A-------T1-------E" new_txtsize 175.0)) ((= scale "100") (setq new_layerr "A-------T1-------F" new_txtsize 350.0)) ((= scale "200") (setq new_layerr "A-------T1-------G" new_txtsize 700.0)) ((= scale "400") (setq new_layer "A-------T1-------K" new_txtsize 1400.0)) ((= scale "500") (setq new_layer "A-------T1-------H" new_txtsize 1750.0)) ((= scale "+500") (setq new_layer "A-------T1-------X" new_txtsize 3500.0)) ) (if (null (tblsearch "LAYER" new_layer)) (command "_LAYER" "_N" new_layer "_C" "red" new_layer "") ) (setvar "cmdecho" 0) (load "K:\\CAD\\AIX-meny-2008\\Lisp\\text\\AIX_TextVariabler.lsp") ; loads variables (fonts) (VanligText) ; that loads variables (font) (setvar "textsize" new_txtsize) (initdia) (setq PT1 (getpoint "\n Starting Point :")) (setvar "filedia" 0) (command "_dtext" PT1 "" "" "") (setvar "filedia" 1) (setvar "clayer" oldlay) ))) And how can I add a scalefactor that a user is choosing ie 1:12 A new layer should be for a user chosen scale A-------T1-------X Is it done with: (setq TextScale (* 3.2 skala)) Quote
Commandobill Posted February 4, 2010 Posted February 4, 2010 Well first things first i suppose. (setq skala (getkword "\nChoose scale [1/2/10/20/50/100/200/400/500/+500]: ")) (cond ((= scale "1") (setq new_layer "A-------T1-------A" new_txtsize 3.2)) ((= scale "2") (setq new_layer "A-------T1-------J" new_txtsize 6.4)) ((= scale "5") (setq new_layer "A-------T1-------J" new_txtsize 16.0)) ((= scale "10") (setq new_layer "A-------T1-------C" new_txtsize 32.0)) ((= scale "20") (setq new_layer "A-------T1-------D" new_txtsize 64.0)) ((= scale "50") (setq new_layer "A-------T1-------E" new_txtsize 175.0)) ((= scale "100") (setq new_layerr "A-------T1-------F" new_txtsize 350.0)) ((= scale "200") (setq new_layerr "A-------T1-------G" new_txtsize 700.0)) ((= scale "400") (setq new_layer "A-------T1-------K" new_txtsize 1400.0)) ((= scale "500") (setq new_layer "A-------T1-------H" new_txtsize 1750.0)) ((= scale "+500") (setq new_layer "A-------T1-------X" new_txtsize 3500.0)) ) you are setting "skala" and checking "scale" Quote
Lee Mac Posted February 4, 2010 Posted February 4, 2010 Also, You are not setting the layer anywhere You are using (command "_.dtext" which can be highly unpredictable, I would use entmake or vla-addtext. Whats with all the initdia and filedia? Quote
au-s Posted February 5, 2010 Author Posted February 5, 2010 Well ... that is only my attempt to make something But I appriciate tips Quote
Lee Mac Posted February 5, 2010 Posted February 5, 2010 See if you can get some tips from this: (defun c:test (/ Make_Text pt new_layer new_txtsize) (defun Make_Text (pt str hgt lay) (entmakex (list (cons 0 "TEXT") (cons 8 lay) (cons 40 hgt) (cons 10 pt) (cons 1 str)))) (setq *scl* (cond (*scl*) ("10"))) (initget "1 2 10 20 50 100 200 400 500 +500") (setq *scl* (cond ((getkword (strcat "\nChoose Scale [1/2/10/20/50/100/200/400/500/+500] <" *scl* "> : "))) (*scl*))) (if (setq pt (getpoint "\nSelect Point: ")) (progn (cond ((= *scl* "1") (setq new_layer "A-------T1-------A" new_txtsize 3.2)) ((= *scl* "2") (setq new_layer "A-------T1-------J" new_txtsize 6.4)) ((= *scl* "5") (setq new_layer "A-------T1-------J" new_txtsize 16.0)) ((= *scl* "10") (setq new_layer "A-------T1-------C" new_txtsize 32.0)) ((= *scl* "20") (setq new_layer "A-------T1-------D" new_txtsize 64.0)) ((= *scl* "50") (setq new_layer "A-------T1-------E" new_txtsize 175.0)) ((= *scl* "100") (setq new_layer "A-------T1-------F" new_txtsize 350.0)) ((= *scl* "200") (setq new_layer "A-------T1-------G" new_txtsize 700.0)) ((= *scl* "400") (setq new_layer "A-------T1-------K" new_txtsize 1400.0)) ((= *scl* "500") (setq new_layer "A-------T1-------H" new_txtsize 1750.0)) ((= *scl* "+500") (setq new_layer "A-------T1-------X" new_txtsize 3500.0))) (Make_Text pt "This is a String" new_txtsize new_layer))) (princ)) Quote
au-s Posted February 11, 2010 Author Posted February 11, 2010 Hey, Thanx... I came up with this idea of having a popup menu loaded. This is the modified lisp, see below. Allthough when I choose a scale from the popup menu I can't get it to work. If I choose scale 1:5 it actually works but it chooses the wrong textheight. For that to work you need DOSLib to be installed. Anyone? ;if layout, stop the lisp and execute textheight 3.2mm (defun dtexttilemode1 () (if (null (tblsearch "LAYER" "A-------T1-------A")) (command "_LAYER" "_N" "A-------T1-------A" "_C" 1 "A-------T1-------A" "") ) (setvar "clayer" "A-------T1-------A") (command "_dtext" pt 3.2 "" "") (setvar "clayer" oldlay) ) ;popupscale, choose which scale (defun popupskaladtext (/ scl x) (setq x ( list "1:1" "1:2" "1:5" "1:10" "1:20" "1:50" "1:100" "1:200" "1:400" "1:500" "1:1000" "1:2000" ) scl nil ) (while (or (not scl) (= scl 0)) (setq scl (dos_popupmenu x)) ) ) ;main function (defun c:TEXT (/ Make_Text pt new_layer new_txtsize oldlay scl x) (setq oldlay (getvar "clayer")) (setq pt (getpoint "\nChoose point: ")) (if (= (getvar "tilemode") 0) (dtexttilemode1) (progn (popupskaladtext) (cond ((= scl 1) (setq new_layer "A-------T1-------A" new_txtsize 3.2)) ((= scl 2) (setq new_layer "A-------T1-------J" new_txtsize 6.4)) ((= scl 5) (setq new_layer "A-------T1-------B" new_txtsize 16.0)) ((= scl 10) (setq new_layer "A-------T1-------C" new_txtsize 32.0)) ((= scl 20) (setq new_layer "A-------T1-------D" new_txtsize 64.0)) ((= scl 50) (setq new_layer "A-------T1-------E" new_txtsize 160.0)) ((= scl 100) (setq new_layer "A-------T1-------F" new_txtsize 320.0)) ((= scl 200) (setq new_layer "A-------T1-------G" new_txtsize 640.0)) ((= scl 400) (setq new_layer "A-------T1-------K" new_txtsize 1280.0)) ((= scl 500) (setq new_layer "A-------T1-------H" new_txtsize 1600.0)) ((= scl 1000) (setq new_layer "A-------T1-------X" new_txtsize 3200.0)) ((= scl 2000) (setq new_layer "A-------T1------X2" new_txtsize 6400.0))) (if (null (tblsearch "LAYER" new_layer)) (command "_LAYER" "_N" new_layer "_C" 1 new_layer "") ) (setvar "clayer" new_layer) (command "_dtext" pt new_txtsize "" "") (setvar "clayer" oldlay))) (princ) ) Hmm ... it might be that I need to convert "1:1" etc to a string? Quote
Lee Mac Posted February 11, 2010 Posted February 11, 2010 Hey, Thanx... I came up with this idea of having a popup menu loaded. This is the modified lisp, see below. Allthough when I choose a scale from the popup menu I can't get it to work. If I choose scale 1:5 it actually works but it chooses the wrong textheight. For that to work you need DOSLib to be installed. Anyone? ;if layout, stop the lisp and execute textheight 3.2mm (defun dtexttilemode1 () (if (null (tblsearch "LAYER" "A-------T1-------A")) (command "_LAYER" "_N" "A-------T1-------A" "_C" 1 "A-------T1-------A" "") ) (setvar "clayer" "A-------T1-------A") (command "_dtext" pt 3.2 "" "") (setvar "clayer" oldlay) ) ;popupscale, choose which scale (defun popupskaladtext (/ scl x) (setq x ( list "1:1" "1:2" "1:5" "1:10" "1:20" "1:50" "1:100" "1:200" "1:400" "1:500" "1:1000" "1:2000" ) scl nil ) (while (or (not scl) (= scl 0)) (setq scl (dos_popupmenu x)) ) ) ;main function (defun c:TEXT (/ Make_Text pt new_layer new_txtsize oldlay scl x) (setq oldlay (getvar "clayer")) (setq pt (getpoint "\nChoose point: ")) (if (= (getvar "tilemode") 0) (dtexttilemode1) (progn (popupskaladtext) (cond ((= scl 1) (setq new_layer "A-------T1-------A" new_txtsize 3.2)) ((= scl 2) (setq new_layer "A-------T1-------J" new_txtsize 6.4)) ((= scl 5) (setq new_layer "A-------T1-------B" new_txtsize 16.0)) ((= scl 10) (setq new_layer "A-------T1-------C" new_txtsize 32.0)) ((= scl 20) (setq new_layer "A-------T1-------D" new_txtsize 64.0)) ((= scl 50) (setq new_layer "A-------T1-------E" new_txtsize 160.0)) ((= scl 100) (setq new_layer "A-------T1-------F" new_txtsize 320.0)) ((= scl 200) (setq new_layer "A-------T1-------G" new_txtsize 640.0)) ((= scl 400) (setq new_layer "A-------T1-------K" new_txtsize 1280.0)) ((= scl 500) (setq new_layer "A-------T1-------H" new_txtsize 1600.0)) ((= scl 1000) (setq new_layer "A-------T1-------X" new_txtsize 3200.0)) ((= scl 2000) (setq new_layer "A-------T1------X2" new_txtsize 6400.0))) (if (null (tblsearch "LAYER" new_layer)) (command "_LAYER" "_N" new_layer "_C" 1 new_layer "") ) (setvar "clayer" new_layer) (command "_dtext" pt new_txtsize "" "") (setvar "clayer" oldlay))) (princ) ) Hmm ... it might be that I need to convert "1:1" etc to a string? Have a look at how I have created the text in my example. Quote
au-s Posted February 11, 2010 Author Posted February 11, 2010 I dont think that that is the issue. I am experimenting now with how the lisp reads the scale from the list x. so I have added setq scldtext (substr scl 3)) which i hope it means that from the list the scale is written as 1, 2, 50, 100 etc without the "1:". But i get it a bit wrong anyway: (defun popupskaladtext () (setq x ( list "" "1:1" "1:2" "1:5" "1:10" "1:20" "1:50" "1:100" "1:200" "1:400" "1:500" "1:1000" "1:2000" "" ) scl nil ) (while (or (not scl) (= 0 scl) ) ;_ or (setq scl (dos_popupmenu x)) ) ;_ while (setq scldtext (substr scl 3)) ); end defun And this is the condition: (cond ((= scldtext "1") (setq new_layer "A-------T1-------A" new_txtsize 3.2)) ((= scldtext "2") (setq new_layer "A-------T1-------J" new_txtsize 6.4)) ((= scldtext "5") (setq new_layer "A-------T1-------B" new_txtsize 16.0)) ((= scldtext "10") (setq new_layer "A-------T1-------C" new_txtsize 32.0)) ((= scldtext "20") (setq new_layer "A-------T1-------D" new_txtsize 64.0)) ((= scldtext "50") (setq new_layer "A-------T1-------E" new_txtsize 160.0)) ((= scldtext "100") (setq new_layer "A-------T1-------F" new_txtsize 320.0)) ((= scldtext "200") (setq new_layer "A-------T1-------G" new_txtsize 640.0)) ((= scldtext "400") (setq new_layer "A-------T1-------K" new_txtsize 1280.0)) ((= scldtext "500") (setq new_layer "A-------T1-------H" new_txtsize 1600.0)) ((= scldtext "1000") (setq new_layer "A-------T1-------X" new_txtsize 3200.0)) ((= scldtext "2000") (setq new_layer "A-------T1------X2" new_txtsize 6400.0))) Allthough this is the error I get when choosing scale 1:10 error: bad argument type: stringp 3 Choosing scale 1:2 will result in this error message: error: bad argument type: stringp 1 etc etc ... I dont know if the substr is okay ... Quote
au-s Posted February 11, 2010 Author Posted February 11, 2010 I have done this with this simple thing ;;;DESCRITION ;if layout, make the lisp write with the layer for 1:1 (defun dtexttilemode1 () (if (null (tblsearch "LAYER" "A-------T1-------A")) (command "_LAYER" "_N" "A-------T1-------A" "_C" 1 "A-------T1-------A" "") ) (setvar "clayer" "A-------T1-------A") (command "_dtext" pt 3.2 "" "") (setvar "clayer" oldlay) ) ;popupscale, choose which scale (defun Popupskala1 () (setq popupskaladtext (dos_popupmenu '( "" "1:1" "1:2" "1:5" "1:10" "1:20" "1:50" "1:100" "1:200" "1:400" "1:500" "1:1000" "1:2000" "" ))) ) ;main function (defun c:test (/ pt new_layer new_txtsize oldlay scldtext scl_Text skala) (setq oldlay (getvar "clayer")) (setq pt (getpoint "\nVälj startpunkt: ")) (if (= (getvar "tilemode") 0) (dtexttilemode1) (progn (Popupskala1) ;(setq scl_Text (atoi skala)) (cond ((= popupskaladtext 0) (setq new_layer "A-------T1-------A" new_txtsize 3.2)) ((= popupskaladtext 1) (setq new_layer "A-------T1-------J" new_txtsize 6.4)) ((= popupskaladtext 2) (setq new_layer "A-------T1-------B" new_txtsize 16.0)) ((= popupskaladtext 3) (setq new_layer "A-------T1-------C" new_txtsize 32.0)) ((= popupskaladtext 4) (setq new_layer "A-------T1-------D" new_txtsize 64.0)) ((= popupskaladtext 5) (setq new_layer "A-------T1-------E" new_txtsize 160.0)) ((= popupskaladtext 6) (setq new_layer "A-------T1-------F" new_txtsize 320.0)) ((= popupskaladtext 7) (setq new_layer "A-------T1-------G" new_txtsize 640.0)) ((= popupskaladtext (setq new_layer "A-------T1-------K" new_txtsize 1280.0)) ((= popupskaladtext 9) (setq new_layer "A-------T1-------H" new_txtsize 1600.0)) ((= popupskaladtext 10) (setq new_layer "A-------T1-------X" new_txtsize 3200.0)) ((= popupskaladtext 11) (setq new_layer "A-------T1------X2" new_txtsize 6400.0))) (if (null (tblsearch "LAYER" new_layer)) (command "_LAYER" "_N" new_layer "_C" 1 new_layer "") ) (setvar "clayer" new_layer) (command "_dtext" pt new_txtsize "" "") (setvar "clayer" oldlay))) (princ) ) Quote
Lee Mac Posted February 11, 2010 Posted February 11, 2010 I dont think that that is the issue. It may not be, but it is a much better way than using _.dtext to create the text, _.dtext is known to be unreliable when used on different drawings. Quote
au-s Posted February 11, 2010 Author Posted February 11, 2010 Okay. For the user input instead of automatically writing "This is a string", do I need to look at the getstring function for the lisp to make a pause and wait for user input on the screen? Quote
Lee Mac Posted February 11, 2010 Posted February 11, 2010 Yes, for example: (defun c:test (/ Make_Text pt new_layer new_txtsize str) (defun Make_Text (pt str hgt lay) (entmakex (list (cons 0 "TEXT") (cons 8 lay) (cons 40 hgt) (cons 10 pt) (cons 1 str)))) (setq *scl* (cond (*scl*) ("10"))) (initget "1 2 10 20 50 100 200 400 500 +500") (setq *scl* (cond ((getkword (strcat "\nChoose Scale [1/2/10/20/50/100/200/400/500/+500] <" *scl* "> : "))) (*scl*))) (if (setq pt (getpoint "\nSelect Point: ")) (progn (setq str (getstring t "\nString: ")) (cond ((= *scl* "1") (setq new_layer "A-------T1-------A" new_txtsize 3.2)) ((= *scl* "2") (setq new_layer "A-------T1-------J" new_txtsize 6.4)) ((= *scl* "5") (setq new_layer "A-------T1-------J" new_txtsize 16.0)) ((= *scl* "10") (setq new_layer "A-------T1-------C" new_txtsize 32.0)) ((= *scl* "20") (setq new_layer "A-------T1-------D" new_txtsize 64.0)) ((= *scl* "50") (setq new_layer "A-------T1-------E" new_txtsize 175.0)) ((= *scl* "100") (setq new_layer "A-------T1-------F" new_txtsize 350.0)) ((= *scl* "200") (setq new_layer "A-------T1-------G" new_txtsize 700.0)) ((= *scl* "400") (setq new_layer "A-------T1-------K" new_txtsize 1400.0)) ((= *scl* "500") (setq new_layer "A-------T1-------H" new_txtsize 1750.0)) ((= *scl* "+500") (setq new_layer "A-------T1-------X" new_txtsize 3500.0))) (Make_Text pt str new_txtsize new_layer))) (princ)) Quote
au-s Posted February 11, 2010 Author Posted February 11, 2010 Yes, I was just reading the manual about it ... By the way , can the user see what he is writing in the model/paperspace instead of in the AutoCad window? Quote
Lee Mac Posted February 11, 2010 Posted February 11, 2010 Yes, I was just reading the manual about it ... By the way , can the user see what he is writing in the model/paperspace instead of in the AutoCad window? No [10 char fill] 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.