Author Topic: GET COORDINATES FROM SAFEARRY  (Read 1674 times)

0 Members and 1 Guest are viewing this topic.

psuchewinner

  • Guest
GET COORDINATES FROM SAFEARRY
« on: July 16, 2010, 10:00:12 AM »
Ive searched for this and I cant find what Im looking for.  How can I get the coordinates from this:
(setq TextInsertionPoint (vla-get-insertionpoint TextObject))?

I know it is simple but I really dont understand variants and safearrays.

Gliderider

  • Guest
Re: GET COORDINATES FROM SAFEARRY
« Reply #1 on: July 16, 2010, 10:13:16 AM »
Code: [Select]
(setq TextInsertionPoint (vlax-get TextObject 'InsertionPoint ))

that really didn't answer your question did it? Try this
Code: [Select]
(setq coords (vlax-safearray->list (vlax-variant-value TextInsertionPoint)))
« Last Edit: July 16, 2010, 10:20:44 AM by lpseifert »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: GET COORDINATES FROM SAFEARRY
« Reply #2 on: July 16, 2010, 10:20:15 AM »
Hi,

Look at the safearray->list function.

Another way is to use vlax-get instead of a vla-* function which returns a variant:
(vlax-get TextObject 'Insertionpoint) returns a standard LISP list.

You can also use this sub which convert any variant or safearray into LISP data type

Code: [Select]
;; gc:VariantToLispData
;; Converts a variant or a safearray into LISP data (list)
;;
;; Argument: var variant or safearray

(defun gc:VariantToLispData (var)
  (cond
    ((= (type var) 'variant)
     (gc:VariantToLispData (vlax-variant-value var)))
    ((= (type var) 'safearray)
     (mapcar 'gc:VariantToLispData (vlax-safearray->list var))
    )
    (T var)
  )
)

Look at this thread
Speaking English as a French Frog

psuchewinner

  • Guest
Re: GET COORDINATES FROM SAFEARRY
« Reply #3 on: July 16, 2010, 11:33:44 AM »
Awesome, thanks guys.

Does the VLAX work woth all properties?

I will read up on this stuff when I am not quite so busy.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: GET COORDINATES FROM SAFEARRY
« Reply #4 on: July 16, 2010, 09:11:40 PM »
Here's the one I use for generic conversion ...

Code: [Select]

;;=====================================================
(defun lisp-value (v)
  ;; the Holy Grail of vla->lisp conversion? ;-)
  ;; Copyright 2002 Vladimir Nesterovsky.
  ;; Free for use by any commercial entity with
  ;; less then $100 million annual revenue.
  (cond ((= (type v) 'variant) (lisp-value (variant-value v)))
        ((= (type v) 'safearray) (mapcar 'lisp-value (safearray-value v)))
        (t v)
  )
)
;;
;;=====================================================
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.