asos2000 Posted April 5, 2010 Posted April 5, 2010 whats wrong with this code? (initget 0 "Meter MMeter") (if (setq DwgUnts (getkword "\nWhat is drawing units? [Meter/MMeter]: ")) (if (> 6 (strlen DwgUnts)) (progn (command "_.-style" "EC-22-0.01" "romans.shx" 0.22 "0.8" "0" "n" "n" "n") (setvar "DIMTXT" 0.22) ) (progn (command "_.-style" "EC-22-100" "romans.shx" 220 "0.8" "0" "n" "n" "n") (setvar "DIMTXT" 220) ) )) Error Invalid option keyword. Quote
asos2000 Posted April 5, 2010 Author Posted April 5, 2010 Try this: (initget 8 "Meter MMeter") The same error Quote
The Buzzard Posted April 5, 2010 Posted April 5, 2010 STRLEN - Returns an integer that is the number of characters in a string (if (> 6 (strlen DwgUnts)) Seems to me both are not greater than 6. In addition to that you should have two statements. (if (= 6 (strlen DwgUnts)) MMeter (if (= 5 (strlen DwgUnts)) Meter Quote
Lee Mac Posted April 5, 2010 Posted April 5, 2010 Why not use something like: (initget "Meter" "mmEter") Quote
The Buzzard Posted April 5, 2010 Posted April 5, 2010 Something like this maybe. (initget 0 "Meter MMeter") (if (setq DwgUnts (getkword "\nWhat is drawing units? [Meter/MMeter]: ")) (if (= 5 (strlen DwgUnts)) (progn (command "_.-style" "EC-22-0.01" "romans.shx" 0.22 "0.8" "0" "n" "n" "n") (setvar "DIMTXT" 0.22) ) ) (if (= 6 (strlen DwgUnts)) (progn (command "_.-style" "EC-22-100" "romans.shx" 220 "0.8" "0" "n" "n" "n") (setvar "DIMTXT" 220) ) ) ) Quote
The Buzzard Posted April 5, 2010 Posted April 5, 2010 I just tested this and it works. (initget 8 "Meter Millimeter") (setq DwgUnts (getkword "\nWhat is drawing units? [Meter/Millimeter]: ")) (if (= DwgUnts "Millimeter") (progn (command "_.-style" "EC-22-0.01" "romans.shx" 0.22 "0.8" "0" "n" "n" "n") (setvar "DIMTXT" 0.22) ) ) (if (= DwgUnts "Meter") (progn (command "_.-style" "EC-22-100" "romans.shx" 220 "0.8" "0" "n" "n" "n") (setvar "DIMTXT" 220) ) ) Quote
Lee Mac Posted April 5, 2010 Posted April 5, 2010 Why bitcode 8? Also, the double IF statement would cause the choice to fail if the user hit enter (causing getkword to return nil). Quote
Lee Mac Posted April 5, 2010 Posted April 5, 2010 I would instead use: (initget "Meter mIllimeter") (if (= "mIllimeter" (getkword "\nWhat is Drawing Units? [Meter/mIllimeter] <Meter> : ")) (progn (command "_.-style" "EC-22-0.01" "romans.shx" 0.22 "0.8" "0" "n" "n" "n") (setvar "DIMTXT" 0.22)) (progn (command "_.-style" "EC-22-100" "romans.shx" 220 "0.8" "0" "n" "n" "n") (setvar "DIMTXT" 220))) Quote
The Buzzard Posted April 5, 2010 Posted April 5, 2010 Why bitcode 8? Also, the double IF statement would cause the choice to fail if the user hit enter (causing getkword to return nil). No special reason, I have always used it. And it is putting the styles in, But you are right about the nil. I suppose this could be done with a cond? Quote
Lee Mac Posted April 5, 2010 Posted April 5, 2010 No special reason, I have always used it. Why use it then? Do you know what it does? I suppose this could be done with a cond? True, with more than two options, a COND would be needed, but with only two, it is concise to use a single IF Quote
The Buzzard Posted April 5, 2010 Posted April 5, 2010 Why use it then? Do you know what it does? True, with more than two options, a COND would be needed, but with only two, it is concise to use a single IF When I crossed it over in the help section, I crossed over on the wrong line. I never ran into a problen with it, So I never double check it. Sorry, I try not to let that happen again. I do believe I was on the right track all the same, Just the wrong car I guess. I did not intentionally try to cross over on anybodies turf either, Just trying to help. Quote
asos2000 Posted April 5, 2010 Author Posted April 5, 2010 The Buzzard Works good Lee Not working I don't know why Quote
Lee Mac Posted April 5, 2010 Posted April 5, 2010 The Buzzard Works goodLee Not working I don't know why Bear in mind that I changed the initget strings, so the user will have to input "I" for millimeters - I considered this less ambiguous. When I crossed it over in the help section, I crossed over on the wrong line.I never ran into a problen with it, So I never double check it. Sorry, I try not to let that happen again. I do believe I was on the right track all the same, Just the wrong car I guess. I did not intentionally try to cross ove on anybodies turf either, Just trying to help. Hey, no worries. Its just in my nature to question every line of code that I use for its purpose - I don't like to code 'blindly'. Quote
The Buzzard Posted April 5, 2010 Posted April 5, 2010 asos2000, Do not use that last code I posted. Although it does put in the styles it give you a nil reply. Here is another using a conditional although Lee's code should be better. Please note that I added a global variable in this one as well as a default: (or Dwg:Unts (setq Dwg:Unts "Meter")) (initget "Meter Millimeter") (setq Dwg:Unts (cond ((getkword (strcat "\nWhat is drawing units? [Meter/Millimeter] <"Dwg:Unts">: "))) (T Dwg:Unts))) (setq DwgUnts Dwg:Unts) (cond ((= DwgUnts "Millimeter")(command "_.-style" "EC-22-0.01" "romans.shx" 0.22 "0.8" "0" "n" "n" "n")(setvar "DIMTXT" 0.22)) ((= DwgUnts "Meter") (command "_.-style" "EC-22-100" "romans.shx" 220 "0.8" "0" "n" "n" "n")(setvar "DIMTXT" 220))) Quote
The Buzzard Posted April 5, 2010 Posted April 5, 2010 Better yet, I made this a complete stand-alone function so you can test it before you use any part of it. Load program and type UNT to start: (defun C:UNT (/ DwgUnts) (or Dwg:Unts (setq Dwg:Unts "Meter")) (initget "Meter Millimeter") (setq Dwg:Unts (cond ((getkword (strcat "\nWhat is drawing units? [Meter/Millimeter] <"Dwg:Unts">: "))) (T Dwg:Unts))) (setq DwgUnts Dwg:Unts) (cond ((= DwgUnts "Millimeter")(command "_.-style" "EC-22-0.01" "romans.shx" 0.22 "0.8" "0" "n" "n" "n")(setvar "DIMTXT" 0.22)) ((= DwgUnts "Meter") (command "_.-style" "EC-22-100" "romans.shx" 220 "0.8" "0" "n" "n" "n")(setvar "DIMTXT" 220))) (princ)) 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.