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

0 Members and 1 Guest are viewing this topic.

velasquez

  • Newt
  • Posts: 195
vla-setXData with Vla-add block
« on: February 21, 2014, 06:42:44 PM »
Hello
Can anyone tell me if it is possible to work with vla-setXData during or after vla-setXData.

Thanks

velasquez

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-setXData with Vla-add block
« Reply #1 on: February 21, 2014, 06:52:09 PM »
Hello
Can anyone tell me if it is possible to work with vla-setXData during or after vla-setXData.

Thanks

velasquez

did you mean to say
....  is possible to work with vla-setXData during or after vla-AddBlock. ?
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 #2 on: February 22, 2014, 05:50:46 AM »
Hello
Can anyone tell me if it is possible to work with vla-setXData during or after vla-setXData.

Thanks

velasquez

did you mean to say
....  is possible to work with vla-setXData during or after vla-AddBlock. ?

I need to include a given extended the block at the time it is created.


Ketxu

  • Newt
  • Posts: 109
Re: vla-setXData with Vla-add block
« Reply #3 on: February 22, 2014, 06:12:30 AM »
Maybe add after object created. Just assign to 'entlast' entity ?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-setXData with Vla-add block
« Reply #4 on: February 22, 2014, 06:29:45 AM »


Code - Auto/Visual Lisp: [Select]
  1. (setq blockObj (vla-Add blocks insertionPnt "New_Block"))
  2.  
  3. (vla-SetXData blockObj DataType Data)
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 #5 on: February 22, 2014, 06:47:00 AM »


Code - Auto/Visual Lisp: [Select]
  1. (setq blockObj (vla-Add blocks insertionPnt "New_Block"))
  2.  
  3. (vla-SetXData blockObj DataType Data)

Hi
This did not work, I believe the reason is the block will not be visible.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-setXData with Vla-add block
« Reply #6 on: February 22, 2014, 06:56:07 AM »
Show us your code in full.
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 #7 on: February 22, 2014, 07:10:43 AM »
Show us your code in full.

Code: [Select]

;;;I am working with the functions that are in the post below
;;;http://www.theswamp.org/index.php?topic=29366.msg349174#msg349174

;;;I THANK THE PEOPLE WHO HAVE POSTED.

;;;Make Xdata
(defun JoyPutXdata (JoyObj JoyApp JoyData / JoyXtype JoyXval)
  (setq JoyXtype
(vlax-make-variant
   (vlax-safearray-fill
     (vlax-make-safearray
       vlax-vbInteger
       '(0 . 1)
     ) ;_ fim de vlax-make-safearray
     '(1001 1000)
   ) ;_ fim de vlax-safearray-fill
) ;_ fim de vlax-make-variant
  ) ;_ fim de setq
  (setq JoyXval
(vlax-make-variant
   (vlax-safearray-fill
     (vlax-make-safearray
       vlax-vbVariant
       '(0 . 1)
     ) ;_ fim de vlax-make-safearray
     (list JoyApp JoyData)
   ) ;_ fim de vlax-safearray-fill
) ;_ fim de vlax-make-variant
  ) ;_ fim de setq
  (vla-setXData JoyObj JoyXtype JoyXval)
) ;_ fim de defun
;;;

;;;MakeBlock
;;; (rcmd-makeBlock pt "TEST1" ss T)
(defun rcmd-makeBlock (pt name ss flag / JoyDock ssArray vla_block)
  (setq JoyDoc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-copyObjects
    JoyDoc
    (setq ssArray (rcmd-selectionSet->array ss))
    (setq vla_block (vla-add (vla-get-blocks (rcmd-thisDwg))
                             (vlax-3d-point pt)
                             name
                    ) ;_ fim de vla-add
    ) ;_ fim de setq
  ) ;_ fim de vla-copyObjects
  ;; delete objects
  (if (and flag
           ssArray
           (= (type ssArray) 'safeArray)
           ;; is the safeArray made of vlax-object's
           (= (vlax-safeArray-type ssArray) 9)
      ) ;_ fim de and
    (mapcar 'vla-delete (safeArray-value ssArray))
  ) ;_ fim de if
 
;;;Test Xdata
  (vla-setXData vla_block JoyXtype JoyXval)
) ;_ fim de defun
;;;

Thanks for your help

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: vla-setXData with Vla-add block
« Reply #8 on: February 22, 2014, 09:35:26 AM »
I had a quick look.
I can add XData to a blockReference but not to a blockDefinition.

Perhaps I'm missing something.

Don't have time to play at the moment.
Code - Auto/Visual Lisp: [Select]
  1.       doc     (vla-get-activedocument acadobj)
  2. )
  3.  
  4.  
  5. (setq blocks       (vla-get-blocks doc)
  6.       insertionpnt (vlax-3d-point 0 0 0)
  7. )
  8.  
  9.  
  10. (setq blockobj  (vla-add blocks insertionpnt "MyBlock_2")
  11.       center    (vlax-3d-point 0 0 0)
  12.       radius    1
  13.       circleobj (vla-addcircle blockobj center radius)
  14. )
  15.  
  16.  
  17. (setq insertionpnt (vlax-3d-point 5 5 0)
  18.       modelspace   (vla-get-modelspace doc)
  19.       blockrefobj  (vla-insertblock modelspace
  20.                                     insertionpnt
  21.                                     "MyBlock_2"
  22.                                     2
  23.                                     2
  24.                                     2
  25.                                     0
  26.                    )
  27. )
  28.  
  29. (regapp "TEST_KDUB123")
  30.  
  31.   blockrefobj
  32.   (vlax-make-variant
  33.     (vlax-safearray-fill (vlax-make-safearray vlax-vbinteger '(0 . 1))
  34.                          '(1001 1000)
  35.     )
  36.   )
  37.   (vlax-make-variant
  38.       (vlax-make-safearray vlax-vbvariant '(0 . 1))
  39.       (list "TEST_KDUB123"
  40.             (vl-prin1-to-string (list "A" "B" "c" (list 1 2 3)))
  41.       )
  42.     )
  43.   )
  44. )
  45.  
  46.  
« Last Edit: February 22, 2014, 09:40:33 AM by Kerry »
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 #9 on: February 22, 2014, 01:15:29 PM »
Hello Kerry
You understood my problem well.
"add XData to the blockDefinition"

Thanks

kruuger

  • Swamp Rat
  • Posts: 637
Re: vla-setXData with Vla-add block
« Reply #10 on: February 22, 2014, 02:45:35 PM »
Hello Kerry
You understood my problem well.
"add XData to the blockDefinition"

Thanks
i'm not sure but xdata can be attached only to entity/object i guess.
what do want to add to this block ? maybe try with attributes: constant or invisible.
k.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: vla-setXData with Vla-add block
« Reply #11 on: February 22, 2014, 03:24:52 PM »
?
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")))
    )
)

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: vla-setXData with Vla-add block
« Reply #12 on: February 22, 2014, 04:32:42 PM »
Or in Vanilla,
Code - Auto/Visual Lisp: [Select]
  1. (defun test ( )
  2.     (regapp "my-app")
  3.     (entmake
  4.        '(
  5.             (00 . "BLOCK")
  6.             (08 . "0")
  7.             (70 . 0)
  8.             (10 0.0 0.0 0.0)
  9.             (02 . "my-block")
  10.             (-3
  11.                 ("my-app"
  12.                     (1000 . "test")
  13.                 )
  14.             )
  15.         )
  16.     )
  17.     (entmake
  18.        '(
  19.             (00 . "CIRCLE")
  20.             (10 0.0 0.0 0.0)
  21.             (40 . 1.0)
  22.         )
  23.     )
  24.     (entmake
  25.        '(
  26.             (0 . "ENDBLK")
  27.         )
  28.     )
  29. )

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: vla-setXData with Vla-add block
« Reply #13 on: February 22, 2014, 04:39:34 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).
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: vla-setXData with Vla-add block
« Reply #14 on: February 22, 2014, 04:57:04 PM »
Here're some helpers to get or set xdata in a more AutoLISP friendly way

Code - Auto/Visual Lisp: [Select]
  1. ;; gc:VariantToLispData
  2. ;; Converts a variant or a safearray into AutoLISP data
  3. ;;
  4. ;; Argument
  5. ;; var : variant or safearray
  6.  
  7. (defun gc:VariantToLispData (var)
  8.   (cond
  9.     ((= (type var) 'variant)
  10.      (gc:VariantToLispData (vlax-variant-value var)))
  11.     ((= (type var) 'safearray)
  12.      (mapcar 'gc:VariantToLispData (vlax-safearray->list var))
  13.     )
  14.     (T var)
  15.   )
  16. )
  17.  
  18. ;; gc:VariantsToDxfList
  19. ;; Returns an association list (DXF list type)
  20. ;;
  21. ;; Arguments
  22. ;; xtyp : variant (integer array)
  23. ;; xval : varinat variant (array)
  24.  
  25. (defun gc:VariantsToDxfList (xtyp xval)
  26.   (mapcar 'cons (gc:VariantToLispData xtyp) (gc:VariantToLispData xval))
  27. )
  28.  
  29. ;; gc:GetXdata
  30. ;; Returns the object xdata DXF list
  31. ;;
  32. ;; Arguments
  33. ;; obj : (vla-object) the object to get xdata
  34. ;; app : (string) the regitered application name ("" for all applications)
  35.  
  36. (defun gc:GetXdata (obj app / xtyp xval)
  37.   (vla-GetXdata obj app 'xtyp 'xval)
  38.   (gc:VariantsToDxfList xtyp xval)
  39. )
  40.  
  41. ;; gc:DxfListToVariants
  42. ;; Defines two variables and set a variant to both
  43. ;;
  44. ;; Arguments
  45. ;; lst : a DXF list
  46. ;; typeSymbol : a quoted symbol
  47. ;; valueSymbol : a quoted symbol
  48.  
  49. (defun gc:DxfListToVariants (lst typeSymbol valueSymbol)
  50.   (set typeSymbol
  51.        (vlax-make-variant
  52.          (vlax-safearray-fill
  53.            (vlax-make-safearray
  54.              vlax-vbInteger
  55.              (cons 0 (1- (length lst)))
  56.            )
  57.            (mapcar 'car lst)
  58.          )
  59.        )
  60.   )
  61.   (set valueSymbol
  62.        (vlax-make-variant
  63.          (vlax-safearray-fill
  64.            (vlax-make-safearray
  65.              vlax-vbVariant
  66.              (cons 0 (1- (length lst)))
  67.            )
  68.            (mapcar '(lambda (x)
  69.                       (if (listp (setq x (cdr x)))
  70.                         (vlax-3d-point x)
  71.                         (vlax-make-variant x)
  72.                       )
  73.                     )
  74.                    lst
  75.            )
  76.          )
  77.        )
  78.   )
  79. )
  80.  
  81. ;; gc:SetXdata
  82. ;; Set xdata to an object
  83. ;;
  84. ;; Arguments
  85. ;; obj : (vla-object) the object to set xdata
  86. ;; lst : (DXF list) xdata as :
  87. ;; '((1001 . "AppName") (1002 . "{") (1000 . "string") (1070 . 1) (1002 . "}"))
  88.  
  89. (defun gc:SetXdata (obj lst / xtyp xval)
  90.   (gc:DxfListToVariants lst 'xtyp 'xval)
  91.   (vla-SetXdata obj xtyp xval)
  92. )

using example :
Code: [Select]
(gc:SetXdata obj '((1001 . "my_app") (1000 . "test")))
Code: [Select]
(gc:GetXdata obj "my_app") returns ((1001 . "my_app") (1000 . "test"))
Speaking English as a French Frog