Author Topic: Ding-Ding Xdata vs. Lspdata. Round 1  (Read 4653 times)

0 Members and 1 Guest are viewing this topic.

daron

  • Guest
Ding-Ding Xdata vs. Lspdata. Round 1
« on: March 15, 2005, 10:55:00 AM »
I'm interested to know your ideas and preferences concerning xdata vs. lspdata. I've never been too successful with xdata, so I'll state my likes for using lspdata.
A) It's easy to create
B) With lspdata you create dictionaries either of the object itself or as an externally named dictionary.
C) You can create (put), retrieve (get), dump (list) and delete lspdata quite easily.
D) You can modify the lspdata with a little work.
E) You can create dotted pair lists that look similar to this:
Code: [Select]
("dictKey" ("val" . "val")
  ("val2" . "val2")
  (etc...)
)


What are the pros and cons to xdata compared to lsp data? If there's anything I left off, feel free to add to it.

MP

  • Seagull
  • Posts: 17344
Ding-Ding Xdata vs. Lspdata. Round 1
« Reply #1 on: March 15, 2005, 11:03:43 AM »
I use xdata and dictionaries. Generally speaking when I have entity centric data I use xdata, application centric data I use dictionaries, though sometimes one can use dictionaries for entity data by linking the handle or objectid, but I digress.

If by lsp data you mean ldata I don't use it, never will - many people have been burnt before using it, and besides, it's just wrapping code you could write yourself - I'd rather roll my own.

:)
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

whdjr

  • Guest
Ding-Ding Xdata vs. Lspdata. Round 1
« Reply #2 on: March 15, 2005, 11:05:56 AM »
I'm not familiar with the term "lspdata".  Is that something new?  I thought everything you mentioned was just different variations of xdata?  :(  :?

daron

  • Guest
Ding-Ding Xdata vs. Lspdata. Round 1
« Reply #3 on: March 15, 2005, 11:52:22 AM »
Yes MP, I do mean ldata. When you say roll your own, I feel that you mean the info you want to put into it and then attaching it to the object. The problem I'm trying to overcome is this: Where I currently work, we use a lousy program called AutoCrete. It's basically, Autocad with a LOT of VERY POORLY written lisp code. Not to get too much into that, but the person that did the code already used xdata and because of that, I want to avoid affecting in any way that program. Therefore, I feel I'd be best off to avoid using xdata if possible. I do however need to attach something to the objects or a dictionary for those objects to list. I also would, if possible, like to not have any external text readable files. This all sort of needs to be SCUBA (Self Contained) or if you want to get technical, SCURA (Self Contained Under Radar Application). Anyway, I noticed in the links, one of them said something about xrecords. I've forgotten about these. I'll look into xRecords. Do you have any thoughts against these?

Will, lspdata is not new. It seems that it's not stable, though. Funny, I remember an Autodesk employee telling me at AU that they won't put anything into the core of AutoCAD that isn't 100% stable. Oh well, didn't believe him then anyway.

daron

  • Guest
Ding-Ding Xdata vs. Lspdata. Round 1
« Reply #4 on: March 15, 2005, 12:08:06 PM »
I'm looking into xrecords. Am I safe to assume that dxf values such as 1 won't affect the value that would normallly be associated with that information in the actual object?

MP

  • Seagull
  • Posts: 17344
Ding-Ding Xdata vs. Lspdata. Round 1
« Reply #5 on: March 15, 2005, 12:14:35 PM »
Hi Daron. First let me apologize for the following terse response, lot's of gators at work today, so I have but a few seconds.

XRecords are normally children to dictionary objects. They are designed to host arbitrary data. Their data will not affect the parent object.

Also be aware that in addition to dictionary objects there are extension dictionary objects. Generally speaking, dictionaries are hosted by the main named dictionary object whereas extension dictionaries can be attached to arbitrary entities / objects, which is particularly useful if the 16kb max that xdata suffers from is an issue. The latter can be made persistant so they'll survive purging.

Sorry, gotta go.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Peter Jamtgaard

  • Guest
Ding-Ding Xdata vs. Lspdata. Round 1
« Reply #6 on: March 15, 2005, 12:22:08 PM »
Hey Swamp,

Here are a couple routines that I developed to use xdata.

The first routine accepts two arguments.

The first is the vla-object and the second argument which is a list of sublists.

The first item in each sublist is the application name.

Like
(setxdata objSelection (list (list "testapp1" "1" 0)(list "testapp2" "peter")))

The other routine reads the xdata and returns the list of sublists.

I also included a command line routine for reading xdata and a subroutine for converting a list to safearray.

The nice thing about xdata is it is readable from both vb(a) and lisp.

The nice thing about ldata is it stores lists!!!

Both are useful and have their place.

Peter Jamtgaard

Code: [Select]

; The setxadatalist function will add a list of sublists to an object as xdata.
; The first item in each sublist is a unique string application name
(defun SetXData (objSelection lstOfSubLists / DataItem lstData
                 intDataType lstOfSublistsDXFCodes lstOfSublistsValues
                 safDXFCodes safDataValues)                
 (if debug (princ "\nSetXdata: "))
 (foreach lstData lstOfSublists
  (setq lstOfSublistsDXFCodes (cons 1001 lstOfSublistsDXFCodes)
        lstOfSublistsValues   (cons (car lstData) lstOfSublistsValues))
  (RegApp (car lstData))
  (foreach DataItem (cdr lstData)
   (cond    ; Determine the data type and corrusponding DXF Code
    ((= (type DataItem) 'INT)
     (if (> DataItem 1000000)
      (setq intDataType  1071)                          ; Long    Data Type
      (setq intDataType  1070)                          ; Integer Data Type
     )
    )                                                  
    ((= (type DataItem) 'REAL)(setq intDataType  1040)) ; Real Data Type
    ((= (type DataItem) 'STR)
     (if (or (= DataItem "{")(= DataItem "}"))          ; String Data Type    
      (setq intDataType  1002)
      (setq intDataType  1000)
     )
    )
   )
   (setq lstOfSublistsDXFCodes (cons intDataType lstOfSublistsDXFCodes)
         lstOfSublistsValues   (cons DataItem    lstOfSublistsValues)
   )
  )
 )
 (setq safDXFCodes   (listToSafearray vlax-vbinteger
                      (reverse lstOfSublistsDXFCodes))                    
       safDataValues (listToSafeArray vlax-vbvariant
                      (reverse lstOfSublistsValues)))
 (errortrap '(vla-setXData objSelection safDXFCodes safDataValues)))

; Returns a list of sublists that include a application name as the first
; Item in every sublist and data for the remaining members

(defun C:GetXdata ()
 (getxdata (car (entsel "\nSelect object with Xdata: ")))
)

(defun GetXdata (objSelection / intCount lstAll lstSub safDXFValues safDXFValues)
;  (print strXdata)  (if DEBUG (print "GetXdata"))
 (if (= (type objSelection) 'ENAME)
  (setq objSelection (vlax-ename->vla-object objSelection))
 )
 (vla-getxdata objSelection "" 'safDXFCodes 'safDXFValues)
 (if (and safDXFCodes
          safDXFValues
     )
  (progn
   (setq lstDXFCodes  (vlax-safearray->list safDXFCodes)  
         lstDXFValues (mapcar 'variant-value (vlax-safearray->list safDXFValues))  
   )
;   (print lstDXFCodes)
;   (print lstDXFValues)  
   (setq intCount 0)
   (foreach intDXFCode lstDXFCodes
    (if (= intDXFCode 1001)
     (if lstSub
      (setq lstAll (cons (reverse lstSub) lstAll)
            lstSub (list (nth intCount lstDXFValues))
      )
      (setq lstSub (list (nth intCount lstDXFValues)))  
     )
     (setq lstSub (cons (nth intCount lstDXFValues) lstSub))  
    )
    (setq intCount (1+ intCount))
   )
   (if lstSub (reverse (cons (reverse lstSub) lstAll)))
  )
 )
)

(defun ListToSafearray (symVariableType lstValues / safValues)
 (setq safValues (vlax-make-safearray symVariableType (cons 0 (1- (length lstValues)))))
 (vlax-safearray-fill safValues lstValues)
)


daron

  • Guest
Ding-Ding Xdata vs. Lspdata. Round 1
« Reply #7 on: March 15, 2005, 01:20:52 PM »
Thanks Peter. I'll have to look into this. I am still a little leary about using xdata in this though as I want to ensure that any xdata that already exists won't get deleted, masked or overlooked by it's calling code.

MP

  • Seagull
  • Posts: 17344
Ding-Ding Xdata vs. Lspdata. Round 1
« Reply #8 on: March 15, 2005, 01:23:18 PM »
Just make sure you use a unique application identifier (appid) AND you ensure there's adequate room for the original data AND your data (see the xdroom function).
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

daron

  • Guest
Ding-Ding Xdata vs. Lspdata. Round 1
« Reply #9 on: March 15, 2005, 01:27:18 PM »
Will do.

MP

  • Seagull
  • Posts: 17344
Ding-Ding Xdata vs. Lspdata. Round 1
« Reply #10 on: March 15, 2005, 01:29:20 PM »
Forgot, look into the xdsize function too.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox