Author Topic: Xdata vs Ldata  (Read 10536 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3251
  • Marko Ribar, architect
Xdata vs Ldata
« on: March 01, 2013, 06:22:36 AM »
Somewhere I read that xdata is more reliable than ldata... Can't find where I read this... Some thoughts if you know...

Thanks, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

togores

  • Guest
Re: Xdata vs Ldata
« Reply #1 on: March 01, 2013, 06:40:21 AM »
Somewhere I read that xdata is more reliable than ldata... Can't find where I read this... Some thoughts if you know...
Hi Marko, I quote here some considerations on this subject from my book "AutoCAD expert's Visual LISP", Chapter 23:
Quote
ActiveX Functions for XDATA, XRECORD and Dictionaries.
XDATA, XRECORD and Dictionaries  emerged in the pre-ActiveX AutoCAD era. Although there are equivalent ActiveX methods and properties, processing from Visual LISP functions has no disadvantages. Quite the contrary, the ease with which LISP creates and processes data lists represents an advantage over ActiveX methods that require packing data as safearrays.
But there is a simpler set of ActiveX dictionary functions. These dictionaries belong to a special type known as LDATA. We already used this format in the Chapter 1 Tutorial.
 LDATA functions can save a lot of programming effort.  In the following section we will summarize the use of these functions when dealing to storing non-graphical information in the drawing, with or without links to graphic entities.
23.5 LDATA Dictionaries.
We can distinguish between two different types of dictionary objects: the LDATA dictionary aimed at storing information in LISP format and dictionary objects composed by XRECORD entities in which information is managed using a DXF style coding. As we have seen, the XRECORD object dictionaries require considerable programming effort. But for LDATA dictionaries, Visual LISP provides a set of functions that ease their use.
Caution should be exercised when using this kind of object because the LDATA information for Release 2000 and above is not compatible with AutoCAD Release 14. If the drawing is saved in R14 drawing format information may be lost or corrupted. Although it's not likely today, a drawing to be used with such an old version should use XRECORD dictionaries. But everything is relative, since we know that XRECORD would be lost when using the drawing in a release prior to R13c4, and XDATA would only survive the round trip to Release 11, but not beyond it.
There is no specific function for the creation of LDATA dictionaries. Adding data will automatically create them. The dictionary can exist by itself in the drawing with a name that identifies it, but it can also be attached to any drawing object.
You can find more information in my blog http://lispexpert.blogspot.com/
Hope this helps...
« Last Edit: March 01, 2013, 06:43:39 AM by togores »

ribarm

  • Gator
  • Posts: 3251
  • Marko Ribar, architect
Re: Xdata vs Ldata
« Reply #2 on: March 01, 2013, 07:34:59 AM »
Thanks, togores, though I have one direct question... How can I obtain list of all registered dictionary names registered through (vlax-ldata-put) function?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Xdata vs Ldata
« Reply #3 on: March 01, 2013, 10:25:45 AM »
One thing I've noted with LDATA, is if a drawing with LDATA is opened and (vl-load-com) has *not* been called the proxy warning dialog will warn about VL data, similar to if a drawing has C3D or other proxy objects.
If you are going to fly by the seat of your pants, expect friction burns.

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

ribarm

  • Gator
  • Posts: 3251
  • Marko Ribar, architect
Re: Xdata vs Ldata
« Reply #4 on: March 01, 2013, 10:50:30 AM »
Yes, I've noticed that too...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

togores

  • Guest
Re: Xdata vs Ldata
« Reply #5 on: March 01, 2013, 04:54:15 PM »
Thanks, togores, though I have one direct question... How can I obtain list of all registered dictionary names registered through (vlax-ldata-put) function?
This is a bit complicated, as LDATA dictionaries may be "named" or can be assigned to an entity. If it is named, it will be included in the Named Object Dicionary:
Code: [Select]
_$ (vlax-ldata-put "TESTDICT" "DATA1" "THIS IS A TEST")
"THIS IS A TEST"
_$ (vlax-ldata-get "TESTDICT" "DATA1")
"THIS IS A TEST"
_$ (entget (namedobjdict))
((-1 . <Entity name: 7ffff7038c0>)
  (0 . "DICTIONARY")
  (330 . <Entity name: 0>)
  (5 . "C")
  (100 . "AcDbDictionary")
  (280 . 0)
  (281 . 1)
  (3 . "ACAD_CIP_PREVIOUS_PRODUCT_INFO")
  (350 . <Entity name: 7ffff7049e0>)
  (3 . "ACAD_COLOR")
  (350 . <Entity name: 7ffff703bb0>)
  (3 . "ACAD_DETAILVIEWSTYLE")
  (350 . <Entity name: 7ffff704a30>)
  (3 . "ACAD_GROUP")
  (350 . <Entity name: 7ffff7038d0>)
  (3 . "ACAD_LAYOUT")
  (350 . <Entity name: 7ffff7039a0>)
  (3 . "ACAD_MATERIAL")
  (350 . <Entity name: 7ffff703ba0>)
  (3 . "ACAD_MLEADERSTYLE")
  (350 . <Entity name: 7ffff704150>)
  (3 . "ACAD_MLINESTYLE")
  (350 . <Entity name: 7ffff703970>)
  (3 . "ACAD_PLOTSETTINGS")
  (350 . <Entity name: 7ffff703990>)
  (3 . "ACAD_PLOTSTYLENAME")
  (350 . <Entity name: 7ffff7038e0>)
  (3 . "ACAD_SCALELIST")
  (350 . <Entity name: 7ffff7040c0>)
  (3 . "ACAD_SECTIONVIEWSTYLE")
  (350 . <Entity name: 7ffff704a10>)
  (3 . "ACAD_TABLESTYLE")
  (350 . <Entity name: 7ffff703c60>)
  (3 . "ACAD_VISUALSTYLE")
  (350 . <Entity name: 7ffff703ef0>)
  (3 . "AcDbVariableDictionary")
  (350 . <Entity name: 7ffff703ae0>)
  (3 . "TESTDICT") ;; this is our dictionary
  (350 . <Entity name: 7ffff704b50>))
If assigned to an entity it will be included as its Extension Dictionary:
Code: [Select]
_$ (vlax-ldata-put (entlast) "ENTDATA1" "THIS IS ATTACHED TO A CIRCLE")
"THIS IS ATTACHED TO A CIRCLE"
_$ (entget (entlast))
((-1 . <Entity name: 7ffff704be0>)
  (0 . "CIRCLE")
  (5 . "236")
  (102 . "{ACAD_XDICTIONARY")
  (360 . <Entity name: 7ffff704bf0>) ;; this ename can be used to get the extension dictionary
  (102 . "}")
  (330 . <Entity name: 7ffff7039f0>)
  (100 . "AcDbEntity")
  (67 . 0)
  (410 . "Model")
  (8 . "0")
  (100 . "AcDbCircle")
  (10 2328.9 2020.6 0.0)
  (40 . 178.42)
  (210 0.0 0.0 1.0))
_$ (entget (cdr (assoc 360 (entget (entlast)))))
((-1 . <Entity name: 7ffff704bf0>)
  (0 . "DICTIONARY")
  (330 . <Entity name: 7ffff704be0>)
  (5 . "237")
  (100 . "AcDbDictionary")
  (280 . 1)
  (281 . 1)
  (3 . "ENTDATA1") ;; this is our dictionary's name
  (360 . <Entity name: 7ffff704c00>))
In my acaddoc.lsp I include a call to (vla-load-com) as I use a lot of ActiveX functions in my code, so I don't get the warning message about ActiveX not being loaded.
But on a second thought, something against using LDATA would be that it is not compatible with AutoCAD for MAC. And it seem the future would point to a multiplatform application instead of Windows-only...

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Xdata vs Ldata
« Reply #6 on: March 01, 2013, 05:25:11 PM »
Note also that LData is stored usig VLO-VL entities, rather than XRECORD entities, as the following code demonstrates:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( )
  2.     (vlax-ldata-put "MyDict" "MyKey" "MyData")
  3.     (mapcar 'print (dictsearch (cdr (assoc -1 (dictsearch (namedobjdict) "MyDict"))) "MyKey"))
  4.     (princ)
  5. )

ribarm

  • Gator
  • Posts: 3251
  • Marko Ribar, architect
Re: Xdata vs Ldata
« Reply #7 on: March 01, 2013, 05:45:22 PM »
It seems that, once they are stored (LDATA) it's pretty hard to remove them all in one shot - or I am wrong - there is something similar to this code I've used to remove XDATAs and their corresponding APPIDs :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:remallregappids+Xdatas ( / ss app appnlst appea )
  2.   (setq ss (ssget "_X"))
  3.     (foreach app (cdr (assoc -3 (entget (vlax-vla-object->ename x) (list "*"))))
  4.       (entmod (list (cons -1 (vlax-vla-object->ename x)) (list -3 (list (car app)))))
  5.       (setq appnlst (cons (car app) appnlst))
  6.     )
  7.   )
  8.   (setq appnlst (acet-list-remove-duplicates appnlst nil))
  9.   (foreach appn appnlst
  10.     (setq appea (vlax-ename->vla-object (tblobjname "APPID" appn)))
  11.     (vla-delete appea)
  12.     (vlax-release-object appea)
  13.   )
  14.   (princ)
  15. )
  16. (defun c:rappX nil (c:remallregappids+Xdatas))
  17. (prompt "\nShortcut for c:remallregappids+Xdatas is c:rappX ; Start with : Command: rappX")
  18.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

hermanm

  • Guest
Re: Xdata vs Ldata
« Reply #8 on: March 02, 2013, 02:29:30 PM »
One thing to keep in mind is accessibility of the data from other APIs.
I dimly recall a post by Tony T (who else?) showing how to access LDATA from .NET, but my memory may be faulty. There is no direct .NET interface to VLO-VL objects, AFAIK.
XDATA, clumsy as it is, is fully acccessible via .NET

ribarm

  • Gator
  • Posts: 3251
  • Marko Ribar, architect
Re: Xdata vs Ldata
« Reply #9 on: March 03, 2013, 04:24:49 AM »
It seems that there is a way and for LDATA... If someone wants to remove them all, there is nothing you can do about it to prevent him/she from doing it...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:remallLdata ( / d ed dn eddn edddn ss e el el360 el360360 )
  2.   (setq ed (entget d))
  3.   (setq ed (member (assoc 3 ed) ed))
  4.   (while ed
  5.     (setq dn (cdr (assoc 3 ed)))
  6.     (setq eddn (dictsearch d dn))
  7.     (setq eddn (member (assoc 3 eddn) eddn))
  8.     (while eddn
  9.       (if (assoc 350 eddn)
  10.         (progn
  11.           (setq edddn (entget (cdr (assoc 350 eddn))))
  12.           (if (and (eq (cdr (assoc 0 edddn)) "VLO-VL") (assoc 300 edddn))
  13.             (dictremove d dn)
  14.           )
  15.         )
  16.       )
  17.       (setq eddn (cddr eddn))
  18.     )
  19.     (setq ed (cddr ed))
  20.   )
  21.   (setq ss (ssget "_X"))
  22.     (setq e (vlax-vla-object->ename x))
  23.     (setq el (entget e))
  24.     (if (assoc 360 el)
  25.       (progn
  26.         (setq el360 (entget (cdr (assoc 360 el))))
  27.         (while (assoc 3 el360)
  28.           (setq el360360 (entget (cdr (assoc 360 el360))))
  29.           (if (and (eq (cdr (assoc 0 el360360)) "VLO-VL") (assoc 300 el360360))
  30.             (entdel (cdr (assoc -1 el360360)))
  31.           )
  32.           (setq el360 (entget (cdr (assoc -1 el360))))
  33.         )
  34.       )
  35.     )
  36.   )
  37.   (princ)
  38. )
  39.  

So, these 2 codes with purging all objects can make dwg size smaller, but with less data... :-D
« Last Edit: March 03, 2013, 11:15:05 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Xdata vs Ldata
« Reply #10 on: March 03, 2013, 08:32:02 AM »
Marko, you may find the dictnext function easier to use when iterating over dictionaries, e.g.:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:remldata ( / dic ent enx lst nod xdc )
  2.     (setq nod (namedobjdict))
  3.     (while (setq dic (cdr (assoc -1 (dictnext nod (null dic)))))
  4.         (if (= "VLO-VL" (cdr (assoc 0 (dictnext dic t))))
  5.             (setq lst (cons dic lst))
  6.         )
  7.     )
  8.     (foreach ent lst (entdel ent))
  9.     (setq ent (entnext))
  10.     (while ent
  11.         (if (and
  12.                 (member '(102 . "{ACAD_XDICTIONARY") (setq enx (entget ent)))
  13.                 (setq xdc (cdr (assoc 360 enx)))
  14.                 (= "VLO-VL" (cdr (assoc 0 (dictnext xdc t))))
  15.             )
  16.             (entdel xdc)
  17.         )
  18.         (setq ent (entnext ent))
  19.     )
  20.     (princ)
  21. )

Though, I have never attempted to delete an Extension Dictionary, so I am unsure whether that part of the code is correct.

ribarm

  • Gator
  • Posts: 3251
  • Marko Ribar, architect
Re: Xdata vs Ldata
« Reply #11 on: March 03, 2013, 08:43:55 AM »
I've changed little more my last code for remallLdata, as I didn't take in consideration multiple ldata-put to each single entity... Now it works as I wanted...

Thanks, Lee... Still my first question stands : What is better Xdata or Ldata and why?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Xdata vs Ldata
« Reply #12 on: March 03, 2013, 10:40:13 AM »
Still my first question stands : What is better Xdata or Ldata and why?
Here's a quote from a post by Tony Tanzillo on the Autodesk Lisp forum, from back in 2004. I have never used LData based on this.
Quote from: Tony T
LDATA is just a way to 'encrypt' your data in a dictionary, using a custom object. In fact, in some circumstances (opening a file by double- clicking in explorer) you can see proxy notices when you open a file with LDATA. The only thing LDATA offers is that it preserves the original list structure, which is something that is useful only to entry level programmers. The disadvantages is that it is a way to lock your data up in a way that can potentially render it completely inaccessible, which is what happened when R14 drawings were migrated to AutoCAD 2000. You can use Dictionaries and XRecords to store anything you can store in LDATA and can access it via any API you might choose to use. In short, stay as far away from LDATA as you can possibly get.
Here's the link to the thread I found that in: http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/What-about-ldata/m-p/941043#M139521
« Last Edit: March 03, 2013, 10:43:47 AM by Jeff_M »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Xdata vs Ldata
« Reply #13 on: March 03, 2013, 11:21:55 AM »
Are we not sufficiently beyond R14 that we no longer worry about that problem?
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.

owenwengerd

  • Bull Frog
  • Posts: 451
Re: Xdata vs Ldata
« Reply #14 on: March 03, 2013, 12:26:19 PM »
Are we not sufficiently beyond R14 that we no longer worry about that problem?

The problem was not R14. The problem was that Autodesk changed the data format. We're most certainly not beyond that problem. Personally, I wouldn't touch ldata with a ten foot pole. There are a lot of potential pitfalls with ldata, and just no real benefit over xrecords.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Xdata vs Ldata
« Reply #15 on: March 03, 2013, 01:03:02 PM »
I just meant that R14 was the change in format not R14 was bad.
If there are no other changes in format the post R14 systems should be OK.
Should professional programers use Ldata, No.
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.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Xdata vs Ldata
« Reply #16 on: March 03, 2013, 02:04:45 PM »
But the point is, Alan, if Autodesk changed the LDATA format between R14 and R2000, what's to stop them from doing it again between 2013 & 2014? Granted, there's been a number of years where it has remained unchanged so the likelihood of it being changed again is slim.

Besides all of that, the main reason I posted that quote was for the last line of it "In short, stay as far away from LDATA as you can possibly get.". IMHO, when Tony suggests something it's usually for a very good reason.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Xdata vs Ldata
« Reply #17 on: March 03, 2013, 03:24:09 PM »
Just playing devil's advocate here as I have no vested interest in Ldata.
Autodesk could drop lisp all together but I'm not going to stop using it just because they could.
So I don't buy the argument that we should not use it because they MIGHT change it in the future.  :-)

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.

owenwengerd

  • Bull Frog
  • Posts: 451
Re: Xdata vs Ldata
« Reply #18 on: March 03, 2013, 08:10:27 PM »
So I don't buy the argument that we should not use it because they MIGHT change it in the future.  :-)

You've created a straw man argument. Nobody argues that you shouldn't use ldata because it might change in the future. That is a real risk, of course, and a relatively much higher risk than lisp going away, at least when evaluated actuarily based on known history.

You shouldn't use ldata because you don't control it AND there is a less risky alternative.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Xdata vs Ldata
« Reply #19 on: March 03, 2013, 09:41:26 PM »
touché
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.