Author Topic: XData question  (Read 12381 times)

0 Members and 1 Guest are viewing this topic.

LE

  • Guest
Re: XData question
« Reply #15 on: February 07, 2006, 06:51:45 PM »
I haven't really, but I have read discussions that said ldata wasn't that good by some pretty smart programmers.  If I can find the again I will post links to those conversations.

Is ldata better to use than xdata?  Opinions welcomed.

Not being pretty smart .... I would simple say yes....   :lol:

And would then.... think... hmm why not then use xrecords, dictionaries?  :-D

Chuck Gabriel

  • Guest
Re: XData question
« Reply #16 on: February 07, 2006, 06:55:03 PM »
Sorry to post this in a LISP forum, but I don't have the mental energy to translate it from VBA right now.  This is how you erase xdata.

Code: [Select]
Sub ClearXdata(obj As acadobject, appName As String)
  Dim dataType(0) As Integer
  Dim dataValue(0) As Variant
  dataType(0) = 1001: dataValue(0) = appName
  obj.setXdata dataType, dataValue
End Sub

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: XData question
« Reply #17 on: February 07, 2006, 06:58:25 PM »
???

Can't you get rid of it by overwriting the data with a null list. I'm sure I've done this in VBA.
Yep, there are numerous posts on how to do this on the Adesk customization group....which Peter used to frequent, so I'm shocked he's unaware of this.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: XData question
« Reply #18 on: February 07, 2006, 07:07:40 PM »
One thing to remember about xdata is you cant get rid of it if you attach it to an object.
............................
Peter

This clears XDAta .. Unless I mis-understand ...
Code: [Select]
(defun StripXdata (ename appname / )
  (entmod (list (cons -1 ename) (list -3 (list appname))))
)
« Last Edit: February 08, 2006, 12:43:25 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: XData question
« Reply #19 on: February 07, 2006, 07:11:34 PM »
Here's the output ..
Quote
XDLIST
Select object:
Enter application name <*>:

* Registered Application Name: KBUB
* Code 1002, Starting or ending brace: {
* Code 1000, ASCII string: apples
* Code 1002, Starting or ending brace: }

Object has 16368 bytes of Xdata space available.


Command: (stripXdata (car (entsel)) "KBUB")

Select object: ((-1 . <Entity name: 7ef61fa8>) (-3 ("KBUB")))

Command: XDLIST

Select object:
Enter application name <*>:

No Xdata associated with Application Name(s).

Object has 16383 bytes of Xdata space available.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: XData question
« Reply #20 on: February 07, 2006, 07:27:35 PM »
I haven't really, but I have read discussions that said ldata wasn't that good by some pretty smart programmers. If I can find the again I will post links to those conversations.

Is ldata better to use than xdata? Opinions welcomed.
I've read these same discussions and based on them decided long ago to steer clear of ldata. I will, however, say that lately I've been using Extension Dictionaries more.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: XData question
« Reply #21 on: February 07, 2006, 07:34:27 PM »
I was going to try and understand dictionaries once, but then I didn't have a use for them at the time.  What I'm doing here is storing information about a polyline object, I didn't see any way to attach an xrecord to it, only xdata, so I went that way.  I guess I could use a dictionary to store the ename (handle), and then just grab from there.

Which is better than, xdata or xrecords and dictionaries?  Since it seems like ldata is out.

Thanks for the interesting conversation, I'm learning a lot.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.


Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: XData question
« Reply #23 on: February 07, 2006, 11:24:22 PM »
I was going to try and understand dictionaries once, but then I didn't have a use for them at the time. 
Thanks for the interesting conversation, I'm learning a lot.
Tim, here are some helper functions and test code to show how Dictionaries attached to objects work. Note that they are similar to Xdata, but they don't require a registered application. I don't show that each object can have multiple xrecords in it's dictionary and even the xrecords can have their own dictionaries! (Not sure how or where this would be needed, but it's fun to know it can be done.... ;-))
Code: [Select]
;| Functions and associated test command, to show their usage,
   for using and working with Extension Dictionaries
   by Jeff Mishler Feb. 7, 2006 |;
(defun get-or-add-xrecord (obj key / oDict tmp)
  (setq oDict (vla-getextensiondictionary obj))
  (setq tmp (vl-catch-all-apply
      '(lambda ()
(vla-item oDict key)
)))
  (if (vl-catch-all-error-p tmp)
    (setq tmp (vla-addxrecord odict key))
    )
  tmp
  )
;;;;;;;;
(defun getxrecorddata (oDict key / return xrec xval)
  (setq xrec (vl-catch-all-apply '(lambda ()
    (vla-item odict key))))
  (if (not (vl-catch-all-error-p xrec))
    (progn
      (vla-getxrecorddata xrec 'xData 'xVal)
      (setq return (mapcar '(lambda (a b)
      (cons a (vlax-variant-value b))
      )
   (vlax-safearray->list xData)
   (vlax-safearray->list xVal)
   )
    )
      )
    )
  return
  )
;;;;;;;;;
(defun putxrecorddata (xrec pairs / iCodes vData)
  (mapcar '(lambda (x)
     (setq iCodes (cons (car x) iCodes)
   vData (cons (vlax-make-variant (cdr x) vlax-vbvariant) vData))
     )
  pairs
  )
  (setq iCodes (vlax-safearray-fill
(vlax-make-safearray vlax-vbinteger (cons 0 (1- (length iCodes))))
iCodes))
  (setq vData (vlax-safearray-fill
(vlax-make-safearray vlax-vbvariant (cons 0 (1- (length vData))))
vData))
  (vla-setxrecorddata xrec iCodes vData)
  )
;;;;;;;;
(defun vl-sel (/ ent)
  (if (setq ent (car (entsel "\nSelect object: ")))
    (vlax-ename->vla-object ent)
    )
  )
;;;;;;;;
(defun c:test (/ ent xrec)
  ;| the pairs may be in any order, the code value can be anything from
     1-369 EXCEPT 5, 100 or 105, and the normal type matching must be
     followed...see the DXF reference for the code/type matchups. |;
  (setq lst '((1 . "TEST1")(40 . 700.00)(60 . 75)))
  (setq ent (vl-sel))
  (setq xrec (get-or-add-xrecord ent "MyTest2"))
  (putxrecorddata xrec lst)
  (setq newpairs (getxrecorddata
   (vla-getextensiondictionary ent)
   "MyTest2"
   )
)
  (print newpairs)
  (princ)
  )

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: XData question
« Reply #24 on: February 07, 2006, 11:48:31 PM »
One feature of XData worth considering is the dynamic characteristics of some of the Fields

From Organization of Extended Data in the Developers Guide ..
Quote
World Space Position

1011. Unlike a simple 3D point, the WCS coordinates are moved, scaled, rotated, and mirrored along with the parent entity to which the extended data belongs. The WCS position is also stretched when the STRETCH command is applied to the parent entity and when this point lies within the select window.

World Space -Displacement

1012. A 3D point that is scaled, rotated, or mirrored along with the parent, but not stretched or moved.

World -Direction

1013. A 3D point that is rotated or mirrored along with the parent, but not scaled, stretched, or moved. The WCS direction is a normalized displacement that always has a unit length.

Distance

1041. A real value that is scaled along with the parent entity.

Scale Factor

1042. Also a real value that is scaled along with the parent.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: XData question
« Reply #25 on: February 08, 2006, 12:20:19 AM »
I have been meaning to see if those values work for xrecords also but I don't think so. The reason I know they work for xdata is every AcDbEntity has an XdataTransformBy() function that is called when you modify an object. Whether this includes xrecords I'm not sure?
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

T.Willey

  • Needs a day job
  • Posts: 5251
Re: XData question
« Reply #26 on: February 08, 2006, 11:20:58 AM »
Tim have you looked at these?
Nope.  I got a lot of reading to do.  Thanks Alan.

Tim, here are some helper functions and test code to show how Dictionaries attached to objects work. Note that they are similar to Xdata, but they don't require a registered application. I don't show that each object can have multiple xrecords in it's dictionary and even the xrecords can have their own dictionaries! (Not sure how or where this would be needed, but it's fun to know it can be done.... ;-))
Thanks Jeff.  I will look this over, and hopefully understand it when I have some time.  Real work awaits me today.

One feature of XData worth considering is the dynamic characteristics of some of the Fields

From Organization of Extended Data in the Developers Guide ..
Thanks Kerry for this.  I don't know enough yet to work with these, but hopefully soon I will.

I have been meaning to see if those values work for xrecords also but I don't think so. The reason I know they work for xdata is every AcDbEntity has an XdataTransformBy() function that is called when you modify an object. Whether this includes xrecords I'm not sure?
Thanks for the info Mick, that is nice to know.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: XData question
« Reply #27 on: February 08, 2006, 05:16:07 PM »
So I went the dictionary route.  I think that I will like that one better.  I can have more control over the codes entered, and that will make it easier to make a function when I extract the information out of the dictionary.  Thanks for all the help, and useful opinions.  Here is the code as is.  It worked in my testing, any comments/suggestions welcomed.
Code: [Select]
(defun c:RoomInfov02 (/ ActDoc Sel StPt EntData PolyObj Dict Xrec CodeList DataList tmpStr CoordList PtList Pt
                        ExInfo tmpExInfo XrecList)

;---------------------------------------------------------------------------
(defun MySetXRec (Obj CodeList DataList / )
; Sets XRecordData.  Must be between 1-369, except for 5, 100, 105.
; See help for information on types, and numbers to use.

(vla-SetXRecordData Obj
 (vlax-make-variant
  (vlax-safearray-fill
   (vlax-make-safearray
    vlax-vbInteger
    (cons 0 (1- (length CodeList)))
   )
   CodeList
  )
 )
 (vlax-make-variant
  (vlax-safearray-fill
   (vlax-make-safearray
    vlax-vbVariant
    (cons 0 (1- (length Datalist)))
   )
   DataList
  )
 )
)
)
;-----------------------------------------------------------------------------
(defun MyGetXRec (Obj / CodeType DataType)
; Retrive XRecordData for an object

(vla-GetXRecordData
 Obj
 'CodeType
 'DataType
)
(if (and CodeType DataType)
 (mapcar
  '(lambda (a b)
   (cons a (variant-value b))
  )
  (safearray-value CodeType)
  (safearray-value DataType)
 )
)
)
;-----------------------------------------------------------------------------

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-StartUndoMark ActDoc)
(initget "Select")
(if (setq StPt (getpoint "\n Select first point [Select existing polyline]: "))
 (if (= StPt "Select")
  (while
   (if
    (and
     (setq Sel (entsel "\n Select polyline: "))
     (setq EntData (entget (car Sel)))
     (= (cdr (assoc 0 EntData)) "LWPOLYLINE")
    )
    (progn
     (setq PolyObj (vlax-ename->vla-object (car Sel)))
     nil
    )
    T
   )
  )
  (progn
   (setq PtList (cons StPt PtList))
   (while (setq Pt (getpoint StPt "\n Select next point: "))
    (setq PtList (cons Pt PtList))
    (if (> (length PtList) 1)
     (grdraw (cadr PtList) (car PtList) 1)
     (grdraw StPt Pt 1)
    )
   )
   (grdraw (car PtList) StPt 1)
   (foreach Pt PtList
    (setq CoordList (cons (cadr Pt) CoordList))
    (setq CoordList (cons (car Pt) CoordList))
   )
   (setq PolyObj
    (vlax-invoke
     (vlax-get
      ActDoc
      (if (equal (getvar "cvport") 1)
       'PaperSpace
       'ModelSpace
      )
     )
     'AddLightweightPolyline
     CoordList
    )
   )
   (vla-put-Closed PolyObj :vlax-true)
  )
 )
)
(setq Dict (vlax-invoke PolyObj 'GetExtensionDictionary))
(if (vl-catch-all-error-p (setq xRec (vl-catch-all-apply 'vla-Item (list Dict "RoomInformation"))))
 (setq xRec (vlax-invoke Dict 'AddXRecord "RoomInformation"))
 (setq ExInfo (MyGetXRec Xrec))
)
(setq XrecList ; (cons [assoc code to use] [question to ask])
 (list
  (cons 1 "\n Room Name:")
  (cons 2 "\n Room Number:")
 )
)
(foreach pair XrecList
 (setq tmpExInfo (cdr (assoc (car pair) ExInfo)))
 (if
  (/=
   (setq tmpStr
    (getstring T
     (strcat
      (cdr pair)
      (if tmpExInfo
       (strcat "<" tmpExInfo ">: ")
       " "
      )
     )
    )
   )
   ""
  )
  (progn
   (setq CodeList (cons (car pair) CodeList))
   (setq DataList (cons tmpStr DataList))
  )
  (if tmpExInfo
   (progn
    (setq CodeList (cons (car pair) CodeList))
    (setq DataList (cons tmpExInfo DataList))
   )
  )
 )
)
(setq CodeList (cons 40 CodeList))
(setq DataList (cons (vlax-get PolyObj 'Area) DataList))
(MySetXRec Xrec (reverse CodeList) (reverse DataList))
(print (MyGetXrec Xrec))
(princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

caddesk2000

  • Guest
Re: XData question
« Reply #28 on: February 15, 2006, 07:59:33 AM »
I just want to say, you people are amazing.  Do you ever get the feeling that your coming to the top of a hil, only to find a mountain and a canyon just on the other side.  It's nice to have a group like this for feedback.  I'm new here, but I'm sure I'll be spending lots of time with you guys/gals.

Have a great day
Sam Cutbirth