Is it possible to create a lisp that remembers your previous string selection?

Is it possible to create a lisp that remembers your previous string selection?

Anonymous
Not applicable
5,009 Views
37 Replies
Message 1 of 38

Is it possible to create a lisp that remembers your previous string selection?

Anonymous
Not applicable

I am relatively new to AutoLISP so I don't much about the things that can be done with this language. I have experience with other languages like C, C++, Python, etc. I was wondering if its possible to create a lisp that remembers your previously selected strings and will prompt you and ask whether or not lets say for example, you want to use the previous 3 strings? Don't worry I am not asking anyone to do this for me. Just want to know is it possible to do it using this language? If yes, then can you guide me as to which command/function to look at in order to achieve this.
Any help will be appreciated 🙂

0 Likes
Accepted solutions (1)
5,010 Views
37 Replies
Replies (37)
Message 21 of 38

Anonymous
Not applicable

I didn't realize I had to type "prefix" to make the prefix part work. I just tried it and it works! Thanks a lot! 🙂 This is what I was looking for. I'll try to understand your code and try to implement the prefix part into mine.

0 Likes
Message 22 of 38

roland.r71
Collaborator
Collaborator

@scot-65 wrote:

d) Some sort of external file such as INI-structured. One will have to create
a custom parser as I do not believe there is one built in that will read this.


Not built in, but there is with Express Tools (which is almost the same), or one could use DOSLib.

Writing your own parser isn't needed.

 

Example:

(setq setSNAP (acet-ini-get "C:/LISP/fix.ini" "config" "setSNAP"))

(acet-ini-set "C:/LISP/fix.ini" "config" "setSNAP" setSNAP)

To read/write the snap setting (prefered / to be used) from/to my ini file.

 

For DOSLib that would be:

(setq setSNAP  (DOS_GETINI "config" "setSNAP"  "C:/LISP/fix.ini"))

(DOS_SETINI "config" "setSNAP" setSNAP "C:/LISP/fix.ini")

 

Where the config.ini looks like:

[config]

setSNAP=4

Message 23 of 38

Moshe-A
Mentor
Mentor

hi,

 

if you still want to save prefix text between drawing sessions (e.g in registry) and you did not get by yourself 

just tell me and i will finish this up.

 

enjoy

moshe

 

0 Likes
Message 24 of 38

smallƑish
Advocate
Advocate

(Setq Height(getreal "\nEnter height"))

 

Example above, if I run the lisp next time, possible to suggest the just previous user given value ?

0 Likes
Message 25 of 38

Sea-Haven
Mentor
Mentor

Make "height" unique to the one program say "XYZheight", it will sit there until you exit CAD. Don't Localize it. 

0 Likes
Message 26 of 38

cadffm
Consultant
Consultant

Hi,

 


@smallƑish wrote:

possible to suggest the just previous user given value ?

Yes.

 

offtopic

original: (Setq Height(getreal "\nEnter height"))

1st edit: (Setq Height(getreal "\nEnter height: ")) ; colon followed by a space to fit normal syntax

 

Sure.

strcat rtos will help, it is not much more than a variable-string, but

if you want to suggest the previous value, you need two variables, one for new enterd input, one for the last entered.

 

something like this:

 

(defun c:MyTest (/ MyTestHeight)

  (if (or
	(and
           (setq MyTestHeight (getreal (strcat "\nEnter height " (if *MyTestHeightPrev (strcat "<" (rtos *MyTestHeightPrev 2) ">") "") ": ")))
           (setq *MyTestHeightPrev MyTestHeight)
         )
         (if *MyTestHeightPrev (setq MyTestHeight *MyTestHeightPrev))
       )
       (progn
           (setq *MyTestHeightPrev MyTestHeight)
           (alert (rtos MyTestHeight)) ; Your program here
       )
       (alert "NoHeightValue")
  )

 (princ)
)

It

Sebastian

Message 27 of 38

Sea-Haven
Mentor
Mentor

Another, uses Multi getvals.lsp, user variable name used as suggested. Just use 3rd line once height exists for repeated entry.

 

 

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(if (= MyTestHeight nil)(setq MyTestHeight 100.))

(setq MyTestHeight (atof(car (AH:getvalsm (list "Enter value " "Height " 8 7 (rtos MyTestHeight 2 2))))))

 

 

SeaHaven_0-1703549706116.png

 

0 Likes
Message 28 of 38

smallƑish
Advocate
Advocate

it's perfect.

Thank you so much.

just one question, If we have multiple numbers to remember? Need to write the same for each correct?

Example

Height : 18O

Age 35

 

 

  (if (or
	(and
           (setq MyTestHeight (getreal (strcat "\nEnter height " (if *MyTestHeightPrev (strcat "<" (rtos *MyTestHeightPrev 2) ">") "") ": ")))
           (setq *MyTestHeightPrev MyTestHeight)
         )
         (if *MyTestHeightPrev (setq MyTestHeight *MyTestHeightPrev))
       )
       (progn
           (setq *MyTestHeightPrev MyTestHeight)
           (alert (rtos MyTestHeight)) ; Your program here
       )
       (alert "NoHeightValue")
  )


(if (or
(and
(setq age (getreal (strcat "\nAge in years:: " (if *age_Prev (strcat "<" (rtos *age_Prev 2 0) ">") "") ": ")))
(setq *age_Prev age)
)
(if *C8_Prev (setq age *age_Prev))
)
(progn
(setq *age_Prev age)
)
(alert "No age !!")
)

 

 

 

0 Likes
Message 29 of 38

cadffm
Consultant
Consultant

There are unlimited (more complicated) ways,

this is just one (simple) way to do it, YES.

 

offtopic

(if *C8_Prev (setq age *age_Prev)

*C8_Prev or *age_prev !?

 

(getreal  "...... :: ")

ONE colon is enough, or do know a native command with doubled colons at the end?

 

 

 

Sebastian

Message 30 of 38

smallƑish
Advocate
Advocate

Thank you so much, was struggling to find this since long. 

 

Oftopic. Yes there are lot of typo, Sorry to confuse you.

 

As result, it's happening. Thank you so much.

 

Anyways Thank you so much!!

0 Likes
Message 31 of 38

ВeekeeCZ
Consultant
Consultant

Remember, you can always use the UP-ARROW key to get the last entry.

Message 32 of 38

smallƑish
Advocate
Advocate

That was new for me.

 

Thank you!!

0 Likes
Message 33 of 38

cadffm
Consultant
Consultant

😆

Okay, so have a look to INPUTHISTORYMODE [F1]

Value 14 should be the most wanted setting (it is the setting how Acad acted for decades).

 

Sebastian

Message 34 of 38

smallƑish
Advocate
Advocate

struggled for decades to learn this.😭

0 Likes
Message 35 of 38

john.uhden
Mentor
Mentor

@cadffm ,

I had never heard of INPUTHISTORYMODE .

The help doesn't clearly indicate whether what's recalled is on a per command basis or not, but I'm guessing that it doesn't apply to custom AutoLisp command functions.

 

Anyway, I look at it this way...

There are three (3) levels of saving and recalling default values, all involving the use of a unique symbol name for each variable:

1.  Save it in the memory of the current active drawing only.

2.  Save it to the bulletin board for access by any drawing in the current AutoCAD session.

3.  Save it to a default file (or registry) for access by any drawing at any time.

 

For example, let's say you have a local variable named 'width.  You can save it and recall it in the current active drawing by giving it a unique prefix or suffix or both, such as *width* which you can also set to a popular default value to start with; let's say 2.0.

(if (not (equal (type *width*) 'REAL))
  (setq *width* 2.0)
)
(setq width (getdist (strcat "\nWidth <" (rtos *width* 2 1) ">: ")))
(if (not width)
  (setq width *width*)
  (setq *width* width)
)

For access during the current AutoCAD session, use the vl-bb-ref and vl-bb-set functions.

 

For access via a default file there are a few techniques, one of which is to write a line for each default, e.g. *width*=2.0.  When you read each line of the default file you must use the delimiter (in this example "=") to separate the name from the value.  If you are interested, remind me to post a handy function for you.

 

John F. Uhden

0 Likes
Message 36 of 38

cadffm
Consultant
Consultant

Hi John,


>>"I had never heard of INPUTHISTORYMODE"
Now, you have 🙂
Since the introduction of the dynamic input method (v2006), there is an expanded range of functions for
the "last input" functions via the arrow keys and context menu. This variable controles WHERE&WHICH of the last inputs can be accessed.

Clear example, Bit1 also repeats coordinate information, which did not exist pre2006.
This can be used very usefully for special tasks. Repeating coordinates is 99.9% annoying for ME, so, so I set the value to 14 and not as default 15.

 

>>"The help doesn't clearly indicate whether what's recalled is on a per command basis or not,"
Commands independent, it's the generally user-input-log, what temporary and per file-session.

I think you knowing and used the ArrowUp/Down function in you (A)cad life a lot, or not? I am using this extensively
since I started with Acad, as all long-time users I know.

 

>>"but I'm guessing that it doesn't apply to custom AutoLisp command"
It does apply to all situations where the program is asking for input, and it doesn't offer any
functions you could use inside your programming or is related to the currently running situation.
BeekeeCZs hint, which I added with the associated system variable, was not a clue to programming.

 

- - -

I think from here: "Anyway, I look at it this way..." is your post no longer just addressed to me?
But if so: Everything is correct and I don't need any help or examples,
but '@smallƑish' (the last questioner) might perhaps be happy about that.

 

 

Sebastian

0 Likes
Message 37 of 38

Sea-Haven
Mentor
Mentor

4th method is use Ldata it gets stored in current dwg can store width & height etc plus more makes a mini dictionary I think, with key name for retrieval. Very easy to use. 

 

(vlax-ldata-put "AlanH" "Layoutname" "Layout1")

(setq lay (vlax-ldata-get "AlanH" "Layoutname"))

 

 

Message 38 of 38

john.uhden
Mentor
Mentor

@Sea-Haven ,

You took the words right out of my mouth.

Others over the years have said that it's faulty, but I've never had a problem including saving an entire LDD surface.

John F. Uhden