Pickpoint or Options in lisp

Discussion in 'AutoCAD' started by Chip Harper, Dec 7, 2004.

  1. Chip Harper

    Chip Harper Guest

    I am thinking this can't be done but thought I would ask anyway.

    I would like to have the user pick a point or choose optional settings
    similar to the insert command (you pick the insertion point or enter R to
    rotate, etc.) ... is this possible with lisp?

    Here is what I was trying last night but of course the getpoint always
    returns an invalid message :-(

    (defun c:OT ()
    (setq ANS nil)
    (setq VAL nil)
    (while (= ANS nil)
    (setq ANS (getpoint "Insertion Point?"))
    (if (= ANS "S")
    (prog
    (setq VAL "Other")
    (setq ANS nil)
    ); End prog
    (setq VAL "Default")
    ); End if
    ); End while
    )
     
    Chip Harper, Dec 7, 2004
    #1
  2. You get the error because you may answer with a string on the getpoint.
    Try something like this:
    (setq ANS (getstring "Default / Other / Insertion point? [ D / O / I]"))
    (cond ((= ANS "D") (do your thing here)
    ((= ANS "O") (do the other thing)
    ((= ANS "I")(setq pnt (getpoint "Insertion Point?"))
    ); end cond

    Just some wilde code, needs to be refined.
    Maybe puts you in the right direction.

    Regards,
    Jan
     
    Jan van de Poel, Dec 7, 2004
    #2
  3. Chip Harper

    Jürg Menzi Guest

    Hi Chip

    Try this:
    Code:
    ;
    ; == Function MeGetPoint
    ; Extended Getpoint function.
    ; Arguments [Type]:
    ;   Pmt = User prompt [STR]
    ;   Def = Default value [LIST/REAL/INT/STR]
    ;   Bit = Initget-bit [INT]
    ;   Stg = Keywords [STR]
    ;   Pnt = Reference point [LIST]
    ; Return [Type]:
    ;   > User input or default value [LIST]
    ;   > Keyword [STR]
    ; Notes:
    ;   None
    ;
    (defun MeGetPoint (Pmt Def Bit Stg Pnt / CurBit TmpPmt)
    (setq CurBit (if Def
    (if (and Bit (= (logand Bit 1) 1)) (1- Bit) (if Bit Bit 0))
    (if (and Bit (= (logand Bit 1) 1)) Bit 0)
    )
    )
    (if Stg (initget CurBit Stg) (initget CurBit))
    (setq TmpPmt (strcat Pmt (cond
    ((= (type Def) 'LIST)
    (strcat " <" (MeList2String Def ",") ">: ")
    )
    ((= (type Def) 'STR)
    (strcat " <" Def ">: ")
    )
    (": ")
    )
    )
    )
    (cond
    ((if Pnt (getpoint Pnt TmpPmt) (getpoint TmpPmt)))
    (Def)
    (T nil)
    )
    )
    ;
    ; == Function MeList2String
    ; Converts a list to a string.
    ; Arguments [Type]:
    ;   Lst = List [LIST]
    ;   Del = Delimiter pattern [STR]
    ; Return [Type]:
    ;   > Converted list [STR]
    ; Notes:
    ;   None
    ;
    (defun MeList2String (Lst Del)
    (apply 'strcat
    (cons
    (MeAll2String (car Lst))
    (mapcar
    '(lambda (l) (strcat Del (MeAll2String l)))
    (cdr Lst)
    )
    )
    )
    )
    ;
    ; == Function MeAll2String
    ; Converts all variable types to a string.
    ; Arguments [Type]:
    ;   Val = Value to convert [INT/REAL/LIST/STR]
    ; Return [Type]:
    ;   > Converted value [STR]
    ; Notes:
    ;   None
    ;
    (defun MeAll2String (Val)
    (cond
    ((= (type Val) 'INT ) (itoa Val))
    ((= (type Val) 'REAL) (rtos Val))
    ((= (type Val) 'LIST) (MeList2String Val " "))
    ((= (type Val) 'STR ) Val)
    (T "")
    )
    )
    
    Use:
    (setq Me:Val (MeGetPoint "\nSelect point or [Settings]" Me:Val 1 "Settings"
    nil))

    Cheers
     
    Jürg Menzi, Dec 7, 2004
    #3
  4. Chip Harper

    Chip Harper Guest

    Yep, thats what I'm using now, trying to avoid the pause for user selection
    and go straight to the pick point for default usage (80% of the time).
    Thanks.
     
    Chip Harper, Dec 7, 2004
    #4
  5. Chip Harper

    Chip Harper Guest

    Wow, thats an eyefull, I'll give it a go tonight. Thanks. :)
     
    Chip Harper, Dec 7, 2004
    #5
  6. Hi Chip,

    (getpoint) will honor keywords

    (initget "Abc Def Ghi")
    (getpoint "\n[Abc/Def/Ghi]pick a point or specify a keyword: ")
     
    Jason Piercey, Dec 7, 2004
    #6
  7. Chip Harper

    Chip Harper Guest

    Jason, You Da Man! Perfect, thanks. :)
     
    Chip Harper, Dec 7, 2004
    #7
  8. Chip Harper

    GaryDF Guest

    I've got to ask...do you dream in code?
    I can put this to use....thanks.

    Gary
     
    GaryDF, Dec 7, 2004
    #8
  9. You're welcome. Check out the help file on INITGET.
    Getstring is the only one that does not honor keywords.
     
    Jason Piercey, Dec 7, 2004
    #9
  10. Chip Harper

    Jürg Menzi Guest

    You're welcome...¦-)
    Not really... but sometimes thinking in code...;-)

    Cheers
     
    Jürg Menzi, Dec 7, 2004
    #10
  11. Chip Harper

    mmm Guest

    when you're more experienced, remember the code Jurg posted above.
    you will see that it uses the initget function as well

    note: when using initget like this:

    (initget 6 "Apples Berries Chocolate")
    (setq ANS (getpoint.....

    your cond statement has to match the format exactly ie

    (cond
    ((= ANS "Apples")
    )
    ((= ANS "Chocolate")
    )

    etc

    ((= ANS "APPLES")) won't work

    HTH


    --
    Princess Jamie,

    Life shrinks or expands in proportion to one's courage.
    - Anais Nin

    | Jason, You Da Man! Perfect, thanks. :)
    |
    | --
    |
    | Chip Harper
    | Autodesk Discussion Group Facilitator
    |
    | http://home.comcast.net/~hot4cad/
    |
    |
    |
     
    mmm, Dec 7, 2004
    #11
  12. Initget really has nothing to do with it. String
    comparisons are always case sensitive regardless
    of what stock functions are being used.
     
    Jason Piercey, Dec 7, 2004
    #12
  13. Chip Harper

    Jürg Menzi Guest

    Oops, correction:
    ; Def = Default value [LIST/STR]

    Cheers
     
    Jürg Menzi, Dec 7, 2004
    #13
  14. Chip Harper

    Jamie Duncan Guest

    the initget function breaks down the string into substrings, and searches
    for capital letters, and returns the substrings in the same format (case if
    you prefer) as you set it up in the initget statement.

    (initget "ApplE BBaby")
    (getpoint)

    will not accept B, but will accept A or BB, and returns ApplE and BBaby

    your point of watching the case for string comparisons is valid. I was
    simply pointing out that you have to be aware of how initget works.
     
    Jamie Duncan, Dec 7, 2004
    #14
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.