Author Topic: vla-setXData with Vla-add block  (Read 9344 times)

0 Members and 1 Guest are viewing this topic.

kruuger

  • Swamp Rat
  • Posts: 633
Re: vla-setXData with Vla-add block
« Reply #15 on: February 22, 2014, 05:18:30 PM »
...
But xdata added to a block definition won't be copied in the block references (inserts).
ok, so now everything depends what OP wants to do with xdata.


another:
Code: [Select]
; =========================================================================================== ;
; Czyta dane dodatkowe XDATA / Reads additional data XDATA                                    ;
;  Ename [ENAME]   - nazwa entycji / entity name                                              ;
;  App   [STR/nil] - nil = dla wszystkich aplikacji / for all applications                    ;
;                    STR = dla aplikacji App / for App application                            ;
; ------------------------------------------------------------------------------------------- ;
; (cd:XDT_GetXData (car (entsel)) "CADPL")                                                    ;
; =========================================================================================== ;
(defun cd:XDT_GetXData (Ename App)
  (if App
    (cadr (assoc -3 (entget Ename (list App))))
    (cdr (assoc -3 (entget Ename (list "*"))))
  )
)
; =========================================================================================== ;
; Dodaje dane dodatkowe XDATA / Adds additional data XDATA                                    ;
;  Ename [ENAME] - nazwa entycji / entity name                                                ;
;  App   [STR]   - nazwa aplikacji / application name                                         ;
;  Data  [LIST]  - lista danych / data list                                                   ;
; ------------------------------------------------------------------------------------------- ;
; (cd:XDT_PutXData (car (entsel)) "CADPL" '((1000 . "X") (1070 . 5)))                         ;
; =========================================================================================== ;
(defun cd:XDT_PutXData (Ename App Data)
  (regapp App)
  (entmod
    (append
      (entget Ename)
      (list (list -3 (cons App Data)))
    )
  )
)
; =========================================================================================== ;
; Usuwa dane dodatkowe XDATA / Removes additional data XDATA                                  ;
;  Ename [ENAME] - nazwa entycji / entity name                                                ;
;  App   [STR]   - nil = z wszystkich aplikacji / from all applications                       ;
;                  STR = z aplikacji App / from App application                               ;
; ------------------------------------------------------------------------------------------- ;
; (cd:XDT_RemoveXData (car (entsel)) "CADPL")                                                 ;
; =========================================================================================== ;
(defun cd:XDT_RemoveXData (Ename App)
  (if
    (and
      App
     (cd:XDT_GetXData Ename App)
    )
    (entmod (list (cons -1 Ename) (list -3 (list App))))
    (foreach %
      (mapcar
        (quote car)
        (cd:XDT_GetXData Ename nil)
      )
      (entmod (list (cons -1 Ename) (list -3 (list %))))
    )
  )
)

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: vla-setXData with Vla-add block
« Reply #16 on: February 22, 2014, 05:42:58 PM »
Some suggestions
Code - Auto/Visual Lisp: [Select]
  1. (defun cd:xdt_getxdata ( ent app )
  2.     (cdr (assoc -3 (entget ent (list (cond (app) ("*"))))))
  3. )
  4.  
  5. (defun cd:xdt_putxdata ( ent app lst )
  6.     (regapp app)
  7.     (entmod (reverse (cons (list -3 (cons app lst)) (reverse (entget ent)))))
  8. )
  9.  
  10. (defun cd:xdt_removexdata ( ent app / lst )
  11.     (if (setq lst (cdr (assoc -3 (entget ent (list (cond (app) ("*")))))))
  12.         (entmod (list (cons -1 ent) (cons -3 (mapcar 'list (mapcar 'car lst)))))
  13.     )
  14. )

kruuger

  • Swamp Rat
  • Posts: 633
Re: vla-setXData with Vla-add block
« Reply #17 on: February 22, 2014, 05:58:29 PM »
Some suggestions
thanks Lee
really like GetXdata :) need to closer review other two.
any reason why you don't want recall GetXdata in RemoveXData ?
kruuger

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: vla-setXData with Vla-add block
« Reply #18 on: February 22, 2014, 07:05:48 PM »
Some suggestions
thanks Lee
really like GetXdata :) need to closer review other two.

You're welcome - it was only a quick rewrite  :-)

any reason why you don't want recall GetXdata in RemoveXData ?

Looking back on it, I suppose it would make sense - I guess it depends on whether you want a 'highly-coupled library' or not.



Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-setXData with Vla-add block
« Reply #19 on: February 22, 2014, 07:44:07 PM »
hi,

You can add xdata (as extension dictionary) to any AutoCAD object (graphical entities, symbol table records (layers, block definitions, ...), dictionaries).
But xdata added to a block definition won't be copied in the block references (inserts).

Thanks gile : That was the conclusion I came to ... something I wasn't explicitly aware of.

@ velasquez

The code you posted seems to be fine for making the block definition and adding the xdata to the definition.
You may be able  to read the xdata from the definition and add it to the insert ( reference ).

Unfortunately this will mean that ONLY the inserts that use your routine will be fully compliant with your requirements.

As usually happens here, the responses posted offer alternatives to the question you asked. ( and to ones you didn't ask ) :)
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.

velasquez

  • Newt
  • Posts: 195
Re: vla-setXData with Vla-add block
« Reply #20 on: February 23, 2014, 08:22:37 AM »
hi,

You can add xdata (as extension dictionary) to any AutoCAD object (graphical entities, symbol table records (layers, block definitions, ...), dictionaries).
But xdata added to a block definition won't be copied in the block references (inserts).

Thanks gile : That was the conclusion I came to ... something I wasn't explicitly aware of.

@ velasquez

The code you posted seems to be fine for making the block definition and adding the xdata to the definition.
You may be able  to read the xdata from the definition and add it to the insert ( reference ).

Unfortunately this will mean that ONLY the inserts that use your routine will be fully compliant with your requirements.

As usually happens here, the responses posted offer alternatives to the question you asked. ( and to ones you didn't ask ) :)

I misunderstood your post I just tried to illustrate my problem.
I believe the answers help many people.

velasquez


velasquez

  • Newt
  • Posts: 195
Re: vla-setXData with Vla-add block
« Reply #21 on: February 23, 2014, 08:45:18 AM »
?
Code: [Select]
(defun test ( / def doc )
    (setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (vla-add (vla-get-registeredapplications doc) "my-app")
    (setq def (vla-add (vla-get-blocks doc) (vlax-3D-point 0 0) "my-block"))
    (vla-setxdata def
        (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbinteger '(0 . 1)) '(1001 1000)))
        (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbvariant '(0 . 1)) '("my-app" "test")))
    )
)

Hi Lee,
I worked with their duties but the results are negative when I search for xdata see -> "In Xdata associated with Application Name (s)."

Thanks for your time.