TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: hudster on March 26, 2004, 07:58:49 AM
-
I have a lisp which lets me draw circuit lines.
I've changed the code to allow me to input the drawing scale so that it sizes the circuit lines according to the drawing scale.
but each time i run the routine it asks me to input the scale, is there a way in which i can make it default to the last scale used, rather than having to input each time.
(initget (+ 1 2 4))
(setq #d (getint "\nDrawing Scale: "))
(setq #dist (* #D 5.75 )
-
You could make the variable global and test for it's existence in the program.
(if (not #d)
(progn
(initget (+ 1 2 4))
(setq #d (getint "\nDrawing Scale: "))
(setq #dist (* #D 5.75))
)
;else
(setq #dist (* #D 5.75))
)
-
Cheers mate.
you are a star. Works great.
-
It works great, but , could be possible to use userrx to store the last scale used , does not matter if the lisp is unloaded or not???
-
I'm already using userr1 to store the scale for insertion of a few blocks.
would i be able to change this to show userr1 = #d?
This would be a lot better, as it would exclude the possibility of a typo.
-
If you are going to store a bunch of var's, wht not store them in a file then read them in when you start the program.
-
the userr1 variable was set up by someone else in my company, and it's already stored in a file so that it is loaded with each drawing.
if it enter (getvar userr1), it returns the drawing scale.
So can i take it by that, I can use it in the lisp routine?
-
>I can use it in the lisp routine?
sure.
-
Don't forget there are 4 other userr# variables. Just use one of them.
-
there's also SETCFG & GETCFG which can be useful
-
You can also use SETENV and GETENV
-
XData? LData? Dictionaries? Registry?
Don't forget a USERIx can hold up to 4 decimals ..
*ok, so I like to overdo it .. so what?!*
-
To fill a global variable full of values I like to use an association list.
(defun var-store (var value)
(cond ((and value) (cons var value))))
(defun test (lst)
(cond
((>= (length lst) 2)
;; if there are atleast two left in the list
(setq a (cons (var-store (car lst) (cadr lst)) a))
;; construct a list
(test (cdr (cdr lst)))))
a
;; Return the list
)
Use it like this:
(reverse (test '(test1 1 test2 2 test3 3 test4 4)))
-> ((TEST1 . 1) (TEST2 . 2) (TEST3 . 3) (TEST4 . 4))
But if you cant create the variables at run-time or ask the user I sudgest a file, regristry, or x/l data. I would try to stay away form the Users variables.