Jump to content

Recommended Posts

Posted

hello people:

i did this little test routine.

I want to learn how to do the following

enter a value in the "esp" variable

but that it is available for the next time the routine is used.

example:

if use 10,  that the next time it is used it suggests the value 10

If I change it to another value, suggest it to me next time.

I know that for teachers it is simple to do.

but I would like to learn.

 

thanks

 

(defun c:test (/ esp)
(initget (+ 1 2 4))
(setq esp (getreal "\nEnter value"))
(setq valor (* 10 esp))
(princ valor)
(PRINC)

  );fin defun

 

Posted (edited)

 

 

Because ( / esp ) means that esp is a local variable,

and the local variable is erased from memory when c:test finishes its function,

so it is used to prevent confusion when a variable called esp is used elsewhere.

Without this, we would have to come up with new, unique and long variable names every time.

 

You can simply replace ( / esp ) with ( ) to keep one dwg file loaded.

 

but, even if you change that.

(setq esp (getreal)) will specify a new one with user input every time.

this situation is keep and bring esp just before (getreal)

but not open it. and then replace with new value. It's like didn't bring it.

 

so, you can make another variable to store esp as a global variable, 

and remove 1 from initget to use the previous value with no response (input space bar).

like this below

(defun c:test ( / esp )
  (initget (+ 2 4))
  (if (setq esp (getreal (strcat "\nEnter value (or Space Bar < Prev. Value = " (rtos oldesp 2 2) " >)")))
    (setq oldesp esp)
    (setq esp oldesp)
  )
  (setq valor (* 10 esp))
  (princ valor)
  (princ)
);fin defun

 

However, if you write it like this, you will get an type error.

Because the type of global variable oldesp has never been specified, but rtos has been used. rtos has limitations on the types that can be input.

so, you can change like this

 

The first value is set to 10, and when user input is received, it is changed to that value from then on.

(setq oldesp 10)
(defun c:test ( / esp )
  (initget (+ 2 4))
  (if (setq esp (getreal (strcat "\nEnter value (or Space Bar < Prev. Value = " (rtos oldesp 2 2) " >)")))
    (setq oldesp esp)
    (setq esp oldesp)
  )
  (setq valor (* 10 esp))
  (princ valor)
  (princ)
);fin defun

or like this

The first value comes out as < Prev. Value = nil >, but since (vl-princ-to-string) is not as picky as rtos, no error occurs

and when user input is received, it is changed to that value from then on.

(vl-load-com)
(defun c:test ( / esp )
  (initget (+ 2 4))
  (if (setq esp (getreal (strcat "\nEnter value (or Space Bar < Prev. Value = " (vl-princ-to-string oldesp) " >)")))
    (setq oldesp esp)
    (setq esp oldesp)
  )
  (setq valor (* 10 esp))
  (princ valor)
  (princ)
);fin defun
Edited by exceed
  • Agree 1
Posted

You could also use ldata to save the variable to the drawing itself so it can be recalled even after restarting the computer.

 

(or (setq win* (vlax-ldata-get "Window" "Manufacturer")) (setq win* "Brown"))  ;if ldata is set will call that fist else defaults to Brown.

 

 

(initget "Brown Jeldwin Newmar Pollard")
(setq win (getkword (strcat "\nSet Window Manufacturer: Brown, JeldWin, Newmar, Pollard <" win* ">: ")))
(cond 
  (win
    (vlax-ldata-put "Window" "Manufacturer" win) ;updates ldata to what was picked.
    (setq WinOffset (cdr (assoc win winManLst)))
  )
  ((eq win nil)
    (setq win win*)
    (vlax-ldata-put "Window" "Manufacturer" win)
    (setq WinOffset (cadr (assoc win winManLst)))
  )
)
  • Agree 1

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...