Author Topic: Save application settings on dwg  (Read 4196 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Save application settings on dwg
« on: February 15, 2015, 08:07:26 AM »
Hello everyone,
I made an application vlisp, requiring many settings (30).
Currently I have saved these settings to a text file that is written and read by the application.

However I'd like to save these settings directly in the dwg files so that each dwg file can have different settings.

is it possible?
Have you any suggestions?

Thanks in advance.

Lee Mac

  • Seagull
  • Posts: 12927
  • London, England
Re: Save application settings on dwg
« Reply #1 on: February 15, 2015, 09:13:50 AM »
Use a Dictionary.


Lupo76

  • Bull Frog
  • Posts: 343
Re: Save application settings on dwg
« Reply #3 on: February 15, 2015, 12:32:55 PM »
Use a Dictionary.

Very interesting!
Tomorrow I will have a lot to learn ;-)

Thank You.

Lupo76

  • Bull Frog
  • Posts: 343
Re: Save application settings on dwg
« Reply #4 on: February 15, 2015, 12:33:56 PM »
For 30 info you can use Xdata also.


mmmmm ... I use the xdata order to associate an object, but I would not know how to use them in this context :-(

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: Save application settings on dwg
« Reply #5 on: February 15, 2015, 01:01:00 PM »
..


mmmmm ... I use the xdata order to associate an object, but I would not know how to use them in this context :(

You can add XData to layer 0, it is a little trick. That layer is always there. And so are your settings.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Save application settings on dwg
« Reply #6 on: February 15, 2015, 01:10:00 PM »
Given a general description of "a program with settings" a dictionary is the right approach. The xdata on layer "0" (or similar prime table entry) trick is not the best approach since it's a sandbox anyone privvy to the trick can frolic in. It's not what a professionally written program would lean on IMO, so I can't advocate it, admitting I've done same many years ago (as a means of thwarting purging -- a hard owned dictionary is as robust). No hate, just sayin. And now off to work ... cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lupo76

  • Bull Frog
  • Posts: 343
Re: Save application settings on dwg
« Reply #7 on: February 16, 2015, 03:00:41 AM »
Use a Dictionary.

I am studying the topic and doing some tests.
I understand that the various settings of my application must be entered on a list like this

(7 . "Setting1")
(8 . "Setting2")
(9 . "Setting3")
etc.

I would like to give a name to my settings.
Eg.
NameLayerWall="LayerWall"
ColLayerWall="5"
etc.

and then call up the various settings with a specially written routin
eg.
(setq LayWall (ReadSetting "NameLayerWall"))

Can I do this with Dictionaries and XRecord?
or I am forced to associate each setting a numerical code?

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Save application settings on dwg
« Reply #8 on: February 16, 2015, 03:46:53 AM »
..


mmmmm ... I use the xdata order to associate an object, but I would not know how to use them in this context :(

You can add XData to layer 0, it is a little trick. That layer is always there. And so are your settings.
Yes, I am using it from many years (+15?), no problem.
For complex data dictionary is more robust (and complex), this is a very good (old) example:

;; SaveData.lsp
;; Save *any* variable with the DWG
;;    Written  Nov 30, 1997.
;;    Updated for r15 and xdict-* functions added Dec 7, 1999.
;;
;;*************************************************************
;;   Copyright Vladimir Nesterovsky 1997, All Rights Reserved

http://vnestr.tripod.com/SaveData.lsp

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Save application settings on dwg
« Reply #9 on: February 17, 2015, 05:24:42 AM »
I think that Ldata, which is also stored in dictionaries, should be mentioned here.

I have heard that there have been issues in the past with Ldata: applications would crash, drawings would become corrupt and Autodesk, apparently, was less than completely honest about it all. If I remember the stories correctly, these problems occurred around the time of Release 14 or AutoCAD 2000. I have not heard of problems with Ldata in recent versions of AutoCAD.

The convenience of Ldata is that you do not need any special code to store Lisp data (=Ldata).
There are 5 built-in functions to deal with Ldata:
Code: [Select]
vlax-ldata-delete
vlax-ldata-get
vlax-ldata-list
vlax-ldata-put
vlax-ldata-test

Example:
Code: [Select]
(vlax-ldata-put "myDict" "myKey" '((STRING . "Abc") (POINT 1.0 2.0 3.0)))
(vlax-ldata-get "myDict" "myKey") => ((STRING . "Abc") (POINT 1.0 2.0 3.0))

To prove that Ldata is stored in a dictionary:
Code: [Select]
(dictsearch (cdr (assoc -1 (dictsearch (namedobjdict) "myDict"))) "myKey")
=>
(
  (-1 . <Entity name: cb2da80>)
  (0 . "VLO-VL")
  (5 . "3DF")
  (102 . "{ACAD_REACTORS")
  (330 . <Entity name: 18bab280>)
  (102 . "}")
  (330 . <Entity name: 18bab280>)
  (100 . "vlo_VL")
  (90 . -64512)
  (91 . 65)
  (92 . 3)
  (40 . 1.0)
  (40 . 2.0)
  (40 . 3.0)
  (300 . "((STRING . \"Abc\") (POINT (&VLO-R . 0) (&VLO-R . 1) (&VLO-R . 2)))")
)

Ldata can also be attached to a drawing entity. It is then stored in the extension dictionary of the entity.
« Last Edit: February 17, 2015, 05:28:11 AM by roy_043 »

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Save application settings on dwg
« Reply #10 on: February 17, 2015, 07:11:19 PM »
One problem with LDATA: if a drawing is opened before the VL support is loaded, you'll get a proxy warning.  One of the reasons why I abandoned its use quite a while back.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Save application settings on dwg
« Reply #11 on: February 17, 2015, 08:54:03 PM »
LData is never used in polite conversations.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Save application settings on dwg
« Reply #12 on: February 18, 2015, 05:24:03 AM »
One problem with LDATA: if a drawing is opened before the VL support is loaded, you'll get a proxy warning.  One of the reasons why I abandoned its use quite a while back.
Being a BricsCAD user I didn't know about this problem. (vl-load-com) is a dummy function in BricsCAD and VL support is always available. Thanks for pointing this out.