Author Topic: Exploding an object and delete xdata  (Read 4996 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Exploding an object and delete xdata
« on: February 14, 2015, 09:18:10 AM »
Hello everyone,
I have developed an application which adds to the xdata MLeader objects (and also to other types).
Unfortunately, if the user exploded a MLeader the xdata are associated with nested objects.

I would that following the explosion the xdata were removed.
is it possible?

I thought to redefine the command EXPLODE but I do not like this solution.

Do you have any idea?
Thanks in advance.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Exploding an object and delete xdata
« Reply #1 on: February 14, 2015, 10:03:18 AM »
You could use a Command Reactor triggered on the :vlr-commandended event to remove the xdata pertaining to a specific AppID for all objects generated following completion of the EXPLODE command.

Lupo76

  • Bull Frog
  • Posts: 343
Re: Exploding an object and delete xdata
« Reply #2 on: February 15, 2015, 06:42:05 AM »
You could use a Command Reactor triggered on the :vlr-commandended event to remove the xdata pertaining to a specific AppID for all objects generated following completion of the EXPLODE command.

Perfect!
thanks for the suggestion!

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Exploding an object and delete xdata
« Reply #3 on: February 16, 2015, 05:17:13 AM »
I have worked with Xdata and I actually did not know about this issue. This is probably because in my application I work with inserts (block references) and when you explode inserts their Xdata is not attached to the new entities (Note: I use BricsCAD). The fact that Xdata is passed on when exploding other complex entities is a big surprise.

Two tips for working with Xdata:
1. Format your data.
Do not use:
Code: [Select]
(
  (1000 . "A")
  (1040 . 10.7)
)
But instead use:
Code: [Select]
(
  (1002 . "{")
  (1000 . "SECTION")
  (1000 . "A")
  (1002 . "}")
  (1002 . "{")
  (1000 . "DEPTH")
  (1040 . 10.7)
  (1002 . "}")
)

2. Add a reference to the object itself.
Code: [Select]
(
  (1002 . "{")
  (1000 . "ENTITY_HANDLE_AS_TEXT")
  (1000 . "B0")
  (1002 . "}")
)

The second tip can also be used for the issue at hand. The new entities resulting from the explode operation can be be identified as such by comparing their handles to the stored value. At a convenient moment, for example when reopening the drawing, the application can decide to remove inherited Xdata.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Exploding an object and delete xdata
« Reply #4 on: February 16, 2015, 10:54:14 AM »
Get out of my brain Roy. Totally agree with everything you've said herein. I construct self described data the same way, be it xdata or dictionary bound. It's something I adopted long ago tho I can't take credit -- it's exactly how AutoPLANT data is stored -- something I've worked with for the last 20 odd years. I also store original handles as a means to determine if objects are originals or copies, most recently on an "auto tagging" program that pulls and publishes intel from xref'd AutoPLANT models in Electrical and Instrumentation layout drawings.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Exploding an object and delete xdata
« Reply #5 on: February 17, 2015, 04:48:13 AM »
I can't take credit either, just passing on sound advice.

I will add a 3rd tip:

3. Add application version information.
During the lifetime of your application features may be introduced or updated requiring changes to the (amount of) Xdata. Having easy access to version information is then convenient.
Code: [Select]
(
  (1002 . "{")
  (1000 . "APPVERSION")
  (1000 . "2015A")
  (1002 . "}")
)

kruuger

  • Swamp Rat
  • Posts: 637
Re: Exploding an object and delete xdata
« Reply #6 on: May 01, 2015, 03:33:01 PM »
But instead use:
Code: [Select]
(
  (1002 . "{")
  (1000 . "SECTION")
  (1000 . "A")
  (1002 . "}")
  (1002 . "{")
  (1000 . "DEPTH")
  (1040 . 10.7)
  (1002 . "}")
)
hello Roy
can you share more info why to format xdata that way ? maybe small sample how do you play with these write/read ?
thanks
kruuger

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Exploding an object and delete xdata
« Reply #7 on: May 04, 2015, 04:18:50 AM »
@ kruuger:

Why format xdata:
  • If you use a consistent formatting scheme you can use the same xdata functions for all your applications.
  • You don't have to use gc 1002 brackets but including variable names will make working with xdata much easier. You can then use something like this: (cdar (member '(1000 . "myVarA") lst)).
  • With formatting your xdata can be more flexible. Your application can for example only store non-default values in xdata. And if you want to store flexible list-type data, using gc 1002 brackets is an obvious choice.
  • Formatting can also help identify missing or incorrect data during debugging or when a future release of your application needs to update xdata.

Here are the two functions I use to translate xdata. They are not the most elegant functions and do not support all xdata group codes. So they may not suit your specific needs.

Code - Auto/Visual Lisp: [Select]
  1. ; (KGA_AppData_List_To_XdataList (list '(varA "abc") '(varB 1) '(varC (1.0 2.0 3.0)) (list 'varD (entlast))))
  2. (defun KGA_AppData_List_To_XdataList (lst / N_Encode)
  3.   (defun N_Encode (v / typ)
  4.     (setq typ (type v))
  5.     (cond
  6.       ((= typ 'str)
  7.         (cons 1000 v)
  8.       )
  9.       ((= typ 'real)
  10.         (cons 1040 v)
  11.       )
  12.       ((= typ 'int)
  13.         (cons 1071 v)
  14.       )
  15.       ((= typ 'ename)
  16.         (if (setq v (vlax-ename->vla-object v)) ; Faster than using (entget).
  17.           (cons 1005 (vla-get-handle v))
  18.           '(1005 . "0")
  19.         )
  20.       )
  21.       ((= typ 'vla-object)
  22.         (cons 1005 (vla-get-handle v))
  23.       )
  24.       (T
  25.         '(1000 . "*INVALID DATA*")
  26.       )
  27.     )
  28.   )
  29.   (append
  30.     '((1002 . "{"))
  31.     (apply
  32.       'append
  33.       (mapcar
  34.         '(lambda (a)
  35.           (apply
  36.             'append
  37.             (list
  38.               '((1002 . "{"))
  39.               (list (cons 1000 (vl-prin1-to-string (car a))))
  40.               (if (listp (cadr a))
  41.                 (append
  42.                   '((1002 . "{"))
  43.                   (mapcar 'N_Encode (cadr a))
  44.                   '((1002 . "}"))
  45.                 )
  46.                 (list (N_Encode (cadr a)))
  47.               )
  48.               '((1002 . "}"))
  49.             )
  50.           )
  51.         )
  52.         lst
  53.       )
  54.     )
  55.     '((1002 . "}"))
  56.   )
  57. )

Code - Auto/Visual Lisp: [Select]
  1. ; (KGA_AppData_XdataList_To_List (KGA_AppData_List_To_XdataList (list '(varA "abc") '(varB 1) '(varC (1.0 2.0 3.0)) (list 'varD (entlast)))) T)
  2. (defun KGA_AppData_XdataList_To_List (lst enamesToObjectsP / N_Convert N_Decode)
  3.   (defun N_Convert ( / ret stopP)
  4.     (while (and lst (not stopP))
  5.       (cond
  6.         ((equal (car lst) '(1002 . "{"))
  7.           (setq lst (cdr lst))
  8.           (setq ret (append ret (list (N_Convert))))
  9.         )
  10.         ((equal (car lst) '(1002 . "}"))
  11.           (setq lst (cdr lst))
  12.           (setq stopP T)
  13.         )
  14.         (T
  15.           (setq ret (append ret (list (car lst))))
  16.           (setq lst (cdr lst))
  17.         )
  18.       )
  19.     )
  20.     ret
  21.   )
  22.   (defun N_Decode (v)
  23.     (if (= (car v) 1005)
  24.       (progn
  25.         (setq v (handent (cdr v)))
  26.         (if enamesToObjectsP
  27.           (if v (vlax-ename->vla-object v))
  28.           v
  29.         )
  30.       )
  31.       (cdr v)
  32.     )
  33.   )
  34.   (mapcar
  35.     '(lambda (a)
  36.       (list
  37.         (read (cdar a))
  38.         (if (atom (caadr a))
  39.           (N_Decode (cadr a))
  40.           (mapcar 'N_Decode (cadr a))
  41.         )
  42.       )
  43.     )
  44.     (car (N_Convert))
  45.   )
  46. )


kruuger

  • Swamp Rat
  • Posts: 637
Re: Exploding an object and delete xdata
« Reply #9 on: May 05, 2015, 02:49:22 AM »
Roy, Marc thank you. it is pretty cool  ;D
kruuger

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Exploding an object and delete xdata
« Reply #10 on: May 06, 2015, 02:36:42 AM »
Roy, Marc thank you. it is pretty cool  ;D
kruuger
Prego.     Thanks also to Vladimir Nesterovsky!   :)


Q1241274614

  • Guest
Re: Exploding an object and delete xdata
« Reply #12 on: July 07, 2015, 07:08:57 AM »
;; 示例(ax:PutXData myVlaObj '((1001 . "ACADX") (1000 . "myStringData")))
(defun ax:PutXData (vlaObj XData)
  (setq XData
         (ax:BuildFilter
           (mapcar
             '(lambda (item / key)
                (setq key (car item))
                (if (<= 1010 key 1033)
                  (cons key
                        (vlax-variant-value
                          (vlax-3d-point
                            (cdr item)
                          )
                        )
                  )
    item
                )
              )
             XData
           )
         )
  )
  (vla-setXData vlaObj (car XData) (cadr XData))
)