Jump to content

Recommended Posts

Posted

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.

Posted

Try this:

 

(initget 8 "Meter MMeter")

Posted

On second thought, Skip that.

Posted
Try this:

 

(initget 8 "Meter MMeter")

 

The same error

Posted

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

Posted

Why not use something like:

 

(initget "Meter" "mmEter")

Posted

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)
   )
 )
)

Posted

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)
   )
 )

Posted

Why bitcode 8?

 

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

Posted

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)))

Posted
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?

Posted
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 :)

Posted
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.

Posted

The Buzzard Works good

Lee Not working I don't know why

Posted
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'.

Posted

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)))

Posted

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))

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...