TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Brick_top on November 23, 2011, 06:48:33 AM

Title: Setting variables in a file opened by a routine?
Post by: Brick_top on November 23, 2011, 06:48:33 AM
Hi there,

I would like to set new variables in a file I open with a routine.

I know I can "copy" variables from a drawing to another using vl-propagate. But how do I create new ones?

And how do I propagate more than one variable? vl-propagate only seems to propagate one variable?

thanks.
Title: Re: Setting variables in a file opened by a routine?
Post by: ElpanovEvgeniy on November 23, 2011, 06:56:11 AM
Code: [Select]
(setq a 1
      b 2
      c 3
)
(mapcar (function vl-propagate) '(a b c))
Title: Re: Setting variables in a file opened by a routine?
Post by: Brick_top on November 23, 2011, 06:56:50 AM
Nice! thanks a lot!
Title: Re: Setting variables in a file opened by a routine?
Post by: Lee Mac on November 23, 2011, 07:05:52 AM
Code: [Select]
(foreach sym '(a b c) (vl-propagate sym))
Title: Re: Setting variables in a file opened by a routine?
Post by: Brick_top on November 23, 2011, 07:15:01 AM
how about the other question? in case I explained my self correctly

thanks for the alternative lee

Title: Re: Setting variables in a file opened by a routine?
Post by: Lee Mac on November 23, 2011, 07:15:58 AM
Creating a new variable:

Code: [Select]
(setq a 1)
Title: Re: Setting variables in a file opened by a routine?
Post by: Brick_top on November 23, 2011, 07:18:26 AM
lets see if I can explain my self better.

I have a routine I run in a drawing.

That routine opens another drawing, and now I want to set new variables in that drawing.

Title: Re: Setting variables in a file opened by a routine?
Post by: Lee Mac on November 23, 2011, 07:24:22 AM
That routine opens another drawing, and now I want to set new variables in that drawing.

Set the variables in the active drawing and propagate them?
Title: Re: Setting variables in a file opened by a routine?
Post by: ElpanovEvgeniy on November 23, 2011, 07:58:00 AM
If you do not have a large amount of data you can use the setenv/getenv
Title: Re: Setting variables in a file opened by a routine?
Post by: Brick_top on November 23, 2011, 08:58:46 AM
That routine opens another drawing, and now I want to set new variables in that drawing.

Set the variables in the active drawing and propagate them?

Well in the way I'm seeing things right now I don't know how to do that because of what I want to do because there are variables that need to be set differently in the "other" drawing.

What I want to do is save notes in each drawing (as xrecords) I have and then have a "master" drawing with all the notes so I can later search all the notes of all the projects. Problem is the xrecord "name?" is diferent in the master drawing.

For example I name the notes in all the projects as "Note 1" "Note 2" "Note 3" etc.. every project will start in number 1. But the "master" drawing where I'll have all the notes stored will only have one "Note 1".





Title: Re: Setting variables in a file opened by a routine?
Post by: Brick_top on November 23, 2011, 09:03:18 AM
I need to check the xrecords in the "opened by the routine" file to set the new name of the next xrecord.

At least this is what I'm thinking
Title: Re: Setting variables in a file opened by a routine?
Post by: Brick_top on November 23, 2011, 09:08:12 AM
This is what I'm doing to check the number of the note, and set the number of the next one.

Code: [Select]
(setq a (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 3 (car x)))(entget (namedobjdict))))
         b (vl-remove-if-not '(lambda (x) (= "Nota" (substr x 1 4))) a)
         titl2 (strcat "Nota" " " (itoa (+ 1 (length b))))
   );setq
Title: Re: Setting variables in a file opened by a routine?
Post by: Brick_top on November 25, 2011, 04:49:23 AM
I gave up the ideia, I just run another routine in the opened file to set the new variables.
Title: Re: Setting variables in a file opened by a routine?
Post by: FreeBird on November 27, 2011, 06:10:12 AM
I have an idea, DBX or vl-propagate + s::startup
Title: Re: Setting variables in a file opened by a routine?
Post by: Brick_top on November 28, 2011, 05:18:27 AM
will the s::startup function define functions for every drawing?
Title: Re: Setting variables in a file opened by a routine?
Post by: shawndoe on December 16, 2011, 04:22:33 PM
Hi,

It's a bit late, but I have a routine that also opens a new drawing from another and I found that (vl-bb-set/ref) is a much better option.  Vl-propogate dumps global variables in the new drawing which may cause problems.  I'm also under the impression that you can't access vl-propogate variables until after the S::STARTUP has finished.

Have a good one.
Shawndoe
Title: Re: Setting variables in a file opened by a routine?
Post by: GDF on December 16, 2011, 05:12:10 PM
I use vl-registry-write and vl-registry-read.

Example: setting globals for dialog box controls.
(defun ARCH:SETDIALMODE  (key /)
  (vl-registry-write
    "HKEY_CURRENT_USER\\Software\\Arch Program\\Controls\\Dialog\\Display"
    ""
    key)
  (setq ARCH#DIAL
         (vl-registry-read
           "HKEY_CURRENT_USER\\Software\\Arch Program\\Controls\\Dialog\\Display"))
  (princ))
Title: Re: Setting variables in a file opened by a routine?
Post by: TimSpangler on December 16, 2011, 06:35:54 PM
setcfg / getcfg  8-)
Title: Re: Setting variables in a file opened by a routine?
Post by: BlackBox on December 17, 2011, 12:38:22 AM
Code - Auto/Visual Lisp: [Select]
  8-)

FTFY :wink:

** Note - the LISP functions are now hyperlinked to the help documentation.
Title: Re: Setting variables in a file opened by a routine?
Post by: Keith™ on December 17, 2011, 03:43:09 AM
I quit using setcfg and getcfg some years ago after I realized that it was causing the config file to grow and you have to manually remove orphaned entries.

Use the registry and then you can programmatically delete the keys after you no longer need them.
Title: Re: Setting variables in a file opened by a routine?
Post by: TimSpangler on December 17, 2011, 09:24:34 AM
I quit using setcfg and getcfg some years ago after I realized that it was causing the config file to grow and you have to manually remove orphaned entries.

Use the registry and then you can programmatically delete the keys after you no longer need them.
The registry is a great option also.

As long as you keep reusing the same cfg there is no issue with file bloat.  Just another way.  :kewl:
(i.e. "AppData/Vars/var1")

There are also the setenv / getenv variables.

Code - Auto/Visual Lisp: [Select]
*This was for you RenderMan :angel:

All great options as long as the limitations are taken into account.
Title: Re: Setting variables in a file opened by a routine?
Post by: BlackBox on December 17, 2011, 06:07:02 PM

There are also the setenv / getenv variables.

Code - Auto/Visual Lisp: [Select]
*This was for you RenderMan :angel:

 :-P