LISP problem

Discussion in 'AutoCAD' started by Xolo, Jun 22, 2004.

  1. Xolo

    Xolo Guest

    Hello everyone,

    Trying to write a new LISP and don't know where I've gone wrong already. Any
    help would be appreciated.

    Here's what I have so far;

    (getstring "V H")
    (setq answ (getkword "\n\nWhat type of vessel do you want to draw [V,H]:
    "))
    (cond
    ((= answ "V") (setq ang 0))
    ((= answ "H") (setq ang 90))
    )

    Running this it doesn't allow a V or an H to be entered. What is wrong with
    this?

    Thanks for the help,

    Xolo
     
    Xolo, Jun 22, 2004
    #1
  2. Xolo

    Tom Smith Guest

    You need to use initget in place of the getstring. Look it up in help.
     
    Tom Smith, Jun 22, 2004
    #2
  3. Xolo

    Xolo Guest

    Weird,

    I thought I had it right with the getstring......thanks for the info.

    Xolo

    "Tom Smith" <nospam> wrote in message You need to use initget in place of the getstring. Look it up in help.
     
    Xolo, Jun 22, 2004
    #3
  4. You can also do it without initget, by forcing their reply (whether they
    type it lowercase or uppercase) to uppercase:

    (setq answ (strcase (getkword "\n\nWhat type of vessel do you want to draw
    [V,H]: ")))
    (cond
    ((= answ "V") (setq ang 0))
    ((= answ "H") (setq ang 90))
    )

    And if you most often do it one way, you can have a default. Say you want
    Vertical to be the default:

    (setq answ (strcase (getkword "\n\nWhat type of vessel do you want to draw
    [V,H]: <V>")))
    (if (= answ "H")
    (setq ang 90)
    (setq ang 0)
    )

    which will actually set ang to 0 if they type in a V, or press Enter, or
    even anything else other than an H.

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Jun 22, 2004
    #4
  5. Xolo

    Xolo Guest

    Thanks for the insight Kent,

    Now another question, how do I set an insertion point without asking for
    user input?

    Here's what I thought was right, but it's definately not working;

    (setq insshl (getpoint (0.00,0.00)))

    Should I just drop the getpoint?

    (setq insshl 0.00,0.00)

    Ah, that doesn't work either.....how do you set a point without asking for
    user input without any other points defined?

    Xolo

    You can also do it without initget, by forcing their reply (whether they
    type it lowercase or uppercase) to uppercase:

    (setq answ (strcase (getkword "\n\nWhat type of vessel do you want to draw
    [V,H]: ")))
    (cond
    ((= answ "V") (setq ang 0))
    ((= answ "H") (setq ang 90))
    )

    And if you most often do it one way, you can have a default. Say you want
    Vertical to be the default:

    (setq answ (strcase (getkword "\n\nWhat type of vessel do you want to draw
    [V,H]: <V>")))
    (if (= answ "H")
    (setq ang 90)
    (setq ang 0)
    )

    which will actually set ang to 0 if they type in a V, or press Enter, or
    even anything else other than an H.

    Kent Cooper, AIA


    ...
     
    Xolo, Jun 22, 2004
    #5
  6. Xolo

    Tom Smith Guest

    Now another question, how do I set an insertion point without asking for
    You need to give a point as a list, either (setq insshl '(0 0)) or (setq
    insshl (list 0 0)).
     
    Tom Smith, Jun 22, 2004
    #6
  7. Xolo

    Xolo Guest

    Tom,

    Thanks again.....this stuff is harder than I though.

    Xolo

    You need to give a point as a list, either (setq insshl '(0 0)) or (setq
    insshl (list 0 0)).
     
    Xolo, Jun 22, 2004
    #7
  8. <soapbox>

    Although Kent is technically correct in his approach, it leaves something to
    be desired from an end-user perspective. Does it not make sense to be
    descriptive with the options, so that there is less possible confusion for
    the end user? Wouldn't you wish the command options to act like all AutoCAD
    standard command options with the right-click menu? Shouldn't you indicate a
    default option?

    (initget "Horizontal Vertical")
    (setq inp (getkword "\nWhat type of vessel? [Horizontal/Vertical]
    <Vertical>: ")
    ang (cond ((= inp "Horizontal") 90) (0)))

    </soapbox>

    --
    R. Robert Bell


    You can also do it without initget, by forcing their reply (whether they
    type it lowercase or uppercase) to uppercase:

    (setq answ (strcase (getkword "\n\nWhat type of vessel do you want to draw
    [V,H]: ")))
    (cond
    ((= answ "V") (setq ang 0))
    ((= answ "H") (setq ang 90))
    )

    And if you most often do it one way, you can have a default. Say you want
    Vertical to be the default:

    (setq answ (strcase (getkword "\n\nWhat type of vessel do you want to draw
    [V,H]: <V>")))
    (if (= answ "H")
    (setq ang 90)
    (setq ang 0)
    )

    which will actually set ang to 0 if they type in a V, or press Enter, or
    even anything else other than an H.

    Kent Cooper, AIA


    ...
     
    R. Robert Bell, Jun 22, 2004
    #8
  9. Xolo

    Tom Smith Guest

    Agreed. In his second example, he was providing a default, but any keypress
    whatsoever other than the non-default answer of the two choices would return
    the default. This isn't a good solution, and couldn't work if there were
    more than two choices possible. It's a good (negative) illustration of why
    initget matters for keywords.
     
    Tom Smith, Jun 22, 2004
    #9
  10. Xolo

    Tom Smith Guest

    Thanks again.....this stuff is harder than I though.

    Hang in there, it takes a while :)
     
    Tom Smith, Jun 22, 2004
    #10
  11. Xolo

    Xolo Guest

    Hey, thanks for the extra information....it's always good to know the
    "better" way to LISP.

    another problem I've come across while writting my horrible code is in this
    tidbit;

    (setq shlout1 (polar insshl (DTR (+ shlang 90)) (/ OD 2)))

    For some reason it will not comlete the DTR function which is called up at
    the beginning of my LISP like this;

    (defun DTR (deg) (* pi (/ deg 180.0)))

    Which I have been using for quite a while now. I just can't figure out why
    it's not letting this run correctly. More expertise is required.

    Thanks

    Xolo
    "Tom Smith" <nospam> wrote in message Agreed. In his second example, he was providing a default, but any keypress
    whatsoever other than the non-default answer of the two choices would return
    the default. This isn't a good solution, and couldn't work if there were
    more than two choices possible. It's a good (negative) illustration of why
    initget matters for keywords.
     
    Xolo, Jun 22, 2004
    #11
  12. Xolo

    ECCAD Guest

    I been at it since 1985. Still don't know much.

    Bob

    :))
     
    ECCAD, Jun 22, 2004
    #12
  13. Xolo

    Xolo Guest

    Actually the LISP didn't stop there, but one line earlier at this section;

    (setq shlend (polar insshl (DTR shlang) shlss))

    for some reason it's not able to read what shlang is. Do I need to convert
    it to a number?

    Thanks

    Xolo

    Hey, thanks for the extra information....it's always good to know the
    "better" way to LISP.

    another problem I've come across while writting my horrible code is in this
    tidbit;

    (setq shlout1 (polar insshl (DTR (+ shlang 90)) (/ OD 2)))

    For some reason it will not comlete the DTR function which is called up at
    the beginning of my LISP like this;

    (defun DTR (deg) (* pi (/ deg 180.0)))

    Which I have been using for quite a while now. I just can't figure out why
    it's not letting this run correctly. More expertise is required.

    Thanks

    Xolo
    "Tom Smith" <nospam> wrote in message Agreed. In his second example, he was providing a default, but any keypress
    whatsoever other than the non-default answer of the two choices would return
    the default. This isn't a good solution, and couldn't work if there were
    more than two choices possible. It's a good (negative) illustration of why
    initget matters for keywords.
     
    Xolo, Jun 22, 2004
    #13
  14. Xolo

    Xolo Guest

    ECCAD,

    Thanks for the vote of confidence that I got from your reply.....how long
    does it take to learn a LOT? I'm impatient!!!

    Xolo

    I been at it since 1985. Still don't know much.

    Bob

    :))
     
    Xolo, Jun 22, 2004
    #14
  15. Your (dtr) function requires a number, so if shlang is not a REAL or INT,
    yes.

    --
    R. Robert Bell


    Actually the LISP didn't stop there, but one line earlier at this section;

    (setq shlend (polar insshl (DTR shlang) shlss))

    for some reason it's not able to read what shlang is. Do I need to convert
    it to a number?

    Thanks

    Xolo

    Hey, thanks for the extra information....it's always good to know the
    "better" way to LISP.

    another problem I've come across while writting my horrible code is in this
    tidbit;

    (setq shlout1 (polar insshl (DTR (+ shlang 90)) (/ OD 2)))

    For some reason it will not comlete the DTR function which is called up at
    the beginning of my LISP like this;

    (defun DTR (deg) (* pi (/ deg 180.0)))

    Which I have been using for quite a while now. I just can't figure out why
    it's not letting this run correctly. More expertise is required.

    Thanks

    Xolo
    "Tom Smith" <nospam> wrote in message Agreed. In his second example, he was providing a default, but any keypress
    whatsoever other than the non-default answer of the two choices would return
    the default. This isn't a good solution, and couldn't work if there were
    more than two choices possible. It's a good (negative) illustration of why
    initget matters for keywords.
     
    R. Robert Bell, Jun 22, 2004
    #15
  16. Xolo

    ECCAD Guest

    A LOT.
    :)
     
    ECCAD, Jun 22, 2004
    #16
  17. Xolo

    ECCAD Guest

    Really though, it doesn't take all that long, typically you can learn the basics in a week or two..then delve into the harder stuff as you gain confidence. Hang in there. !

    Bob
     
    ECCAD, Jun 22, 2004
    #17
  18. Xolo

    ECCAD Guest

    What have you set into shlang ? (as far as type of data).
    Is it a number, number of 'radians' or what ?

    Bob
     
    ECCAD, Jun 22, 2004
    #18
  19. Xolo

    Xolo Guest

    Robert,

    shlang was defined earlier by this code;

    (initget "V H")
    (setq answ (getkword
    "\n\nWhat type of vessel do you want to draw [V,H]: "))
    (cond
    ((= answ "V") (setq shlang 0))
    ((= answ "H") (setq shlang 90)))

    So it's either set to 0 or 90. I'm just trying to define the two end points
    of the vessel. The first one is always going to be at 0,0

    (setq insshl '(0.00,0.00))

    and the second one is at a user input distance at an angle defined by what
    type of vessel it is.

    (setq shlend (polar insshl (DTR shlang) shlss))

    However, for some reason the (DTR shlang) is where the animated debugging
    stopped at. I have no idea why it stopped there. It doesn't make sense to me
    why it would and I can't figure it out.....plus I'm trying to do whatever
    work that needs getting done while I'm doing this, so my attention isn't
    fully on this.

    Thanks for the help,

    Xolo

    Your (dtr) function requires a number, so if shlang is not a REAL or INT,
    yes.

    --
    R. Robert Bell


    Actually the LISP didn't stop there, but one line earlier at this section;

    (setq shlend (polar insshl (DTR shlang) shlss))

    for some reason it's not able to read what shlang is. Do I need to convert
    it to a number?

    Thanks

    Xolo

    Hey, thanks for the extra information....it's always good to know the
    "better" way to LISP.

    another problem I've come across while writting my horrible code is in this
    tidbit;

    (setq shlout1 (polar insshl (DTR (+ shlang 90)) (/ OD 2)))

    For some reason it will not comlete the DTR function which is called up at
    the beginning of my LISP like this;

    (defun DTR (deg) (* pi (/ deg 180.0)))

    Which I have been using for quite a while now. I just can't figure out why
    it's not letting this run correctly. More expertise is required.

    Thanks

    Xolo
    "Tom Smith" <nospam> wrote in message Agreed. In his second example, he was providing a default, but any keypress
    whatsoever other than the non-default answer of the two choices would return
    the default. This isn't a good solution, and couldn't work if there were
    more than two choices possible. It's a good (negative) illustration of why
    initget matters for keywords.
     
    Xolo, Jun 22, 2004
    #19
  20. Xolo

    Tom Smith Guest

    (setq shlend (polar insshl (DTR shlang) shlss))
    Yes, the dtr function expects a number representing an angle in degrees. If
    you look at that function, it's dividing the deg vaiable by 180 and then
    multiplying it by pi.

    As with any programming languages, you must always be conscious of the
    "type" of a variable -- string, integer, real number, or whatever.
     
    Tom Smith, Jun 22, 2004
    #20
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.