User input = enter

Discussion in 'AutoCAD' started by Adesu, Oct 12, 2004.

  1. Adesu

    Adesu Guest

    How to completed user input if user only hit enter

    ; eh is stand for edit hatch
    ; Design by Ade Suharna <>
    ; 5 October 2004
    ; Program no.102/10/2004
    (defun c:eh (/ ent info2 info41 info52 inp1 ans1 inp2 ans2 inp3 ans3 ed)
    (while
    (setq ent (entget (car (entsel))))
    (setq info2 (cdr (assoc 2 ent)))
    (setq info41 (rtos (cdr (assoc 41 ent))))
    (setq info52 (rtos (cdr (assoc 52 ent))))
    (setq inp1
    (getstring
    (strcat "\nENTER NEW NAME OF HATCH PATTERN" "<" info2 ">" ": ")))
    (setq ans1 (getstring " ")) ; >>>>>> ????
    (if (eq inp2 ans1)(setq inp2 info41)) ; >>>>>> ????
    (setq inp2
    (getreal
    (strcat "\nENTER NEW SCALE OF HATCH" "<" info41 ">" ": ")))
    (setq ans2 (getstring " ")) ; >>>>>> ????
    (if (eq inp2 ans2)(setq inp2 info41)) ; >>>>>> ????
    (setq inp3
    (getreal
    (strcat "\nENTER NEW ANGLE OF HATCH" "<" info52 ">" ": ")))
    (setq ans3 (getstring " ")) ; >>>>>> ????
    (if (eq inp3 ans3)(setq inp3 info52)) ; >>>>>> ????
    (setq ed1 (subst (cons 2 inp1)(assoc 2 ent) ent))
    (setq ed2 (subst (cons 41 inp2)(assoc 41 ent) ed1))
    (setq ed3 (subst (cons 52 inp3)(assoc 52 ent) ed2))
    (entmod ed3)
    )
    )
     
    Adesu, Oct 12, 2004
    #1
  2. ;* USTR
    ;* BIT=1 no null "" user input alloved, 0 for none, BIT ignored
    ;* if DEF present. MSG is the prompt string, to which a default
    ;* string is added as <DEF> (nil o "" for none), and a : is added.
    ;* If SPFLAG T (True), spaced are allowed in string.
    ;*
    (defun ustr (bit msg def spflag / inp nval)
    (if (and def (/= def ""))
    (setq
    msg (strcat "\n" msg " <" def ">: ")
    inp (getstring msg spflag)
    inp (if (= inp "") def inp)
    )
    (progn
    (setq msg (strcat "\n" msg ": "))
    (if (= bit 1)
    (while (= "" (setq inp (getstring msg spflag))))
    (setq inp (getstring msg spflag))
    ) )
    )
    inp
    )
    ;
    ;* UREAL
    ;* BIT (0 for none) e KWD key word ("" for none) are the same as
    ;* for INITGET. MSG is the prompt string, to which a default
    ;* real is added as <DEF> (nil for none), and a : is added.
    ;*
    (defun ureal (bit kwd msg def / inp)
    (if def
    (setq
    msg (strcat "\n" msg " <" (ALE_RTOS_DZ8 def) ">: ")
    bit (* 2 (fix (/ bit 2)))
    )
    (setq msg (strcat "\n" msg ": "))
    )
    (initget bit kwd)
    (setq inp (getreal msg))
    (if inp inp def)
    )
    ;
    (defun ALE_RtoS_DZ8 (ReaVal / CurDZn OutVal)
    (if (= 8 (setq CurDZn (getvar "DIMZIN")))
    (setq CurDZn nil)
    (setvar "DIMZIN" 8)
    )
    (setq OutVal (rtos ReaVal 2))
    (and CurDZn (setvar "DIMZIN" CurDZn))
    OutVal
    )


    --

    Marc'Antonio Alessi
    http://xoomer.virgilio.it/alessi
    (strcat "NOT a " (substr (ver) 8 4) " guru.")

    --
     
    Marc'Antonio Alessi, Oct 12, 2004
    #2
  3. here is another method -
    (while (= "" (setq inp1 (getstring (strcat "\nENTER NEW NAME OF HATCH
    PATTERN" "<" info2 ">" ": ")))))

    also, you might want to create a list of valid hatch pattern names to check
    example -
    (setq ListHatch (list "ansi31" "ansi32" "solid"))
    (while (or
    (= "" (setq inp1 (getstring (strcat "\nENTER NEW NAME OF HATCH PATTERN"
    "<" info2 ">" ": ")))))
    (not (member inp1 ListHatch)))
    )

    also, check for valid input on scale and rotation values
     
    Alan Henderson @ A'cad Solutions, Oct 12, 2004
    #3
  4. Adesu

    James Allen Guest

    Hi Ade.

    These values should work:
    (setq ans1 "" ans2 nil ans3 nil)

    Once you do that you can do it without the variables, like
    (setq str1 (getstring (strcat "\nEnter String <" sinfo1 ">: ")))
    (if (eq str1 "") (setq str1 sinfo1))
    (setq rea1 (getreal (strcat "\nEnter String <" rinfo1 ">: ")))
    (if (eq rea1 nil) (setq rea1 rinfo1))

    or
    (setq str1 (getstring (strcat "\nEnter String <" sinfo1 ">: "))
    str1 (if (eq str1 "") sinfo1 str1)
    rea1 (getreal (strcat "\nEnter String <" rinfo1 ">: "))
    rea1 (if (not rea1) rinfo1 rea1)
    )
     
    James Allen, Oct 12, 2004
    #4
  5. Adesu

    Adesu Guest

    Hi James ,thanks a lot as your advice,here my code become below

    eh is stand for edit hatch
    ; Design by Ade Suharna <>
    ; 5 October 2004
    ; Program no.102/10/2004
    ; Edit by James Allen <JamesA~AA~mwengrs~DD~com> 12/10/2004 1).
    (defun c:eh (/ ent info2 info41 info52 inp1 inp2 inp3 ed)
    (while
    (setq ent (entget (car (entsel))))
    (setq info2 (cdr (assoc 2 ent)))
    (setq info41 (rtos (cdr (assoc 41 ent))))
    (setq info52 (rtos (cdr (assoc 52 ent))))
    (setq inp1
    (getstring
    (strcat "\nENTER NEW NAME OF HATCH PATTERN" "<" info2 ">" ": ")))
    (if (eq inp1 "")(setq inp1 info2))
    ; 1).
    (setq inp2
    (getreal
    (strcat "\nENTER NEW SCALE OF HATCH" "<" info41 ">" ": ")))
    (if (eq inp2 nil)(setq inp2 (atoi info41)))
    ; 1).
    (setq inp3
    (getreal
    (strcat "\nENTER NEW ANGLE OF HATCH" "<" info52 ">" ": ")))
    (if (eq inp3 nil)(setq inp3 (atoi info52)))
    ; 1).
    (setq ed1 (subst (cons 2 inp1)(assoc 2 ent) ent))
    (setq ed2 (subst (cons 41 inp2)(assoc 41 ent) ed1))
    (setq ed3 (subst (cons 52 inp3)(assoc 52 ent) ed2))
    (entmod ed3)
    )
    )
     
    Adesu, Oct 12, 2004
    #5
  6. Adesu

    Tom Smith Guest

    I commend you on your code. One small point: I find it easier to read and
    maintain code if the variables are given more meaningful names. This is
    important when you need to go back after a year or two to modify the
    program. For instance, I would prefer something like:

    (setq
    hp-name (cdr (assoc 2 ent))
    hp-scale (rtos (cdr (assoc 41 ent)))
    hp-angle (rtos (cdr (assoc 52 ent))))

    Likewise I would suggest names such as new-hp-name and new-hp-scale rather
    than inp1 and inp2. Variable names can help you understand the program more
    easily if they are chosen carefully.

    Also, if you prefer, you can nest the subst operations and eliminate two
    temporary variables:

    (entmod
    (subst (cons 2 new-hp-name) (assoc 2 edata)
    (subst (cons 41 new-hp-scale) (assoc 41 edata)
    (subst (cons 52 new-hp-angle) (assoc 52 edata) edata)))))
     
    Tom Smith, Oct 12, 2004
    #6
  7. Adesu

    Adesu Guest

    HI Tom,I like that your advice and good input for me,and thanks a lot.
     
    Adesu, Oct 13, 2004
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.