See the top rated post in this thread. Click here

Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: How to make a variable from the last user input

  1. #1
    Member
    Join Date
    2011-06
    Location
    Montreal, QC, CA
    Posts
    28
    Login to Give a bone
    0

    Default How to make a variable from the last user input

    Hi,
    Is it possible to get the active command shortcut as a variable? or the last entered command value as a variable?

    Simple example:
    (defun c:1()
    (setq SS (ssget (prompt"\nCouleur de Trait")))
    (command "_change" SS "" "_p" "_c" "1" "")(princ))

    What I would like is to create a variable that contains the typed number so I don't have to create one function per number; i.e: type 1, objects turn red, type 2 objects turn yellow.....
    I would like to keep to lisp structure as is - I know I could make: (defunc:COLOR() (setq CLR (getint)) .... blablabla, but the idea is to be able to type in the color number as user input and apply it to the selected objects. It is autoloaded from another lisp, so I can control what colors I permit or not through that (remove defun c: and replace 1 by variable)

    Maybe my brain is off this morning, but I can't get hold of this one...
    Thanks

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

    Default Re: How to make a variable from the last user input

    Would it not be simpler to instead prompt the user to specify the color?

    Code:
    (defun c:FOO (/ ss)
      (princ "\nChanger la couleur: ")
      (if (setq ss (ssget "_:L"))
        (command "._change" ss "" "properties" "color" pause "")
        (prompt "\n** Rien sélectionné ** ")
      )
      (princ)
    )
    "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
    Member
    Join Date
    2011-06
    Location
    Montreal, QC, CA
    Posts
    28
    Login to Give a bone
    0

    Default Re: How to make a variable from the last user input

    It would be easier (in fact, I've scripted something already for myself), but I have some die-hard drafters that have been using these shortcuts for the last century or so. I'd like not to break the habit, if possible. Which leads us back to getting the user input as a variable.

    I do enjoy your "pause", though, will make it part of my routine.

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

    Default Re: How to make a variable from the last user input

    Quote Originally Posted by Phil Gravel View Post
    It would be easier (in fact, I've scripted something already for myself), but I have some die-hard drafters that have been using these shortcuts for the last century or so. I'd like not to break the habit, if possible. Which leads us back to getting the user input as a variable.
    Always happy to further perpetuate inefficiency :

    You can use simple LISP routines as such:
    Code:
    (defun c:1 () (_ChangeSsColor 1))
    (defun c:2 () (_ChangeSsColor 2))
    (defun c:3 () (_ChangeSsColor 3))
    (defun c:4 () (_ChangeSsColor 4))
    (defun c:5 () (_ChangeSsColor 5))
    (defun c:6 () (_ChangeSsColor 6))
    (defun c:7 () (_ChangeSsColor 7))
    (defun c:8 () (_ChangeSsColor 8))
    (defun c:9 () (_ChangeSsColor 9))
    (defun c:10 () (_ChangeSsColor 10))
    ;;; ... And so on
    ... Which supply the color (the command name) to the dependent sub-function, changing the color of a valid selection set, and supports undo functionality:
    Code:
    (vl-load-com)
    
    (defun _ChangeSsColor (color / *error*)
      (princ "\nChanger la couleur: ")
    
      (defun *error* (msg)
        (and oldNomutt (setvar 'nomutt oldNomutt))
        (if acDoc
          (vla-endundomark acDoc)
        )
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ msg))                                                 ; Fatal error, display it
        )
        (princ)
      )
    
      ((lambda (acDoc oldNomutt / ss)
         (vla-startundomark acDoc)
         (princ "\nSélectionnez les objets à changer de couleur: ")
         (setvar 'nomutt 1)
         (if (setq ss (ssget "_:L"))
           (progn
             (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
               (vl-catch-all-apply 'vla-put-color (list x color))
             )
             (vla-delete ss)
             (*error* nil)
           )
           (*error* "\n** Rien sélectionné ** ")
         )
       )
        (vla-get-activedocument (vlax-get-acad-object))
        (getvar 'nomutt)
      )
    )
    Rather than load this into every drawing, consider adding a robust AUTOLOAD Statement instead:

    Code:
    (autoload "<SomeFileName>.lsp" '("1" "2" "3" "4" "5" "6" "7" "8" "9" "10"))
    "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
    Member
    Join Date
    2011-06
    Location
    Montreal, QC, CA
    Posts
    28
    Login to Give a bone
    0

    Default Re: How to make a variable from the last user input

    That's what I'm trying to avoid...... that never ending list. If I can't get the user input into a variable, then I'll leave my existing code as is, as it is painfully long already.



    [QUOTE=RenderMan;1190854]Always happy to further perpetuate inefficiency :

    You can use simple LISP routines as such:
    Code:
    (defun c:1 () (_ChangeSsColor 1))
    (defun c:2 () (_ChangeSsColor 2))
    (defun c:3 () (_ChangeSsColor 3))
    (defun c:4 () (_ChangeSsColor 4))
    (defun c:5 () (_ChangeSsColor 5))
    (defun c:6 () (_ChangeSsColor 6))
    (defun c:7 () (_ChangeSsColor 7))
    (defun c:8 () (_ChangeSsColor 8))
    (defun c:9 () (_ChangeSsColor 9))
    (defun c:10 () (_ChangeSsColor 10))
    ;;; ... And so on

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

    Default Re: How to make a variable from the last user input

    The Change Command settings are drawing dependent, yet are not saved with the drawing... So, presumably, any modifications are temporarily stored to either Global Variable, or Dictionary/XRecord, but I am unsure as to where to look at the moment.
    "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
    Member
    Join Date
    2011-06
    Location
    Montreal, QC, CA
    Posts
    28
    Login to Give a bone
    0

    Default Re: How to make a variable from the last user input

    Here's nothing: would it be possible to retain the last line from the text window (F2) and dump it in a variable?

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

    Default Re: How to make a variable from the last user input

    Quote Originally Posted by Phil Gravel View Post
    Here's nothing: would it be possible to retain the last line from the text window (F2) and dump it in a variable?
    Yes, that can be done... But it's a whole lot of overhead, as you have to turn on logging, specify the location, let the command complete, extract the last line of the log file contents, perhaps destroy the log file, and restore all settings changed... BEFORE you can begin your code.

    ... If memory serves, there's a thread around here where someone needed to do this for CUI manipulation, as they had to list something to the command line first in order to access certain information. In any event, so much more work than is necessary... More work in fact than it would be for the learning curve to learn the simpler way.

    If nothing else, I appreciate your tenacity.
    "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
    Member
    Join Date
    2011-06
    Location
    Montreal, QC, CA
    Posts
    28
    Login to Give a bone
    0

    Default Re: How to make a variable from the last user input

    Oh well. I tried. I really did.

    Thanks!

  10. #10
    Certifiable AUGI Addict tedg's Avatar
    Join Date
    2005-06
    Location
    in the upper right corner
    Posts
    3,507
    Login to Give a bone
    0

    Default Re: How to make a variable from the last user input

    Quote Originally Posted by Phil Gravel View Post
    Hi,
    Is it possible to get the active command shortcut as a variable? or the last entered command value as a variable?

    Simple example:
    (defun c:1()
    (setq SS (ssget (prompt"\nCouleur de Trait")))
    (command "_change" SS "" "_p" "_c" "1" "")(princ))

    What I would like is to create a variable that contains the typed number so I don't have to create one function per number; i.e: type 1, objects turn red, type 2 objects turn yellow.....
    I would like to keep to lisp structure as is - I know I could make: (defunc:COLOR() (setq CLR (getint)) .... blablabla, but the idea is to be able to type in the color number as user input and apply it to the selected objects. It is autoloaded from another lisp, so I can control what colors I permit or not through that (remove defun c: and replace 1 by variable)

    Maybe my brain is off this morning, but I can't get hold of this one...
    Thanks
    Another option you could look into.
    I'm not sure of how you're calling up the functions, how your people are using the command or whatever..
    But this routine asks for user input (color number) then tells user to select entities and changes them.
    You could wrap this in defun or have it run automatically.
    May need to be modified and put into a loop or something.

    It's a start toward simply typing a number and have it do it's thing.
    (using the "lastprompt" variable)

    ~shrug~

    Code:
    (defun c:test (/ color entcolor)
    (setq color (getstring  (prompt "Color?\n")))
    (setq entcolor (getvar "lastprompt"))
    (setq SS (ssget (prompt"\select objects to change color")))
    (command "_change" SS "" "_p" "_c" entcolor "")(princ))
    Last edited by tedg; 2012-09-12 at 07:13 PM.

Page 1 of 3 123 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. 2014: Input order issues (variable setting?)
    By Dennis.Conner in forum AutoCAD General
    Replies: 1
    Last Post: 2014-06-17, 07:08 PM
  3. Scr or Lsp for User Input?
    By ameador in forum AutoLISP
    Replies: 5
    Last Post: 2009-08-07, 04:29 PM
  4. Replies: 5
    Last Post: 2008-01-21, 02:35 PM
  5. Recall and input a variable
    By ch00su in forum AutoLISP
    Replies: 10
    Last Post: 2006-09-11, 12:36 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
  •