See the top rated post in this thread. Click here

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

Thread: Setting a variable from a list

  1. #1
    I could stop if I wanted to
    Join Date
    2009-10
    Posts
    262
    Login to Give a bone
    0

    Default Setting a variable from a list

    Can i make a variable set based upon a select using this code or something similar

    (setq X (getkword "\nWhat should X equal? [Time,Money,Help] :"))

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

    Default Re: Setting a variable from a list

    Sorry for any syntax errors; posting from an iPhone:

    Code:
    (if
      (and
        (not (initget "Time Money Help"))
        (setq X (getkword "\nWhat should \"X\" equal? [Time,Money,Help] :"))
      )
      (prompt (strcat "\nYou entered \"" X "\" for the value of \"X\" "))
    )
    "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
    I could stop if I wanted to
    Join Date
    2009-10
    Posts
    262
    Login to Give a bone
    0

    Default Re: Setting a variable from a list

    Another question...the X variable needs to interact with other instances there for the variable must show the whole word.

    Is there a way I can do this with getstring without entering the whole word...

    So If I have (setq X (getstring "\nWhat should X equal? [Time,Money,Help] : "))

    If i enter just H for Help it sets X's string equal to H in other references of X in a code.

    Can I make that string = Help without entering the whole word

    Maybe with something like Y=X string based on the letter entered, then having Y reference the rest of the code.

    Also how did you encapsulate your code in your post?

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

    Default Re: Setting a variable from a list

    Try adding a CONDitional statement:

    Code:
    (if
      (and
        (not (initget "Time Money Help"))
        (setq X (getkword "\nWhat should \"X\" equal? [Time,Money,Help] :"))
        (setq X (strcase X))
      )
      (prompt 
        (strcat 
          "\nYou entered \"" 
          (cond
            ((wcmatch X "T*") "Time")
            ((wcmatch X "M*") "Money")
            ((wcmatch X "H*") "Help")
          )
          "\" for the value of \"X\" "
        )
      )
    )

    Also, see posting guidelines for use of [ CODE ] tags; posting from mobile, so sorry for not providing direct link. You can quote my post to see more.

    Cheers
    "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

  5. #5
    I could stop if I wanted to
    Join Date
    2009-10
    Posts
    262
    Login to Give a bone
    0

    Default Re: Setting a variable from a list

    Code:
    (defun C:Test (/ kw X)
     (while
      (and (not (initget 7 "Yes No"))
            (setq kw (getkword "\nDefine X? [Yes,No] :"))
            (eq kw "Yes")
       (if
         (and(not (initget "Time Money Help"))
             (setq X (getstring "\nWhat should \"X\" equal? [Time,Money,Help] :"))
             (setq X (strcase X))
             )
         (prompt 
           (strcat 
             "\nYou entered \"" 
             (cond
               ((wcmatch X "T*") "Time")
               ((wcmatch X "M*") "Money")
               ((wcmatch X "H*") "Help")
             )
             "\" for the value of \"X\" "
           )
         )
       )
      )
     )
    )
    Any ideas why this isn't continuing after value of x is returned?

    I apologize for the lack of bracket spacing...I just can't seem to find how to enclose my code
    Last edited by BlackBox; 2015-05-18 at 04:41 AM. Reason: Please use [CODE] Tags

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

    Default Re: Setting a variable from a list

    Quote Originally Posted by mbrandt5 View Post
    Code:
    (defun C:Test (/ kw X)
     (while
      (and (not (initget 7 "Yes No"))
            (setq kw (getkword "\nDefine X? [Yes,No] :"))
            (eq kw "Yes")
       (if
         (and(not (initget "Time Money Help"))
             (setq X (getstring "\nWhat should \"X\" equal? [Time,Money,Help] :"))
             (setq X (strcase X))
             )
         (prompt 
           (strcat 
             "\nYou entered \"" 
             (cond
               ((wcmatch X "T*") "Time")
               ((wcmatch X "M*") "Money")
               ((wcmatch X "H*") "Help")
             )
             "\" for the value of \"X\" "
           )
         )
       )
      )
     )
    )
    Any ideas why this isn't continuing after value of x is returned?
    I'll let you identify the difference in code logic:

    Code:
    (defun C:Test (/ kw X)
      (while
        (and (not (initget 7 "Yes No"))
             (setq kw (getkword "\nDefine X? [Yes,No] :"))
             (eq kw "Yes")
        )
         (if
           (and (not (initget "Time Money Help"))
                (setq X
                       (getstring "\nWhat should \"X\" equal? [Time,Money,Help] :"
                       )
                )
                (setq X (strcase X))
           )
            (prompt
              (strcat
                "\nYou entered \""
                (cond
                  ((wcmatch X "T*") "Time")
                  ((wcmatch X "M*") "Money")
                  ((wcmatch X "H*") "Help")
                )
                "\" for the value of \"X\" "
              )
            )
         )
      )
    )


    Quote Originally Posted by mbrandt5 View Post
    I apologize for the lack of bracket spacing...I just can't seem to find how to enclose my code
    No worries; we all start somewhere... This should help:

    http://forums.augi.com/misc.php?do=bbcode
    "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

  7. #7
    I could stop if I wanted to
    Join Date
    2009-10
    Posts
    262
    Login to Give a bone
    0

    Default Re: Setting a variable from a list

    Thank you very much

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

    Default Re: Setting a variable from a list

    Quote Originally Posted by mbrandt5 View Post
    Thank you very much
    You're welcome, mbrandt5; I'm happy to help.
    "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
    I could stop if I wanted to
    Join Date
    2009-10
    Posts
    262
    Login to Give a bone
    0

    Default Re: Setting a variable from a list

    How can I repeat the same results with a response of same results...

    I don't just want the results to be displayed again but actually stored and reentered essentially

    So I'd define x, define y then be prompted to repeat same results and the definitions would be once again defined as the original input string

    Code:
    (defun C:Test (/ kw X)
      (while
        (and (not (initget 7 "Yes No"))
             (setq kw (getkword "\nDefine X? [Yes,No] :"))
             (eq kw "Yes")
        )
         (if
           (and (not (initget "Time Money Help"))
                (setq X
                       (getstring "\nWhat should \"X\" equal? [Time,Money,Help] :"
                       )
                )
                (setq X (strcase X))
           )
            (prompt
              (strcat
                "\nYou entered \""
                (cond
                  ((wcmatch X "T*") "Time")
                  ((wcmatch X "M*") "Money")
                  ((wcmatch X "H*") "Help")
                )
                "\" for the value of \"X\" "
              )
            )
         )
         (if
           (and (not (initget "Time Money Help"))
                (setq Y
                       (getstring "\nWhat should \"Y\" equal? [Time,Money,Help] :"
                       )
                )
                (setq Y (strcase Y))
           )
            (prompt
              (strcat
                "\nYou entered \""
                (cond
                  ((wcmatch Y "T*") "Time")
                  ((wcmatch Y "M*") "Money")
                  ((wcmatch Y "H*") "Help")
                )
                "\" for the value of \"Y\" "
              )
            )
         )
      )
    )

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

    Default Re: Setting a variable from a list

    Quote Originally Posted by mbrandt5 View Post
    How can I repeat the same results with a response of same results...

    I don't just want the results to be displayed again but actually stored and reentered essentially

    So I'd define x, define y then be prompted to repeat same results and the definitions would be once again defined as the original input string

    Code:
    (defun C:Test (/ kw X)
      (while
        (and (not (initget 7 "Yes No"))
             (setq kw (getkword "\nDefine X? [Yes,No] :"))
             (eq kw "Yes")
        )
         (if
           (and (not (initget "Time Money Help"))
                (setq X
                       (getstring "\nWhat should \"X\" equal? [Time,Money,Help] :"
                       )
                )
                (setq X (strcase X))
           )
            (prompt
              (strcat
                "\nYou entered \""
                (cond
                  ((wcmatch X "T*") "Time")
                  ((wcmatch X "M*") "Money")
                  ((wcmatch X "H*") "Help")
                )
                "\" for the value of \"X\" "
              )
            )
         )
         (if
           (and (not (initget "Time Money Help"))
                (setq Y
                       (getstring "\nWhat should \"Y\" equal? [Time,Money,Help] :"
                       )
                )
                (setq Y (strcase Y))
           )
            (prompt
              (strcat
                "\nYou entered \""
                (cond
                  ((wcmatch Y "T*") "Time")
                  ((wcmatch Y "M*") "Money")
                  ((wcmatch Y "H*") "Help")
                )
                "\" for the value of \"Y\" "
              )
            )
         )
      )
    )

    I'm not entirely sure that I understand what you're asking; perhaps you could clarify?

    In any event, here's a quick stab in the dark:

    Code:
    (defun c:FOO (/ _GetValue kw x y)
    
      (defun _GetValue (x)
        (cond
          ((wcmatch x "T*") "Time")
          ((wcmatch x "M*") "Money")
          ((wcmatch x "H*") "Help")
        )
      )
      
      (while
        (and
          (not (initget 7 "Yes No"))
          (setq kw (getkword "\nDefine X? [Yes/No] :"))
          (eq kw "Yes")
        )
         (if
           (and
             (or *Option1*
                 (setq *Option1* "Time")
             )
             (not (initget "Time Money Help"))
             (or
               (/= ""
                   (setq x
                          (getstring
                            (strcat
                              "\nWhat should \"X\" equal? [Time/Money/Help] "
                              (if *Option1*
                                (strcat "<" *Option1* ">: ")
                                ": "
                              )
                            )
                          )
                   )
               )
               (setq x *Option1*)
             )
             (setq *Option1* x)
           )
            (prompt
              (strcat
                "\nYou entered \""
                (_GetValue x)
                "\" for the value of \"X\" "
              )
            )
         )
         (if
           (and
             (or *Option2*
                 (setq *Option2* *Option1*)
             )
             (not (initget "Time Money Help"))
             (or
               (/= ""
                   (setq y
                          (getstring
                            (strcat
                              "\nWhat should \"Y\" equal? [Time/Money/Help] "
                              (if *Option2*
                                (strcat "<" *Option2* ">: ")
                                ": "
                              )
                            )
                          )
                   )
               )
               (setq y *Option2*)
             )
             (setq *Option2* y)
           )
            (prompt
              (strcat
                "\nYou entered \""
                (_GetValue y)
                "\" for the value of \"Y\" "
              )
            )
         )
      )
    )
    "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

Page 1 of 2 12 LastLast

Similar Threads

  1. 2014: Input order issues (variable setting?)
    By Dennis.Conner in forum AutoCAD General
    Replies: 1
    Last Post: 2014-06-17, 07:08 PM
  2. Setting the ACAD environment variable on launch
    By jpcadconsulting347236 in forum AutoLISP
    Replies: 8
    Last Post: 2014-04-03, 04:14 PM
  3. Setting INSUNITS variable
    By ivan.hudak87583861 in forum VBA/COM Interop
    Replies: 1
    Last Post: 2011-11-27, 06:59 PM
  4. autocad tips: Setting a system variable on the tool palette
    By fishdigg2 in forum AutoCAD Tips & Tricks
    Replies: 0
    Last Post: 2010-09-26, 04:56 AM
  5. Setting a variable on startup
    By kathy71046 in forum AutoCAD General
    Replies: 7
    Last Post: 2010-03-31, 11:32 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
  •