Author Topic: Xdata....again.  (Read 9413 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
Xdata....again.
« on: November 23, 2005, 10:13:21 AM »
Yes....again..

Because I have read many sample in this forum on how to read and write or replace Xdata from an entity...
but to many different way...and now i'm lost with how to...

i'm not very familar with VLAX object ...

so if someone can show me the good way on how to read/write and replace Xdata from an entity..
or any link on how it work..

this will be appreciated.

I'm trying to get/write/replace Xdata for a viewport..
if someone have an idea..

thanks. :roll:
Keep smile...

LE

  • Guest
Re: Xdata....again.
« Reply #1 on: November 23, 2005, 10:17:07 AM »
See if a sample made by Jimmy B.... from www.jtbworld.com could help here:

http://jtbworld.com/lisp/vplayers.htm

TR

  • Guest
Re: Xdata....again.
« Reply #2 on: November 23, 2005, 10:23:30 AM »
Wouldn't this post fit better in the LISP section as it's not a General CAD question?

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Xdata....again.
« Reply #3 on: November 23, 2005, 10:30:50 AM »
Wouldn't this post fit better in the LISP section as it's not a General CAD question?
Maybe..your right..

Can any ADMIN can transfert this post to the right direction ? :oops:
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Xdata....again.
« Reply #4 on: November 23, 2005, 10:35:44 AM »
See if a sample made by Jimmy B.... from www.jtbworld.com could help here:

http://jtbworld.com/lisp/vplayers.htm

Sorry, I've made a search int JTB...but no Xdata sample..

thanks.
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Xdata....again.
« Reply #5 on: November 23, 2005, 10:39:58 AM »
i'm trying to make test with this....

(setq var1 (list (list -3  (cons 1000 "TEST"))))


but not seem to work..
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Xdata....again.
« Reply #6 on: November 23, 2005, 11:03:20 AM »
hmmm...

In the Help AutoCAD in 2006 I have this...


Code: [Select]
An application can call entget to obtain the xdata that it has registered. The entget function can return both the definition data and the xdata for the applications it requests. It requires an additional argument, application, that specifies the application names. The names passed to entget must correspond to applications registered by a previous call to regapp; they can also contain wild-card characters.

By default, associative hatch patterns contain extended data. The following code shows the association list of this xdata.

Command: (entget (car (entsel)) ’("ACAD"))

Select object: Select an associative hatch

Entering the preceding code at the command line returns a list that looks something like this:

((-1 . <Entity name: 600000c0>) (0 . "INSERT") (8 . "0") (2 . "*X0")

(10 0.0 0.0 0.0) (41 . 1.0) (42 . 1.0) (50 . 0.0) (43 . 1.0) (70 . 0) (71 . 0)

(44 . 0.0) (45 . 0.0) (210 0.0 0.0 1.0) (-3 ("ACAD" (1000 . "HATCH")

(1002 . "{") (1070 . 16) (1000 . "LINE") (1040 . 1.0) (1040 . 0.0)

(1002 . "}"))))

but in fact the result is...

Code: [Select]
Command: (entget (car (entsel)) ’("ACAD"))

Select object: ; error: bad function: "ACAD"

so How can I learn.. :cry:

Keep smile...

LE

  • Guest
Re: Xdata....again.
« Reply #7 on: November 23, 2005, 11:05:54 AM »
See if a sample made by Jimmy B.... from www.jtbworld.com could help here:

http://jtbworld.com/lisp/vplayers.htm

Sorry, I've made a search int JTB...but no Xdata sample..

thanks.

Sorry, I thought you were looking for code to get the xdata from the floating viewports.... it is have a while that I do not use xdata.... let me see if I have some code about it with me.....

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Xdata....again.
« Reply #8 on: November 28, 2005, 01:57:19 PM »
ok,...let's see if I understand ?

I use this code to select a ViewPort and add Xdata on it.

Code: [Select]
(defun c:XD ()
  (setvar "cmdecho" 0)      ;switch off command echo

(setq VP1 (entget (car (entsel))));; Select a viewport
 
;check if the application has been registered
  (if (not (tblsearch "APPID" "ANDREA"))
;if not, register it
            (regapp "ANDREA"))             

;if there is no exdata
    (if (not (assoc -3 VP1))         
    (progn
      ;create new xdata list
      (setq xd (list (list -3 (list "ANDREA"
               (cons 1000 "test")
               )
      )))
     ;append it and entmod
     (setq VP1 (append VP1 xd))
     (entmod VP1)
     
     ));end if end progn
 
(princ)
)

This supposed to add an Xdata named "ANDREA" if not already in...right ?
but if I use this commands

Code: [Select]
(setq VP1 (entget (car (entsel))));; Select a viewport
(setq value (assoc -3 VP1))

and reselect the same Viewport
the value variable must be not NIL....isn't it ?

 :|
Keep smile...

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Xdata....again.
« Reply #9 on: November 28, 2005, 03:13:00 PM »
Quote from: AutoCAD Help file
You cannot use the entmod function to modify a viewport entity.
You CAN, however, use ActiveX to add/modify the Xdata associated with Vports. Let me see if I can find an example....

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Xdata....again.
« Reply #10 on: November 28, 2005, 03:44:33 PM »
OK, here's a quick example using the same test you were using.
Code: [Select]
;;select vp
(setq vp (vlax-ename->vla-object (car (entsel))))
;;get the existing xdata
(vla-getxdata vp  "" 'code 'val)
;;convert to paired list
(setq pairs (mapcar '(lambda (x y)
       (cons x (vlax-variant-value y))
       )
    (vlax-safearray->list code)
    (vlax-safearray->list val)
    )
      )
;;APPID check
(if (not (tblsearch "APPID" "ANDREA"))
  (regapp "ANDREA")
  )
;;create new pairs
(setq newpairs '((1001 . "ANDREA")(1000 . "This is a Test for Andrea")))
;;convert to individual lists
(foreach x newpairs
  (setq newcodes (cons (car x) newcodes)
newvals (cons (cdr x) newvals))
  )
;;convert to variants
(setq codes (listtovariantarray (reverse newcodes) vlax-vbInteger)
      vals (listtovariantarray (reverse newvals) vlax-vbvariant))
;;add the new Xdata
(vla-setxdata vp codes vals)
;;now check it like we did before
;;get the existing xdata
(vla-getxdata vp  "" 'code 'val)
;;convert to paired list
(setq pairs (mapcar '(lambda (x y)
       (cons x (vlax-variant-value y))
       )
    (vlax-safearray->list code)
    (vlax-safearray->list val)
    )
      )
;;the new data should be at the end of the list
;;function from AcadX.com to convert list to variant array
(defun listToVariantArray (lst varType)
  (vl-load-com)
  (vlax-make-variant
    (vlax-safearray-fill
      (vlax-make-safearray
varType
(cons 0 (1- (length lst)))
      )
      (mapcar
'(lambda (x)
   (cond
     ((= (type x) 'list)
      (vlax-safearray-fill
(vlax-make-safearray
  (if (apply '= (mapcar 'type x))
    (cond
      ((= (type (car x)) 'REAL) vlax-vbDouble)
      ((= (type (car x)) 'INT) vlax-vbInteger)
      ((= (type (car x)) 'STR) vlax-vbString)
    )
    vlax-vbVariant
  )
  (cons 0 (1- (length x)))
)
x
      )
     )
     ((= (type x) 'ename)
      (vla-get-objectid (vlax-ename->vla-object x))
     )
     (t x)
   )
)
lst
      )
    )
  )
)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Xdata....again.
« Reply #11 on: November 29, 2005, 08:06:56 AM »
;;select vp
;;get the existing xdata
;;convert to paired list
;;APPID check
;;create new pairs
;;convert to individual lists
;;convert to variants
;;add the new Xdata
;;now check it like we did before
;;get the existing xdata
;;convert to paired list
;;the new data should be at the end of the list
;;function from AcadX.com to convert list to variant array


Wooo!  :| !!
This is to hot for me..
need to studying....

Jeff, Thank you very much, this is a greate example.
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Xdata....again.
« Reply #12 on: December 01, 2005, 12:51:17 PM »
Jeff,
I have tried your routine..to lurn

but don't know why the "listtovariantarray" is refering...
maybe you don't put the entire code..?
I got an error on it.
Keep smile...

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Xdata....again.
« Reply #13 on: December 02, 2005, 01:14:34 PM »
Andrea,
Nope, it's all there. Note that the (losttovariantarray) must be loaded before trying the lines that preceded it in my post. That function is used to create the array that is passed to the SetXdata method.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Xdata....again.
« Reply #14 on: December 02, 2005, 05:23:00 PM »
Andrea,
Nope, it's all there. Note that the (losttovariantarray) must be loaded before trying the lines that preceded it in my post. That function is used to create the array that is passed to the SetXdata method.

OK....but how can i load this (losttovariantarray) !!??
Keep smile...

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Xdata....again.
« Reply #15 on: December 02, 2005, 05:42:43 PM »
You load the (defun listtovaraintarray .....) just like you do any other function......

It is then called by the lines:
(setq codes (listtovariantarray (reverse newcodes) vlax-vbInteger)
      vals (listtovariantarray (reverse newvals) vlax-vbvariant))

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Xdata....again.
« Reply #16 on: December 07, 2005, 03:22:12 PM »
You load the (defun listtovaraintarray .....) just like you do any other function......

It is then called by the lines:
(setq codes (listtovariantarray (reverse newcodes) vlax-vbInteger)
      vals (listtovariantarray (reverse newvals) vlax-vbvariant))

I'm sorry Jeff, but not sure if I really understand.
the listtovaraintarray is somthing allready exist in AutoCAD ?
or I need to create one ?   :|

Keep smile...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Xdata....again.
« Reply #17 on: December 07, 2005, 03:23:19 PM »
Andrea, go back and read post #10 in this thread <by Jeff>.

added:
actually, it's Reply #10 instead
« Last Edit: December 07, 2005, 03:29:50 PM 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.