Author Topic: autolisp to activex variable conversion.  (Read 2332 times)

0 Members and 1 Guest are viewing this topic.

danadrian.baluta@yahoo.co

  • Guest
autolisp to activex variable conversion.
« on: April 20, 2015, 07:17:29 AM »
Hi. I'm trying to use visual lisp setxdata and getxdata for viewports. It works fine while I use constants, but I don't know how to convert autolisp data types to activex data types.
I tried this way, but it doesn't work:
Code - Auto/Visual Lisp: [Select]
  1. (setq app "MYCOMP")
  2. (setq appv (vlax-make-variant app vlax-vbstring))
  3. (vlax-safearray-put-element DataType 0 1001)
  4. (vlax-safearray-put-element Data 0 appv)
  5.  
I'm sure it's wrong, but I hope it shows what I want to do.
Also, when I extract data with getxdata, I get a list containing variants, which I also don't know how to convert.
This is the code for getting xdata:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:gggxd (/ xtypeout xdataout)
  2.   (vla-GetXData (vlax-ename->vla-object (ssname (ssget) 0)) "MYAPP" 'xtypeOut 'xdataOut)
  3.   (PRINC (vlax-safearray->list xtypeout))
  4.   (PRINC (vlax-safearray->list xdataout))
  5.   (princ)
  6. )

Please help me sort this out. If you could point me to the right documentation, I'll sort it myself.
Thank you,
Adrian

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: autolisp to activex variable conversion.
« Reply #1 on: April 20, 2015, 09:08:50 AM »
Here's a quick example to point you in the right direction:
Code - Auto/Visual Lisp: [Select]
  1. (setq ax:app "MYAPP")
  2.  
  3. (defun c:axaddxdata ( / ent rgp )
  4.     (if (setq ent (car (entsel "\nSelect viewport: ")))
  5.         (progn
  6.             (if
  7.                 (vl-catch-all-error-p
  8.                     (vl-catch-all-apply 'vla-item
  9.                         (list
  10.                             (setq rgp
  11.                                 (vla-get-registeredapplications
  12.                                     (vla-get-activedocument (vlax-get-acad-object))
  13.                                 )
  14.                             )
  15.                             ax:app
  16.                         )
  17.                     )
  18.                 )
  19.                 (vla-add rgp ax:app)
  20.             )
  21.             (vla-setxdata (vlax-ename->vla-object ent)
  22.                 (vlax-make-variant
  23.                     (vlax-safearray-fill
  24.                         (vlax-make-safearray vlax-vbinteger '(0 . 3))
  25.                        '(1001 1002 1000 1002)
  26.                     )
  27.                 )
  28.                 (vlax-make-variant
  29.                     (vlax-safearray-fill
  30.                         (vlax-make-safearray vlax-vbvariant '(0 . 3))
  31.                         (mapcar 'vlax-make-variant (list ax:app "{" "This is a test!" "}"))
  32.                     )
  33.                 )
  34.             )
  35.         )
  36.     )
  37.     (princ)
  38. )
  39.  
  40. (defun c:axgetxdata ( / ent typ val )
  41.     (if (setq ent (car (entsel "\nSelect viewport containing xdata: ")))
  42.         (progn
  43.             (vla-getxdata (vlax-ename->vla-object ent) ax:app 'typ 'val)
  44.             (mapcar 'cons
  45.                 (variant->list typ)
  46.                 (variant->list val)
  47.             )
  48.         )
  49.     )
  50. )
  51.  
  52. ;; (Original concept by Vladimir Nesterovsky I believe)
  53. (defun variant->list ( x )
  54.     (cond
  55.         (   (= 'list (type x))
  56.             (mapcar 'variant->list x)
  57.         )
  58.         (   (= 'variant (type x))
  59.             (variant->list (vlax-variant-value x))
  60.         )
  61.         (   (= 'safearray (type x))
  62.             (variant->list (vlax-safearray->list x))
  63.         )
  64.         (   x   )
  65.     )
  66. )
  67.  

danadrian.baluta@yahoo.co

  • Guest
Re: autolisp to activex variable conversion.
« Reply #2 on: April 20, 2015, 10:39:24 AM »
Thank you so much!

I corrected now my setxdata and getxdata functions. They work perfectly!
I still have to chew on some of the code like the Nesterovsky function calling itself.
This is a great example!

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: autolisp to activex variable conversion.
« Reply #3 on: April 20, 2015, 11:12:27 AM »
You're most welcome Adrian  :-)