been too long - need a little refresher on easy code

Discussion in 'AutoCAD' started by wundrlik, Jun 30, 2004.

  1. wundrlik

    wundrlik Guest

    ok - all I need this to do is put a "0" (zero) if the enter is pushed with no input. Here's the string that I have -

    text_angle (* (/ 180 pi)(getangle "Enter angle: " text_insert))

    Thanks for your help.

    Ryan
     
    wundrlik, Jun 30, 2004
    #1
  2. wundrlik

    T.Willey Guest

    (if (not text_angle)
    (setq text_angle "0")
    )

    Tim
     
    T.Willey, Jun 30, 2004
    #2
  3. wundrlik

    wundrlik Guest

    not quite -

    Here's the complete code - I didn't define text_angle

    (setq sav_lyr(getvar "clayer"))
    (setq layer_new(layer_make layer_typ)
    text_height(* 0.1 idc#dwgsc)
    text_insert(getpoint "Select text insertion Point:\n")
    text_angle (* (/ 180 pi)(getangle "Enter angle: " text_insert))
    text_string(getstring T "Enter text: ")
     
    wundrlik, Jun 30, 2004
    #3
  4. wundrlik

    C Witt Guest

    (if (= (setq t (getangle "Enter angle: ")) nil)(* 0 0)(* (/ 180 pi) t
    text_insert))

    ?
     
    C Witt, Jun 30, 2004
    #4
  5. wundrlik

    T.Willey Guest

    The way it's written you will error out if enter is hit with
    text_insert(getpoint "Select text insertion Point:\n")
    and
    text_angle (* (/ 180 pi)(getangle "Enter angle: " text_insert))

    Why don't you just stop the "setq" after you get "text_insert" and then test for it.
    (if text_insert
    (setq text_angle (getangle "Enter angle:" text_insert))
    (if text_angle
    (setq text_angle (* (/ 180 pi) text_angle))
    (setq text_angle "0")
    )
    )

    That is how I would do it.

    Tim
     
    T.Willey, Jun 30, 2004
    #5
  6. wundrlik

    C Witt Guest

    rather..

    (if (= (setq t (getangle "Enter angle: ")) nil)(* 0 0)(* (/ 180
    pi)(getangle t text_insert)))

    I think..
     
    C Witt, Jun 30, 2004
    #6
  7. wundrlik

    C Witt Guest

    damn.. wrong again..

    (if (= (setq t (getangle "Enter angle: ")) nil)(* (/ 180 pi) (getangle 0
    text_insert))(* (/ 180 pi)(getangle t text_insert)))


    err.. yea
     
    C Witt, Jun 30, 2004
    #7
  8. wundrlik

    ECCAD Guest

    Tim,
    Doesn't the angle have to be a number ?
    (setq text_angle 0)

    Bob
     
    ECCAD, Jun 30, 2004
    #8
  9. wundrlik

    T.Willey Guest

    I thought so, but the post'er had quotes around it, so I put quotes. Thanks for making that clear Bob.

    Tim
     
    T.Willey, Jun 30, 2004
    #9
  10. How about:

    (if (= text_angle nil) (setq text_angle 0))

    Doesn't look a whole lot different from Tim's, except it checks for an
    entered value a little differently, AND I think his, with the "0" in quotes,
    would set it as a text string rather than a numerical value.

    Kent Cooper, AIA
     
    Kent Cooper, AIA, Jun 30, 2004
    #10
  11. wundrlik

    Phil Guest

    don't know about rest of post but should use something besides t for
    variable
     
    Phil, Jul 1, 2004
    #11
  12. wundrlik

    Phil Guest

    I use a nz code , nullToZero

    (defun nz ( x) (if (null x)0 x))

    text_angle (* (/ 180 pi)(nz(getangle "Enter angle: " text_insert)))
     
    Phil, Jul 1, 2004
    #12
  13. wundrlik

    Doug Barr Guest

    Another approach... not totally convinced it's different than what others have
    offered, but it's the way I've been accepting <RET> for the displayed default
    value. If there's a better way, someone please tell me!
    -doug

    (princ "\nEnter angle:<0.0> ")
    (setq enter-angle (getstring))
    (if (= enter-angle "")
    (setq enter-angle 0.0)
    (setq enter-angle (atof enter-angle))
    )
    (setq text_angle (* (/ 180 pi)(enter-angle)))

    input. Here's the string that I have -
     
    Doug Barr, Jul 1, 2004
    #13
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.