Results 1 to 8 of 8

Thread: recall last input

  1. #1
    100 Club
    Join Date
    2005-12
    Location
    Columbus, OH
    Posts
    158
    Login to Give a bone
    0

    Default recall last input

    I'm hoping to get a litte help with a LISP routine that I wrote. I took the lengthen command and just added a step so that it will ask for the distance first and put the distance value in the lengthen command for me.

    What I am hoping to do is have it recall the last distance inputted the same way the offset command store the last offset distance.

    I have attached my LISP command. If anyone could I would be greatfull.

    I want to thank you in advance for any help.

    Matt

  2. #2
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: recall last input

    Try this ... changes marked in red:
    Code:
    ;;;This is the Lengthen command set to Delta
    (prompt "\nType dd to run.....")
    (setq size 0.0) ;Initialize global var
    (defun C:dd(/ sz)
      (setvar "cmdecho" 0)
      (if (setq sz (getdist (strcat "\nLengthen of segment <" (rtos size) ">: ")))
        (setq size sz))
      (command "lengthen" "de"size)
      (princ))
    Just hit Enter if the same length change is needed.

  3. #3
    100 Club
    Join Date
    2005-12
    Location
    Columbus, OH
    Posts
    158
    Login to Give a bone
    0

    Default Re: recall last input

    Thank you! That's what I was looking for.

  4. #4
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: recall last input

    Pleasure!

    Just as a general comment ... try to declare the variables you're going to use inside the function. Otherwise they become global variables and use up RAM even after the function has finished. See this example:
    Code:
    ;;; New command with local variables
    (defun c:NewCommand (/ var1 var2)
      .....
    )
    ;;; After finish var1 & var2 are set to nil and cleared from RAM
    
    ;;; Normal function with arguments and local vars
    (defun Test (arg1 arg2 / var1 var2)
      .....
    )
    ;;; You can call this function together with passing values through the arg variables
    ;;; e.g. (Test 1.0 4.5)
    ;;; And as before var1 & var2 is cleared from RAM after finish
    The only time you use a global variable is when you want a value to be consistent between separate calls to the function / command as per my last post. In this case it's good practice to initialize it first as well (even if not needed) just so you know what variables are global (easier for yourself to see).

  5. #5
    I could stop if I wanted to
    Join Date
    2005-09
    Location
    Canada
    Posts
    214
    Login to Give a bone
    0

    Default Re: recall last input

    Quote Originally Posted by irneb View Post
    Try this ... changes marked in red:
    Code:
    ;;;This is the Lengthen command set to Delta
    (prompt "\nType dd to run.....")
    (setq size 0.0) ;Initialize global var
    (defun C:dd(/ sz)
      (setvar "cmdecho" 0)
      (if (setq sz (getdist (strcat "\nLengthen of segment <" (rtos size) ">: ")))
        (setq size sz))
      (command "lengthen" "de"size)
      (princ))
    Just hit Enter if the same length change is needed.
    Just a suggestion..
    your code do not clear the size variable because it's created when the program was loaded.

    also, each time it was loaded, it reset the variable size to 0.0

    The code below show how you can keep the variable by drawing and clear all the variable of RAM.

    Code:
    (defun C:dd(/ sz size)
    
    (setq cmdecho (getvar "cmdecho"))
    (prompt "\nType dd to run.....")
    
    (if (not (setq size (vlax-ldata-get "dd" "size")))
      (setq size (vlax-ldata-put "dd" "size" 0.0))
    )
    
    (setvar "cmdecho" 0)
    (if (setq sz (getdist
    	       (strcat "\nLengthen of segment <" (rtos size) ">: ")
    	     )
        )
      (progn
        (vlax-ldata-put "dd" "size" sz)
        (command "._lengthen" "_de" size)
        (setvar "cmdecho" cmdecho)
        (princ)
    )
    )
    )
    Don't forget to underscore any AutoCAD command.
    Last edited by andrea.andreetti; 2009-01-09 at 06:27 AM.

  6. #6
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: recall last input

    Yep, that's a very nice way of keeping the variable consistent even after closing & re-opening the DWG and the default is specific to each DWG. I suppose you could even save it to registry if you want the same default for all drawings even after a reboot. But that depends on what the OP wants.

    Mine was just a simple way of doing it, and is similar to most of the standard commands' way of keeping default values. Obviously this can be improved upon as you've pointed out.

  7. #7
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Iron Station, NC
    Posts
    3,198
    Login to Give a bone
    0

    Default Re: recall last input

    another method if you want the value to transfer between drawings, find what lisp file controls the express tool EXOFFSET, and find the code in there that controls saving of the offset variable. If I remember correctly, you can set it and it will always stay that value no matter what drawing you open, until you change the offset distance value

  8. #8
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Exclamation Re: recall last input

    Quote Originally Posted by andrea.andreetti View Post
    Code:
    ...
        (vlax-ldata-put "dd" "size" sz)
    ...
    Everyone please be aware that LData is not visible to VBA so I strongly recommend using a normal Dictionary/XRecord to store such drawing data. With a few wrapper functions the actual data storage/retrieval is exactly the same as using the ldata* functions without the API issues of LData.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

Similar Threads

  1. Replies: 5
    Last Post: 2007-05-08, 09:59 PM
  2. recall saved view
    By cheukling125525.110216 in forum Revit Structure - General
    Replies: 7
    Last Post: 2006-09-25, 05:31 PM
  3. Recall and input a variable
    By ch00su in forum AutoLISP
    Replies: 10
    Last Post: 2006-09-11, 12:36 PM
  4. Recall move/copy distance
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2006-01-05, 05:51 PM
  5. Viewport name recall or view name recall
    By dervin in forum AutoCAD General
    Replies: 1
    Last Post: 2005-01-03, 06:43 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
  •