TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mailmaverick on March 04, 2015, 12:00:22 PM

Title: Store Data in AUTOCAD file
Post by: mailmaverick 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 ?






Title: Re: Store Data in AUTOCAD file
Post by: ronjonp on March 04, 2015, 12:04:37 PM
You could use xdata (https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=site:theswamp.org+xdata).
Title: Re: Store Data in AUTOCAD file
Post by: snownut2 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.
Title: Re: Store Data in AUTOCAD file
Post by: CAB on March 04, 2015, 12:09:05 PM
Some links:
-----------  Ldata - xData -------------
http://www.theswamp.org/index.php?topic=30445.0 Quick XData Functions by Lee Mac
http://www.theswamp.org/index.php?topic=31804.0
http://www.theswamp.org/index.php?topic=5003.0  MP - dictionaries and xRecords
http://www.theswamp.org/index.php?topic=17203.msg207853#msg207853 Remove xData by MP
http://www.theswamp.org/index.php?topic=1283.0  Ldata vs xData
http://www.theswamp.org/index.php?topic=4395.0
http://www.theswamp.org/index.php?topic=8829.0 
http://www.theswamp.org/index.php?topic=29381.0
http://www.theswamp.org/index.php?topic=23294.msg281024#msg281024 Ldata
http://www.theswamp.org/index.php?topic=29564.0
http://www.theswamp.org/index.php?topic=18490.0  Ldata example
http://www.afralisp.net/autolisp/tutorials/dictionaries-and-xrecords.php  xRecord
http://cadtips.cadalyst.com/node/tiplisting?keywords=1756  Message Store Routine

  Data Structures
http://www.theswamp.org/index.php?topic=37660.msg427038#msg427038 LeeMac
Title: Re: Store Data in AUTOCAD file
Post by: Lee Mac on March 04, 2015, 12:36:05 PM
Here (http://bit.ly/127drDl)'s a concept Modification Logging Utility that I wrote as an example quite recently - it may give you some ideas.

Lee
Title: Re: Store Data in AUTOCAD file
Post by: mailmaverick on March 04, 2015, 01:03:12 PM
Here (http://bit.ly/127drDl)'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).

Title: Re: Store Data in AUTOCAD file
Post by: ronjonp 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.  
Title: Re: Store Data in AUTOCAD file
Post by: mailmaverick 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.


Title: Re: Store Data in AUTOCAD file
Post by: mailmaverick on March 04, 2015, 03:44:52 PM
Some links:
-----------  Ldata - xData -------------
http://www.theswamp.org/index.php?topic=30445.0 Quick XData Functions by Lee Mac
http://www.theswamp.org/index.php?topic=31804.0
http://www.theswamp.org/index.php?topic=5003.0  MP - dictionaries and xRecords
http://www.theswamp.org/index.php?topic=17203.msg207853#msg207853 Remove xData by MP
http://www.theswamp.org/index.php?topic=1283.0  Ldata vs xData
http://www.theswamp.org/index.php?topic=4395.0
http://www.theswamp.org/index.php?topic=8829.0 
http://www.theswamp.org/index.php?topic=29381.0
http://www.theswamp.org/index.php?topic=23294.msg281024#msg281024 Ldata
http://www.theswamp.org/index.php?topic=29564.0
http://www.theswamp.org/index.php?topic=18490.0  Ldata example
http://www.afralisp.net/autolisp/tutorials/dictionaries-and-xrecords.php  xRecord
http://cadtips.cadalyst.com/node/tiplisting?keywords=1756  Message Store Routine

  Data Structures
http://www.theswamp.org/index.php?topic=37660.msg427038#msg427038 LeeMac

I appreciate the comprehensive links list dear CAB.
Title: Re: Store Data in AUTOCAD file
Post by: ronjonp 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. :)
Title: Re: Store Data in AUTOCAD file
Post by: Lee Mac on March 04, 2015, 05:52:51 PM
Here (http://bit.ly/127drDl)'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 (http://www.afralisp.net/autolisp/tutorials/extended-entity-data-part-1.php).

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)

Title: Re: Store Data in AUTOCAD file
Post by: ronjonp 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.  :|
Title: Re: Store Data in AUTOCAD file
Post by: MP on March 05, 2015, 12:36:46 AM
Not if you make it hard owned. Search the swamp for same. :)
Title: Re: Store Data in AUTOCAD file
Post by: mailmaverick 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 (http://www.afralisp.net/autolisp/tutorials/extended-entity-data-part-1.php).
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.

Title: Re: Store Data in AUTOCAD file
Post by: ronjonp 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 (http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-EF0393EC-8446-4989-8C72-F3AE49D81176) 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.
Title: Re: Store Data in AUTOCAD file
Post by: ronjonp on March 05, 2015, 09:04:50 AM
Not if you make it hard owned. Search the swamp for same. :)
Will do Michael .. thanks  :)
Title: Re: Store Data in AUTOCAD file
Post by: Jeff H on March 05, 2015, 04:37:36 PM
You can add data to anything that derives from AcDbObject  object. So any object that can be saved in a autocad file or another way of putting it is a whole butt-load

Now most of these objects have many objects derived from them like a layer that derives from symbolTableRecord
 
Quote
           
            AcDbAssocAction
            AcDbAssocActionBody
            AcDbAssocActionParam
            AcDbAssocDependency
            AcDbAssocDependencyBody
            AcDbAssocManager
            AcDbBackground
            AcDbBreakData
            AcDbBreakPointRef
            AcDbColor
            AcDbDataLink
            AcDbDataTable
            AcDbDictionary
            AcDbDimAssoc
            AcDbEntity
            AcDbEvalExpr
            AcDbEvalGraph
            AcDbField
            AcDbFilter
            AcDbGeoData
            AcDbGroup
            AcDbIndex
            AcDbLinkedData
            AcDbLongTransaction
            AcDbMaterial
            AcDbMLeaderStyle
            AcDbMlineStyle
            AcDbModelDocViewStyle
            AcDbMotionPath
            AcDbNamedPath
            AcDbPlaceHolder
            AcDbPlotSettings
            AcDbPointCloudColorMap
            AcDbPointCloudDefEx
            AcDbPointCloudDefReactorEx
            AcDbProxyObject
            AcDbRasterImageDef
            AcDbRasterImageDefReactor
            AcDbRasterVariables
            AcDbRenderEnvironment
            AcDbRenderGlobal
            AcDbRenderSettings
            AcDbSectionManager
            AcDbSectionSettings
            AcDbSortentsTable
            AcDbSun
            AcDbSymbolTable
            AcDbSymbolTableRecord
                 AcDbAbstractViewTableRecord
                 AcDbBlockTableRecord
                 AcDbDimStyleTableRecord
                 AcDbLayerTableRecord
                 AcDbLinetypeTableRecord
                 AcDbRegAppTableRecord
                 AcDbTextStyleTableRecord
                 AcDbUCSTableRecord
            AcDbTableStyle
            AcDbUnderlayDefinition
            AcDbVisualStyle
            AcDbXrecord