PDA

View Full Version : whats wrong with this code?



asos2000
5th Apr 2010, 04:50 pm
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.

The Buzzard
5th Apr 2010, 05:04 pm
Try this:


(initget 8 "Meter MMeter")

The Buzzard
5th Apr 2010, 05:22 pm
On second thought, Skip that.

asos2000
5th Apr 2010, 05:22 pm
Try this:


(initget 8 "Meter MMeter")

The same error

The Buzzard
5th Apr 2010, 05:31 pm
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

Lee Mac
5th Apr 2010, 05:47 pm
Why not use something like:



(initget "Meter" "mmEter")

The Buzzard
5th Apr 2010, 05:53 pm
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)
)
)
)

The Buzzard
5th Apr 2010, 06:10 pm
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)
)
)

Lee Mac
5th Apr 2010, 06:17 pm
Why bitcode 8?

Also, the double IF statement would cause the choice to fail if the user hit enter (causing getkword to return nil).

Lee Mac
5th Apr 2010, 06:20 pm
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)))

The Buzzard
5th Apr 2010, 06:21 pm
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?

Lee Mac
5th Apr 2010, 06:57 pm
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 :)

The Buzzard
5th Apr 2010, 07:13 pm
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.

asos2000
5th Apr 2010, 07:16 pm
The Buzzard Works good
Lee Not working I don't know why

Lee Mac
5th Apr 2010, 08:18 pm
The Buzzard Works good
Lee 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'.

The Buzzard
5th Apr 2010, 09:11 pm
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)))

The Buzzard
5th Apr 2010, 09:16 pm
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))