Jump to content

Remembering the last input placed on a command


Recommended Posts

Posted

Hello everybody,

 

I'm fairly new to visual lisp and just started messing with it for about 2 weeks now. I have gone around learning as much as I can trying to program my own functions. I placed a couple goals in mind and so far hit some of them. I also kinda copy pasted some code here and there i found and created a few Frankenstein functions. This one has got me stuck though. So, basically I have a program that creates a Multi leader with the layer, annotation style,  and multi leader style loaded with it. It also loads up to different scale factors. When i enter the command "Test" i get prompted to choose a scale factor. If i choose, lets say "4" I would like it if when i hit space bar again the command remembered my last input. That way i can hit the space bar twice and have it be a lot smoother. If anyone can help me out that would be great.

 

I also found this link and tried to somewhat replicate it but had no luck

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/remember-display-use-last-initget-choice-as-default/td-p/8295768

 

Here is the beginning of my program

 

 

(defun c:TEST()
    (setq a
       (strcase (getstring "\nChoose Scale Factor [2/4/8/12/16/24/32/48/64/96/128/192/384] ")
      );strcase
    );setq
    (cond
        ((= a "2") (dTXT2)(mTXT2)(CTXT2))
        ((= a "4") (dTXT)(mTXT4)(CTXT4))
        ((= a "8") (dTXT)(mTXT8)(cTXT8))
        ((= a "12") (dTXT12)(mTXT12)(CTXT12))
        ((= a "16") (dTXT16)(mTXT16)(CTXT16))
        ((= a "24") (dTXT24)(mTXT24)(CTXT24))
        ((= a "32") (dTXT32)(mTXT32)(CTXT32))
        ((= a "48") (dTXT48)(mTXT48)(CTXT48))
        ((= a "64") (dTXT64)(mTXT64)(CTXT64))
        ((= a "96") (dTXT96)(mTXT96)(CTXT96))
        ((= a "128") (dTXT128)(mTXT128)(CTXT128))
        ((= a "192") (dTXT192)(mTXT192)(CTXT192))
        ((= a "384") (dTXT384)(mTXT384)(CTXT384))

    );cond
    (princ)
 (princ)
); _end defun, TEST

Posted

So, I just read the guide lines I apologized im very new to this site im not sure how to edit so ill post the original link of the code below.

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/create-new-layers-lisp/td-p/3560508

 

(defun c:TEST()
    (setq a
       (strcase (getstring "\nChoose Scale Factor [2/4/8/12/16/24/32/48/64/96/128/192/384] ")
      );strcase
    );setq
    (cond
        ((= a "2") (dTXT2)(mTXT2)(CTXT2))
        ((= a "4") (dTXT)(mTXT4)(CTXT4))
        ((= a "8") (dTXT)(mTXT8)(cTXT8))
        ((= a "12") (dTXT12)(mTXT12)(CTXT12))
        ((= a "16") (dTXT16)(mTXT16)(CTXT16))
        ((= a "24") (dTXT24)(mTXT24)(CTXT24))
        ((= a "32") (dTXT32)(mTXT32)(CTXT32))
        ((= a "48") (dTXT48)(mTXT48)(CTXT48))
        ((= a "64") (dTXT64)(mTXT64)(CTXT64))
        ((= a "96") (dTXT96)(mTXT96)(CTXT96))
        ((= a "128") (dTXT128)(mTXT128)(CTXT128))
        ((= a "192") (dTXT192)(mTXT192)(CTXT192))
        ((= a "384") (dTXT384)(mTXT384)(CTXT384))

    );cond
    (princ)
 (princ)
); _end defun, TEST

 

Posted

Try:

(defun c:TEST(/ notnil)
    (initget "2 4 8 12 16 24 32 48 64 96 128 192 384")
    (if(= a nil)(setq a "2"))
    (if(setq notnil (getkword (strcat "\nChoose Scale Factor [2/4/8/12/16/24/32/48/64/96/128/192/384] <" a ">: ")))(setq a notnil))
    (cond
        ((= a "2") (dTXT2)(mTXT2)(CTXT2))
        ((= a "4") (dTXT)(mTXT4)(CTXT4))
        ((= a "8") (dTXT)(mTXT8)(cTXT8))
        ((= a "12") (dTXT12)(mTXT12)(CTXT12))
        ((= a "16") (dTXT16)(mTXT16)(CTXT16))
        ((= a "24") (dTXT24)(mTXT24)(CTXT24))
        ((= a "32") (dTXT32)(mTXT32)(CTXT32))
        ((= a "48") (dTXT48)(mTXT48)(CTXT48))
        ((= a "64") (dTXT64)(mTXT64)(CTXT64))
        ((= a "96") (dTXT96)(mTXT96)(CTXT96))
        ((= a "128") (dTXT128)(mTXT128)(CTXT128))
        ((= a "192") (dTXT192)(mTXT192)(CTXT192))
        ((= a "384") (dTXT384)(mTXT384)(CTXT384))

    );cond
    (princ)
); _end defun, TEST?

 

Posted (edited)

 A recent post showing examples of remembering input HERE.

 

Also if your naming conventions for your subs are consistent appending the scale to the end, the conditional statement could be replaced with something like this :)

(foreach r '("dtxt" "mtxt" "ctxt") (eval (read (strcat "(" r a ")"))))

 

Edited by ronjonp
Posted (edited)

This "prompting for a default option" question seems to be more common than I thought. Again, take a look at Lee Mac's tutorial.

 

Heres another way to shorten the consecutive function calls :)

(foreach f (list dtxt mtxt ctxt)
  ('((v)(v)) f)
)

EDIT:

Actually, this is enough -

(foreach f (list dtxt mtxt ctxt)
  (f)
)

 

Edited by Grrr
Posted

Ok great thank you everyone for your input and examples. I didn’t know if this post was going to be approved by the mods because I didn’t fallow guidelines so I created another post on the Autodesk forum. Link below. For anyone that might have the same issue.  I’ll try these out at work and try to figure out what I was doing wrong. Thanks again. 

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-way-for-your-input-to-be-remembered/m-p/8622072/highlight/false#M381592

Posted

A suggestion maybe you can use a dialouge with a list of scales pretty sure you can pre higlight one of them which would be the last used so just press ok or press another.

 

Lee-mac has a nice listbox dcl easy to use. Just checked, if you look at this line in his code  (setq rtn (set_tile "list" "0")) you change the zero to the item number in your list so 4 would be a = 16. The cond would reflect the order number of a list rather than a physical number like 128. 

 

; check for updated code by lee-Mac.

; save a variable called Ben_sc with the scale as a string

(setq lst (list "2" "4" "8" "12" "16" "24" "32" "48" "64" "96" "128" "192" "384"))
(if (not LM:listbox)(load "ListboxV1-2.lsp"))
(setq scale (nth 0 (LM:listbox "Please choose scale" lst 0)))


Lees-code changed to
(if (= Ben_sc nil)(setq Ben_sc "0"))) ;added

(setq rtn (set_tile "list" Ben_sc)) ; check scale now

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...