Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Dynamic User Input with Getstring List?

  1. #1
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Question Dynamic User Input with Getstring List?

    Good Morning!

    Is there a way to use a list as options for a Getstring command?

    I'd like to have a set of default options with the ability for the user to add a new option, then this new option is included in the list for the next time the command is used. Possible?

    Something maybe kinda like this (except working, lol)?

    Code:
      (setq OptLst (list
    		 "PNL"
    		 "CAB"
    		 "DSK"
    		 "CLT"
    		 "TFS"
    		 "STD"
    		 "SGN"
    		 "DOR"
    		 "CLG"
    		 "FAS"
    		 "PST"
    		 "SUP"
    		 )
    	)
    
    
    (initget OptLst)
      
    (setq *ans*
           (cond
    	 (
    	  (getstring
    	    (strcat "\nChoose [" OptLst "] <"
    		    (setq *ans*
    			   (cond (*ans*)
    				 (car OptLst)
    			   )
    		    )
    		    ">: "
    	    )
    	  )
    	 )
    	 (*ans*)
           )
    )
    
    
    (setq OptLst (cons *ans* OptLst))
    Cheers

    -stu

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Dynamic User Input with Getstring List?

    Consider INITGET + GETKWORD:

    Code:
    (defun c:FOO (/ x)
      (initget "Yes No" 128)
      (if (setq x (getkword "\nEnter an option [Yes/No]: "))
        (print x)
      )
      (princ)
    )

    Example:

    Code:
    Command: FOO
    Enter an option [Yes/No]: y
    "Yes"
    Command:
    Command: FOO
    Enter an option [Yes/No]: n
    "No"
    Command: FOO
    Enter an option [Yes/No]: perhaps
    "perhaps"
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Dynamic User Input with Getstring List?

    I can do that, but I think I could get inconsistent strings. For example, if a user needs to abbreviate "closet", they could use a variety of 3-letter abbreviations ("CLO", "CLS", "CLT", etc.). I don't mind them creating a new abbreviation (it's almost required with the varirety of our projects), but once an abbreviation has been created, it needs to remain consistent so that you can have "CLO-1" and "CLO-2", not "CLO-1" and "CLS-1".

    Definitely need to use the initget with a bitcode, but is there a way to specify the options using a list? Like have autolisp read a list like a string?

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Dynamic User Input with Getstring List?

    Not really. You would need to combine the strings from the list into one string separated with spaces. You could then supply that combined string into your initget call.

    Here is a subroutine to combine a list of strings into one string
    Code:
    (defun _implode ( data delim / str n )
      ;; Join list items into string with delimiter string
      (if (and (= (type data) 'LIST)
    	   (= (type delim) 'STR)
    	   (> (strlen delim) 0)
          )
        (foreach n data
          (if str
    	(setq str (strcat str delim n))
    	(setq str n)
    	)
          )
        )
      )
    I'm not certain where I found this code, but I know CAB did one to split a string into a list based on a delimiter. This just goes the other direction.
    Last edited by Opie; 2016-01-13 at 10:33 PM.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Dynamic User Input with Getstring List?

    You can either allow arbitrary input, and filter the user's non-Nil value against a qualified list, or provide them all options from the outset.

    I do this in one of my routines; have a single list of options, and use string concatenation to supply said list to both Initget, and Getkword. I've posted an example somewhere, but am not at a computer at the moment.

    [Edit] - Give this code a look-see:
    http://forums.augi.com/showthread.ph...=1#post1153163



    Cheers

    [Edit] - I have a Parser sub-Function here:
    http://forums.augi.com/showthread.ph...=1#post1275218
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  6. #6
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Dynamic User Input with Getstring List?

    Quote Originally Posted by Opie View Post
    Not really. You would need to combine the strings from the list into one string separated with spaces. You could then supply that combined string into your initget call.

    Here is a subroutine to combine a list of strings into one string
    Code:
    (defun...
    Well that just saved me a bunch of time. I figured I'd need to combine my list into one big string (one with spaces for initget and one with "\" for the getkword call).

    Quote Originally Posted by BlackBox View Post
    You can either allow arbitrary input, and filter the user's non-Nil value against a qualified list, or provide them all options from the outset.

    I do this in one of my routines; have a single list of options, and use string concatenation to supply said list to both Initget, and Getkword. I've posted an example somewhere, but am not at a computer at the moment.

    [Edit] - Give this code a look-see:
    http://forums.augi.com/showthread.ph...=1#post1153163



    Cheers

    [Edit] - I have a Parser sub-Function here:
    http://forums.augi.com/showthread.ph...=1#post1275218
    That my friend is good stuff. I thought it could be done, but I guess my google-fu is off today.

    Thanks a heap fellas! I'm going to look this over and crush it.

  7. #7
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Dynamic User Input with Getstring List?

    You guys are awesome. I'll through in there a bit to see if *ans* already exists, if not add it to OptLst.

    Thanks fellas.

    Code:
        (setq OptLst (list
    		 "PNL"
    		 "CAB"
    		 "DSK"
    		 "CLT"
    		 "TFS"
    		 "STD"
    		 "SGN"
    		 "DOR"
    		 "CLG"
    		 "FAS"
    		 "PST"
    		 "SUP"
    		 "MIS"
    		 )
    	)
    
    (setq OptStr (_implode OptLst " "))
    
    (initget OptStr 128)
    
    (if (setq *ans*	(getkword (strcat "\nEnter an option ["
    			  (vl-string-translate " " "/" OptStr)
    			  "]: ")
    		)
        )
      (print *ans*)
    )

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Dynamic User Input with Getstring List?

    I can post a sample of that for you as well... Next time I remote into the office, that is. Haha

    The basic logic is that in your Strcat for the Getkword string, you include an If statement, where if the global variable is non-Nil, include it, else "" (empty string). Then once a valid non-Nil string has been set, set you global variable to that value, and consume the global variable within the body of the main code.

    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  9. #9
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Dynamic User Input with Getstring List?

    Quote Originally Posted by BlackBox View Post
    I can post a sample of that for you as well... Next time I remote into the office, that is. Haha

    The basic logic is that in your Strcat for the Getkword string, you include an If statement, where if the global variable is non-Nil, include it, else "" (empty string). Then once a valid non-Nil string has been set, set you global variable to that value, and consume the global variable within the body of the main code.

    HTH
    Lol, dude, that is awesome. I do okay by dealing with problems as they come, but your thought processes solve multiple problems in one fell swoop. I tend to just save a bunch of generic subroutines and insert them where necessary and tackle problems one at a time. I'd need a minimum of three subroutines to accomplish what you do in one.

  10. #10
    Design Visualization Moderator stusic's Avatar
    Join Date
    2004-10
    Location
    Denver, Colorado
    Posts
    1,515
    Login to Give a bone
    0

    Default Re: Dynamic User Input with Getstring List?

    Got a weird problem with this. I think it has something to do with the initget bitcode, but I'm not sure what's up. It seems to work fine (except the wcmatch that I haven't fixed yet) as long as you enter the kword string correctly. It works the first time you enter a wrong option, but then doesn't accept anything after that, giving the error "Invalid option keyword".

    Would someone mind taking a look?

    Code:
    (defun c:foo ()
    
      (vl-load-com)
    
    ;|			BEGIN SUBFUNCTIONS			|;
    
      ;; Join list items into string with delimiter string
      (defun _implode	(data delim / str n)
      (if (and (= (type data) 'LIST)
    	   (= (type delim) 'STR)
    	   (> (strlen delim) 0)
          )
        (foreach n data
          (if str
    	(setq str (strcat str delim n))
    	(setq str n)
          )
        )
      )
    )
    
    ;|			END SUBFUNCTIONS			|;
    
    ;|			BEGIN MAIN ROUTINE			|;
    
        ; SET UP OPTIONS FOR ITEM TYPE
    
      (if
        (= *TypLst nil)
        (setq *TypLst (list
    		 "PNL"
    		 "CAB"
    		 "DSK"
    		 "CLT"
    		 "TFS"
    		 "STD"
    		 "SGN"
    		 "DOR"
    		 "CLG"
    		 "FAS"
    		 "PST"
    		 "SUP"
    		 "MIS"
    		 )
    	)
        )
    
      ; BREAK THE LIST UP INTO A STRING WITH SPACES
    
    (setq TypStr (_implode *TypLst " "))
    
      ; ON FIRST RUN, SET DEFAULT OPTION
      
    (if (not *Typ) (setq *Typ (car *TypLst)))
    
      ; GET TYPE FROM USER
    
    (initget 128 TypStr)
    
    	(while
    	  (not
    	    (and
    	      (setq
    		str (strcase (getkword
    			       (strcat "\nChoose [" ; hangs right here when retrying an incorrect keyword
    				       (vl-string-translate " " "/" TypStr)
    				       "] <"
    				       *Typ
    				       ">: "
    			       )
    			     )
    		    )
    	      )
    	      (= (strlen str) 3)
    	    )
    	  )
    	   (prompt "\nNothing entered, or too many characters --")
    	  (setq str nil)
    	)
    
    
    (setq *Typ str)
    
    
    
    
      ; ADD IT TO THE OPTION LIST IF NOT ALREADY PRESENT
    
      (if
        (not (wcmatch TypStr *Typ))
        (setq *TypLst (cons *Typ *TypLst))
        )
      (princ *Typ)
    
      (setq str nil)
      (setq *typ nil)
      (setq *typlst nil)
      (setq typstr nil)
    
    ;|			END MAIN ROUTINE			|;
    
      (princ)
    
      )

Page 1 of 2 12 LastLast

Similar Threads

  1. 2014: New Keynote/Tag User - Can User input be added.
    By jason.miller681034 in forum Revit - Platform
    Replies: 1
    Last Post: 2014-11-26, 05:13 PM
  2. Controlling visibility by user input method. (Not by the list.)
    By Ykang.236078 in forum Dynamic Blocks - Technical
    Replies: 3
    Last Post: 2010-11-23, 02:10 PM
  3. Anyone know how to get (getstring T) to work?
    By RapidCAD in forum AutoLISP
    Replies: 4
    Last Post: 2007-11-07, 06:02 PM
  4. Replies: 5
    Last Post: 2007-05-08, 09:59 PM
  5. Input bearings when using dynamic input
    By rmk in forum AutoCAD General
    Replies: 3
    Last Post: 2006-03-13, 04:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •