Author Topic: Store Data in AUTOCAD file  (Read 4190 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 473
Store Data in AUTOCAD file
« on: March 04, 2015, 12:00:22 PM »
Dear All,

I want to store some data in AUTOCAD file. For example, as soon as an AUTOCAD file is opened on any computer, the computer name, date and time must be recorded automatically. When the same file is opened in another computer, the same information must be stored in addition to the earlier information.

Also, this information must be hidden from the users of the file but should be retrievable by me using LISP.

How to do so ?







ronjonp

  • Needs a day job
  • Posts: 7327
Re: Store Data in AUTOCAD file
« Reply #1 on: March 04, 2015, 12:04:37 PM »
You could use xdata.

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 20 Ultimate
Re: Store Data in AUTOCAD file
« Reply #2 on: March 04, 2015, 12:06:49 PM »
Do a search here on use of dictionaries, could be a very easy task to accomplish.

You will need to load a lisp function in your acad.lsp startup function, so to get it to work on computers outside your control will be tough to accomplish.


Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: Store Data in AUTOCAD file
« Reply #4 on: March 04, 2015, 12:36:05 PM »
Here's a concept Modification Logging Utility that I wrote as an example quite recently - it may give you some ideas.

Lee

mailmaverick

  • Bull Frog
  • Posts: 473
Re: Store Data in AUTOCAD file
« Reply #5 on: March 04, 2015, 01:03:12 PM »
Here's a concept Modification Logging Utility that I wrote as an example quite recently - it may give you some ideas.

Lee

Excellent Lee !!! This is quite similar to what I wanted. Once again, Lee to the rescue.

I have seen that you have used Group Code -3. How come we can use a negative Group Code ?

Also, apart from -3, what other Group Codes can we assign to an entity which do not interfere with the AUTOCAD's predefined group codes ?

Also, you have assigned the data to an entity. How can we assign the data to a drawing file (not an entity).


ronjonp

  • Needs a day job
  • Posts: 7327
Re: Store Data in AUTOCAD file
« Reply #6 on: March 04, 2015, 02:30:27 PM »
Here's another .. you can choose what you'd like the data written to. My example writes to layer 0.

Code - Auto/Visual Lisp: [Select]
  1. (defun _xdatalogger (ename appname / data el)
  2.   (if (and (= 1 (getvar 'dwgtitled))
  3.            (= (type ename) 'ename)
  4.            (or (tblobjname "APPID" appname) (regapp appname))
  5.            (setq el (entget ename (list appname)))
  6.       )
  7.     (progn
  8.       (setq data (strcase (strcat (getenv "computername")
  9.                                   "_"
  10.                                   (getenv "username")
  11.                                   "_"
  12.                                   (rtos (getvar 'cdate) 2 4)
  13.                           )
  14.                  )
  15.       )
  16.       (if (not (wcmatch (vl-princ-to-string (cdr (assoc -3 el))) (strcat "*" data "*")))
  17.         (entmod
  18.           (append
  19.             (vl-remove (assoc -3 el) el)
  20.             (list (list -3 (append (list appname) (list (cons 1000 data)) (cdadr (assoc -3 el)))))
  21.           )
  22.         )
  23.       )
  24.     )
  25.   )
  26.   (princ)
  27. )
  28. (defun _readxdatalogger (ename appname)
  29.   (if (= (type ename) 'ename)
  30.     (mapcar 'print (mapcar 'cdr (cdadr (assoc -3 (entget ename (list appname))))))
  31.   )
  32. )
  33. ;; Log to layer 0
  34. (_xdatalogger (tblobjname "layer" "0") "MyDataLogger")
  35. ;; Read data
  36. (_readxdatalogger (tblobjname "layer" "0") "MyDataLogger")
  37.  
« Last Edit: March 04, 2015, 03:12:40 PM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

mailmaverick

  • Bull Frog
  • Posts: 473
Re: Store Data in AUTOCAD file
« Reply #7 on: March 04, 2015, 03:37:39 PM »
Dear RONJONP, I am confused by your LISP.

Please explain how can we write data to a layer when a layer is not an entity like a circle, polyline etc.




ronjonp

  • Needs a day job
  • Posts: 7327
Re: Store Data in AUTOCAD file
« Reply #9 on: March 04, 2015, 03:52:52 PM »
Dear RONJONP, I am confused by your LISP.

Please explain how can we write data to a layer when a layer is not an entity like a circle, polyline etc.

Quote from: mailmaverick
Also, you have assigned the data to an entity. How can we assign the data to a drawing file (not an entity).

I thought you wanted to write the data to the "drawing" .. figured layer 0 is part of every drawing so I used it as an example. It does not have to be layer 0 that you write to. The function gives you flexibility to write to whatever makes you happy. :)
« Last Edit: March 04, 2015, 03:58:48 PM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: Store Data in AUTOCAD file
« Reply #10 on: March 04, 2015, 05:52:51 PM »
Here's a concept Modification Logging Utility that I wrote as an example quite recently - it may give you some ideas.

Lee

Excellent Lee !!! This is quite similar to what I wanted. Once again, Lee to the rescue.

You're most welcome  :-)

I have seen that you have used Group Code -3. How come we can use a negative Group Code ?

Also, apart from -3, what other Group Codes can we assign to an entity which do not interfere with the AUTOCAD's predefined group codes ?

All Extended Entity Data (xData) is stored under DXF group -3; I would recommend that you first read up on xData, perhaps starting here.

Also, you have assigned the data to an entity. How can we assign the data to a drawing file (not an entity).

For this I would personally use a dictionary defined under the Named Object Dictionary (namedobjdict)


ronjonp

  • Needs a day job
  • Posts: 7327
Re: Store Data in AUTOCAD file
« Reply #11 on: March 04, 2015, 11:54:49 PM »

.....

For this I would personally use a dictionary defined under the Named Object Dictionary (namedobjdict)


I was thinking that too but after a quick test, the data gets lost if the drawing is wblocked.  :|

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Store Data in AUTOCAD file
« Reply #12 on: March 05, 2015, 12:36:46 AM »
Not if you make it hard owned. Search the swamp for same. :)
Engineering Technologist CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

mailmaverick

  • Bull Frog
  • Posts: 473
Re: Store Data in AUTOCAD file
« Reply #13 on: March 05, 2015, 04:28:43 AM »
All Extended Entity Data (xData) is stored under DXF group -3; I would recommend that you first read up on xData, perhaps starting here.
For this I would personally use a dictionary defined under the Named Object Dictionary (namedobjdict)

Thanks to Lee for all his inputs.

I thought you wanted to write the data to the "drawing" .. figured layer 0 is part of every drawing so I used it as an example. It does not have to be layer 0 that you write to. The function gives you flexibility to write to whatever makes you happy. :)

Dear Ron, I agree that I want to write the data to a drawing and not an entity. But i did not know that you can write data to a layer also. In that case, can we write such datas to Dimension Styles, Text Styles etc ?

Is there any comprehensive list of AUTOCAD objects which support data writing ? If any link is available, please let me know.


ronjonp

  • Needs a day job
  • Posts: 7327
Re: Store Data in AUTOCAD file
« Reply #14 on: March 05, 2015, 09:02:17 AM »
...
Is there any comprehensive list of AUTOCAD objects which support data writing ? If any link is available, please let me know.
There is a list of supported objects in the HELP file :)

Quote from: AutoCAD Help File
object
Type: All drawing objects, AttributeReference, Block, Dictionary, Dimension, DimStyle, Group, Layer, Layout, Linetype, Material, MLeaderStyle, PlotConfiguration, RegisteredApplication, TableStyle, TextStyle, UCS, View, Viewport, XRecord
The object this method applies to.

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC