TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: hudster on March 26, 2004, 07:58:49 AM

Title: how do i keep this loaded.
Post 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.

Code: [Select]
(initget (+ 1 2 4))
     (setq #d (getint "\nDrawing Scale: "))
   (setq #dist (* #D 5.75 )
Title: how do i keep this loaded.
Post by: Mark on March 26, 2004, 08:14:14 AM
You could make the variable global and test for it's existence in the program.

Code: [Select]

(if (not #d)
  (progn
    (initget (+ 1 2 4))
    (setq #d (getint "\nDrawing Scale: "))
    (setq #dist (* #D 5.75))
  )
  ;else
 (setq #dist (* #D 5.75))
)
Title: how do i keep this loaded.
Post by: hudster on March 26, 2004, 10:54:00 AM
Cheers mate.

you are a star.  Works great.
Title: how do i keep this loaded.
Post by: DEVITG on March 26, 2004, 05:21:15 PM
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???
Title: how do i keep this loaded.
Post by: hudster on March 26, 2004, 05:49:56 PM
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.
Title: how do i keep this loaded.
Post by: Mark on March 26, 2004, 05:52:29 PM
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.
Title: how do i keep this loaded.
Post by: hudster on March 27, 2004, 04:32:02 AM
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?
Title: how do i keep this loaded.
Post by: Mark on March 27, 2004, 07:33:45 AM
>I can use it in the lisp routine?
sure.
Title: how do i keep this loaded.
Post by: daron on March 27, 2004, 10:51:03 PM
Don't forget there are 4 other userr# variables. Just use one of them.
Title: how do i keep this loaded.
Post by: hendie on March 29, 2004, 02:44:49 AM
there's also SETCFG & GETCFG which can be useful
Title: how do i keep this loaded.
Post by: Keith™ on March 29, 2004, 08:10:34 AM
You can also use SETENV and GETENV
Title: how do i keep this loaded.
Post by: SMadsen on March 29, 2004, 01:35:25 PM
XData? LData? Dictionaries? Registry?

Don't forget a USERIx can hold up to 4 decimals ..

*ok, so I like to overdo it .. so what?!*
Title: how do i keep this loaded.
Post by: JohnK on March 29, 2004, 04:00:21 PM
To fill a global variable full of values I like to use an association list.

Code: [Select]
(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.