Author Topic: Storing variables  (Read 14886 times)

0 Members and 1 Guest are viewing this topic.

cadman6735

  • Bull Frog
  • Posts: 255
  • Life is all about the attitude.
Storing variables
« on: March 28, 2011, 02:16:07 PM »
I have 2 questions

1.  What is the simplist way to store a variable for future use, so after AutoCAD has been shut down and re-started I can call this variable?


2.  Why does USERS1 not store a variable in the drawing after saving and shutting down?  What use is this system variable?
  Ability is what you're capable of doing.
  Motivation determines what you do.
  Attitude determines how well you do it.

    Lou Holtz
----------------------------------------------

  Revit Certified Professional

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Re: Storing variables
« Reply #1 on: March 28, 2011, 02:24:59 PM »
If you want something saved int the drawing use xdata.

If you want a global save use a text file or the registry.
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

cadman6735

  • Bull Frog
  • Posts: 255
  • Life is all about the attitude.
Re: Storing variables
« Reply #2 on: March 28, 2011, 02:48:46 PM »
Doesn't xdata just append to the entities dotted pair?  (can't remember the other name for dotted pair)
so I would use a filter to look for the xdata now associated to this element so now my xdata works as the handle?  (in my logic this would make the handle useless)  I know I am missing a bigger picture


Was USERS1-5 not developed for such a task?

USERR1-5
USERI1-5  save to the drawing but USERS1-5 does not, what is USSERS1-5 good for?
  Ability is what you're capable of doing.
  Motivation determines what you do.
  Attitude determines how well you do it.

    Lou Holtz
----------------------------------------------

  Revit Certified Professional

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Re: Storing variables
« Reply #3 on: March 28, 2011, 03:26:53 PM »
xData can be attached to dictionaries. 8-)
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: Storing variables
« Reply #4 on: March 28, 2011, 03:41:53 PM »
I would echo what CAB suggests -

I mostly use text files for storing program settings that I wish to persist between drawing sessions (such as dialog settings), as these are safer and easier for the average user to remove than deleting registry keys.

As for storing data in drawings, if the data pertains to an entity in the drawing (for example, when using an Object Reactor perhaps) I would use the XData (eXtended data) for that entity, otherwise you can create your own dictionaries and add xRecords to those dictionaries (example here), and there is also LData.

Lee

CAB

  • Global Moderator
  • Seagull
  • Posts: 10395
Re: Storing variables
« Reply #5 on: March 28, 2011, 04:52:41 PM »
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Storing variables
« Reply #6 on: March 28, 2011, 05:57:44 PM »
Xdata and Ldata there are not only per drawings ?

maybe (setenv "myenvironnement") ??

or another suggestion...
a config file ? like cfg or ini ?
Keep smile...

Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: Storing variables
« Reply #7 on: March 28, 2011, 07:17:34 PM »
Xdata and Ldata there are not only per drawings ?

I don't follow?

maybe (setenv "myenvironnement") ??

SetEnv is convenient, but one must still remember that the function is writing data to the registry, under the following location:

Code: [Select]
(strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\FixedProfile\\General")
And hence I would be careful not to bloat the registry unnecessarily.

a config file ? like cfg or ini ?

I suppose these would fall under the umbrella 'text file' method...

Aerdvark

  • Guest
Re: Storing variables
« Reply #8 on: March 29, 2011, 01:42:11 AM »
If you want something saved int the drawing use xdata.
If you want a global save use a text file or the registry.

For what I do with lisp, the textfile method suits me best

My reasons:
1. they can be viewed from outside autocad by notepad (handy in case of trouble)
2. also this will give you the ability to check or modify settings
3. you can create any extension like MyTextFile.mtf just rename your *.txt file

My 2 cents.

I see what you mean, the USERI1-5 are stored in the drawing just as the USERR1-5 are.
The USERS1-5 however are NOT. (http://docs.autodesk.com/ACD/2011/ENU/filesACR/WS1a9193826455f5ffa23ce210c4a30acaf-4e0d.htm)
Mind this: I = integer / R = Real / S = string.
Anyway... I assume you need to save a string in a specific drawing so I'd use a textfile or investigate some Xdata options.
« Last Edit: March 29, 2011, 01:48:44 AM by Aerdvark »

Stefan

  • Bull Frog
  • Posts: 255
Re: Storing variables
« Reply #9 on: March 29, 2011, 04:35:04 AM »
2.  Why does USERS1 not store a variable in the drawing after saving and shutting down?

Just a thought ...
Imagine that someone inexperienced download a lisp file that contains something like:

Code: [Select]
(eval (read (getvar "USERS1")))

Imagine now what could be saved in a DWG in USERS1-5 and you have a "perfect bomb" ...

Code: [Select]
(setvar "USERS1" "(vl-registry-delete HKEY_CURRENT_USER\\...  ... )")

... or other "goodies"

Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: Storing variables
« Reply #10 on: March 29, 2011, 07:26:47 AM »
Hmmm... but that 'danger' would exist should a string be stored in the registry, text file, or even if the string was disguised and present in the LISP code itself...

On this topic, I posted some tips on how to spot malicious code in programs here, might be useful to some.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Storing variables
« Reply #11 on: March 29, 2011, 08:11:22 AM »
I strongly suggest to not use the "USERS*" variables..
for the simple reason that to many program use it.

we had several problem with that on our offices..
and cause conflictual uncompatible problem between thirdparty software.

LDATA = saved by drawing
Xdata = saved by Entity
Vl-Registry-write = saved by PC
setenv = save data on registry without having administrative right.
(open "x:\\config\\yourfile.txt" "w") = allow you to store anything and share those info with your collegue over a network if you want. sure you can use any king of extension file and eaven...no extension.

so it is depend what the objective is.

Regards.

Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Storing variables
« Reply #12 on: March 29, 2011, 08:54:22 AM »

Personally I'd use XRecords ... the data sounds like it should stay with the document.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

cadman6735

  • Bull Frog
  • Posts: 255
  • Life is all about the attitude.
Re: Storing variables
« Reply #13 on: March 29, 2011, 09:56:27 AM »
Quote
LDATA = saved by drawing
Xdata = saved by Entity
Vl-Registry-write = saved by PC
setenv = save data on registry without having administrative right.
(open "x:\\config\\yourfile.txt" "w") = allow you to store anything and share those info with your collegue over a network if you want. sure you can use any king of extension file and eaven...no extension.
This is a great breakdown for my feeble mind, thanks

I am reading AfraLisp Dictionary
What is an example I could use a dictionary for?  (not code, just an idea)

From what I understand:
  - Xdata appends to an existing entity assoiciation list
  - Dictionary is a container of entities or objects
  - Xrecord is the assoiciated list (dotted pair) of an entity or object inside of a dictionary
  - ENTMAKEX is act of creating an object without an owner.  Meaning it is a man made dictionary and a man made entity (inside this dictionary)...  The meaning of "no owner" is that this container (dictionary) did not exist until I created it, so it is not associated to any existing dictionary?
  Ability is what you're capable of doing.
  Motivation determines what you do.
  Attitude determines how well you do it.

    Lou Holtz
----------------------------------------------

  Revit Certified Professional

laidbacklarry

  • Guest
Re: Storing variables
« Reply #14 on: March 29, 2011, 01:18:37 PM »
Just another thought... XData can also be attached to Layers (and other Table objects). Attach your data to Layer "0" and it's pretty secure since you can't delete layer 0.

We started using this technique as soon as XData was introduced, before Dictionaries, LData, etc., and as long as you don't exceed the XData limit of 16K (I think), it works well. We store over 200 of our application specific "system" variables with this method.

Text files (.ini files) are used to store the initial settings, but if the variables need to change value from drawing to drawing, this system works.

We also use XData attached to entities and blocks. If XData had existed in the mid-80s, there would have no need for us to use attributes.