Handling Arbitrary Keywords

Discussion in 'AutoCAD' started by Jason Piercey, Feb 4, 2004.

  1. How are you handling generating keywords from an
    arbitrary comma delimited string to use with (initget)
    and (getkword) ? Do you suppose it is 'good enough'
    to just capitalize the first character, forcing the user to
    type out additional characters if any duplicate are used?

    Thinking about writing such a function just not sure if it is
    worth the time, as I can't see a clear solution in my head
    at the moment. On the other hand I'd rather not have to
    deal with duplicates, sort of defeats the purpose of a
    keyword, eh? < thinking out loud >
     
    Jason Piercey, Feb 4, 2004
    #1
  2. Jason Piercey

    Paul Turvill Guest

    The usual method is to capitalize a different character (not necessarily the
    first one) for each selection; if the words are *very* similar, you can
    capitalize two or more characters, to require that number of characters from
    the user.
    ___
     
    Paul Turvill, Feb 4, 2004
    #2
  3. That is what I would do if I were creating the keywords
    manually. In this case the keywords are taken from an
    alternate source (stored data from the user) which means
    I have to find a way to parse the strings and determine
    which characters are unique to each string then 'reformat'
    them so they work properly.

    I started to work on this a last night, but got a little side
    tracked. It'll be back to the drawing board again this
    evening.

    Thanks for the response.
     
    Jason Piercey, Feb 4, 2004
    #3
  4. Jason,

    This might be cutting corners, but could you strcat "1-" "string1"
    and "2-" "string2" or something like that.


    --
    Ken Alexander
    Acad2004
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Feb 4, 2004
    #4
  5. Jason Piercey

    Paul Turvill Guest

    If they're not excessively long keywords, I suppose you could simply process
    them to ALL CAPS with (strcase), and force the user to type the entire
    keyword ...
    ___
     
    Paul Turvill, Feb 4, 2004
    #5
  6. Jason Piercey

    BillZ Guest

    This may be the ramblings of a madman but try it and see if it gives you any ideas.
    You'll have to figure out a way to capitalize the letters in the word that you want.

    Bill

    (defun List_Keywords ()

    (setq lt (list "arbor" "annual" "cat" "dog" "animal" "dug" "well" "aqua" "worm" "canoe" "wiggle" "dumb" "cut" "awful" "diggy" "what" "cot")
    ltt (acad_strlsort lt)
    )

    (setq cnt 0 ;outside most loop first.
    )
    (while (> (length ltt) 0) ;get lists of same starting letters.
    (setq ent (nth 0 ltt)
    l1 nil
    l1 (cons ent l1)
    ltt (cdr ltt)
    ) ;end setq
    (while (and (car ltt)
    (= (substr ent 1 1)(substr (car ltt) 1 1))
    )
    (setq l1 (cons (car ltt) l1) ;point list of each pline.
    ltt (cdr ltt)
    )
    ) ;end second while
    (setq l1 (reverse l1)
    plnt (cons (set (read (strcat (strcase (substr ent 1 1)) "_list")) l1) plnt) ;list of lists.
    slst (cons (strcat (strcase (substr ent 1 1)) "_list") slst) ;list of names list.
    cnt (1+ cnt)
    )
    ) ;end while
    (setq plnt (reverse plnt)
    slst (reverse slst)
    )
    ) ;end defun
     
    BillZ, Feb 4, 2004
    #6
  7. Thanks for the idea, Ken. However, I don't think that
    will suite this particular situation very well.
     
    Jason Piercey, Feb 4, 2004
    #7
  8. They could be long,short, or anywhere in between.
    I'll see what type of things I can cook up after while.
     
    Jason Piercey, Feb 4, 2004
    #8
  9. Bill,

    I'll have a look at this a bit later (too much work right now).
    Thanks for your ideas.
     
    Jason Piercey, Feb 4, 2004
    #9
  10. Jason Piercey

    BillZ Guest

    If I get a chance I'll look at this some more also. :)


    Bill
     
    BillZ, Feb 4, 2004
    #10
  11. Jason Piercey

    Devin Guest

    Jason,

    I've devloped a real nice routine. It basically takes the text supplied to
    my own ggetxxx functions and searches them for keywords. I no longer have
    to do any initget function calls as it's all done automatically. I format
    like this (ggetxxx 'var "User prompt select pt or [Kword1/Kword2]"). It
    automatically searches the prompt for the keyword and applies the initget
    with the extracted kewords. It also performs another function. It checks
    'var for a value and suggests it as a default if found not null, ie: "User
    prompt select pt or [Kword1/Kword2]<(default from 'var)>: "

    It saves me alot of trouble and time.

    Maybe or maybe not helpful?

    Devin
     
    Devin, Feb 4, 2004
    #11
  12. Devin,

    This situation is a bit different than what you described.

    Take something like this as an example.

    ; get a list of arbitrary strings (just an example)
    ; modify case as required

    (vl-registry-descendents
    (strcat
    "HKEY_CURRENT_USER\\"
    (vlax-product-key)
    )
    )

    With that return value, parse the strings and find the
    unique characters within each string that will be
    capitalized to work as a shortcut for a keyword.

    I wrote a strcaseNth function, that was the easy part :)
    Finding the nth(s) is the hard part (so far anyway). I'm
    thinking vl-string-mismatch is a good start. Back to the
    drawing board.

    Hope that helps explain the situation a little better.
     
    Jason Piercey, Feb 5, 2004
    #12
  13. Think I have something that works, I'll post
    when I get it all "polished up". Probably
    tomorrow.
     
    Jason Piercey, Feb 5, 2004
    #13
  14. Alrighty, here we are. Give this a whirl and see how
    it works for ya. I tested it for a while seemed to have
    reasonable return values to me.

    (getKeywords
    '("webservices" "settings" "profiles"
    "mtext" "minidump" "ism" "fixedprofile"
    "filenavextensions" "express" "dragdropformats"
    "dbview" "autodeskapps" "applications"))

    returns:
    ("Webservices" "Settings" "Profiles"
    "Mtext" "mInidump" "ISM" "Fixedprofile"
    "fiLenavextensions" "Express" "Dragdropformats"
    "dBview" "Autodeskapps" "appliCations")


    ; Jason Piercey . February 6th, 2004
    ; function to format a list of strings to
    ; be used as keywords for iniget/getkword
    ; Arguments:
    ; [strings] - list of strings
    ; return: list of strings
    ; Example:
    ; (getKeywords '("abc" "abc" "abc")) -> ("Abc" "aBc" "abC")
    ; (getKeywords '("jb" "jf" "jhjghj"))-> ("Jb" "jF" "jHjghj")
    (defun getKeywords (strings / i l next keys lst)
    (setq strings (mapcar (function (lambda (x) (strcase x t))) strings))
    (foreach item strings
    (setq i 1)
    (setq l (strlen item))

    (while (<= i l)
    (setq next (substr item i 1))

    (cond
    ((not (vl-position next keys))
    (setq keys (cons next keys))
    (setq lst (cons (strcaseNth item (1- i) nil) lst))
    (setq i (1+ l)) )

    ((= i l)
    (setq keys (cons item keys))
    (setq lst (cons (strcase item) lst))
    (setq i (1+ i)) )

    ((vl-position next keys) (setq i (1+ i)))
    )

    )
    )
    (reverse lst)
    )


    ; Jason Piercey . February 6th 2004
    ; function to strcase the nth element of a string
    ; Arguments:
    ; {string] - string, string to modify
    ; [position] - integer, nth element
    ; [which] - Re: strcase function, NOT an optional argument
    ; return: string if successful
    (defun strcaseNth (string position which)
    (cond
    ((zerop position)
    (strcat
    (strcase (substr string 1 1) which)
    (substr string 2 (strlen string))) )

    ((< position (strlen string))
    (strcat
    (substr string 1 position)
    (strcase (substr string (1+ position) 1) which)
    (substr string (+ 2 position) (strlen string))) )

    (t nil)
    )
    )
     
    Jason Piercey, Feb 7, 2004
    #14
  15. Pretty slick Jason.

    I'm real curious as to a project that would need something like
    this. I have a few routines that use different keyword lists even one
    that uses nine different.
    However, all are definable within the routine.

    Just being Nosey I guess.

    --
    Ken Alexander
    Acad2004
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein

     
    Ken Alexander, Feb 9, 2004
    #15
  16. Hi Ken,

    I am writing this routine (isn't that how it always starts <g>)
    for autolayering standard stuff (notes, dimensions, hatch, etc)
    allowing the user to create a named group of commands and
    associate a layer with each named group.

    I've got several user prompts that allow adding of groups,
    adding commands to a group, removing groups, etc.....
    Well, rather than leave the user typing blind and trap the
    input, check what what typed against what is defined, I
    thought it would be nice to display the available choices
    in a getkword fashion.

    Since the groups are created from the user, I have no idea
    what they are called, so I needed a way to grab the group
    names from the registry then format them for prompting on
    the fly.

    Does that clear things up?
     
    Jason Piercey, Feb 9, 2004
    #16
  17. Jason Piercey

    BillZ Guest

    Thanks Jason,
    I'll copy this for trial on a later date.

    Bill
     
    BillZ, Feb 9, 2004
    #17
  18. You're welcome, Bill.

    Hope you find it useful some day.
     
    Jason Piercey, Feb 9, 2004
    #18
  19. Jason,

    Yup....clears it up. Your functions have given me some ideas on a
    function I am working on. A 'complete' string sorter. Seem to run
    into roadblock each direction. I think I'm making it too difficult.
    Keep plungin away.

    Thanks for sharing the functions.


    --
    Ken Alexander
    Acad2004
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Feb 9, 2004
    #19
  20. I seem to have a knack for making things more difficult
    than what they need to be also, you are not alone :)
    and you are welcome.
     
    Jason Piercey, Feb 9, 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.