Author Topic: Values of VLAX-PUT & VLAX-GET ...  (Read 10884 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Values of VLAX-PUT & VLAX-GET ...
« on: April 30, 2010, 02:10:17 PM »
I have a piece of code Tim helped put together for me which grabs a string of text from an attribute block or any text element, and copies it to another element.
Here's a piece of it:
Code: [Select]
(mapcar
   '(lambda (x)
    (vlax-put ToObj x (vlax-get FromObj x)))
   '("TextString")
  )

My question is this;  is there a documented something out there somewhere that will tell me more about what the vlax-put and the vlax-get commands can control ??

For example, the code here shows it'll grab the '("TextString") of object 'FromObj' variable.  I have another piece of code identical to it, but it gets the '("ScaleFactor") of a text object.

I'm wondering if there's more I can add to this.  Getting an insertion point of a text object, or layer, or ... something else.  What are my options ??

I hope this is making some sense, I know what I want to search for but I don't know just how to explain it I think.
Thank you for your help.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #1 on: April 30, 2010, 02:19:52 PM »
This may help. Haven't use it for years myself but I just tried it with AutoCAD 2008 and it appears to still work.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

hermanm

  • Guest
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #2 on: April 30, 2010, 03:49:39 PM »
Kudos to MP once again for his fine work (as usual).
Thanks, MP. :)
Quote
Haven't use it for years myself

Eh? Meaning,
 a) you've got the ACAD AX typelib committed to memory, or
 b) you no longer write AutoLISP
?

Other options per hangman's Q:

1. invoke VBAIDE and use its object browser - bad habit for the long run, as Adesk admits VBA is going away
2. go to Microsft website, down load a free version of one of their compilers and use its object browser
3. search the web for a free or nearly free typelib browser.

All those options will give you the ability to browse other typelibs on your machine,

But none, AFAIK, will tell you the difference between a (vlax-get) and (vlax-get-property) call.

Thx, MP.
« Last Edit: April 30, 2010, 03:57:19 PM by hermanm »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #3 on: April 30, 2010, 04:05:59 PM »
Thanks Herman, nice of you to say. As for memory -- I forget when I had a good one -- I lean on one of my other tools to help me with my object model exploits.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #4 on: April 30, 2010, 05:13:25 PM »
Just for the record. You don't need the mapcar statement or a list for that.

eg.
Code: [Select]
((lambda (x)
   (vlax-put ToObj x (vlax-get FromObj x))
 )
  "TextString"
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #5 on: April 30, 2010, 05:48:45 PM »
vlax-put / get are undocumented as far as I know, but here's my take on the subject:

Using the example of retrieving the Centre of a Circle:

A Circle has the center property and this can be retrieved using the following methods, each with varying returns:

Method 1:

Code: [Select]
(vla-get-Center <circle>)
Returns a Variant:

Code: [Select]
#<variant 8197 ...>
[ The 8197 indicates the variant type (which can also be obtained using the vlax-variant-type, in this case 8197 = 8192 + 5 indicating that the variant is a safearray of Doubles. ]

This can be converted to a SafeArray, then a 3D point using:

Code: [Select]
(vlax-safearray->list
  (vlax-variant-value
    (vla-get-center <circle>)))

We now have the data in list form.

Method 2:

Code: [Select]
(vlax-get-property <circle> 'Center)
This will also return a variant, and the above applies.

Method 3:

Code: [Select]
(vlax-get <circle> 'Center)
This is an older method, and the function vlax-get isn't documented. The method will return data in AutoLISP data types:

Code: [Select]
(-46.4701 16.7293 0.0)
This method is preferable in most cases, but can sometimes be troublesome with some properties.



A similar reasoning applies to Methods,

Using our Circle as an example again, let's say we want to perform the Move Method:

Method 1:

We could use:

Code: [Select]
(vla-move <circle> (vlax-3D-point <point1>) (vlax-3D-point <point2>))

Notice that we require the vlax-3D-point function to convert our 3 element lists into safearray variants of Doubles.

Aside: Another way to create our variants for use with this method would be:

Code: [Select]
(vlax-make-variant
  (vlax-safearray-fill
    (vlax-make-safearray vlax-vbDouble '(0 . 2)) <point>))

But this is of course slightly verbose...

Method 2:

Using the logic that applied to the property functions, we could also use:

Code: [Select]
(vlax-invoke-method <circle> 'Move (vlax-3D-point <point1>) (vlax-3D-point <point2>))

This again deals in variants.

Method 3:

Finally, we can use:

Code: [Select]
(vlax-invoke <circle> 'Move <point1> <point2>)

This method deals in native AutoLISP datatypes such as lists, and can sometimes be more manageable.

Thats all for now,

Lee


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #6 on: April 30, 2010, 08:58:14 PM »
Very nice explanation Lesson Lee -- the only thing I'd add for the OP is that all the vla-* stuff is just a large <convenience> wrapper library -- everything that is accessible via vla-get* | vla-put* | vla-method* is also accessible via vlax-get | vlax-put | vlax-invoke -- but not vice versa.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #7 on: April 30, 2010, 09:00:15 PM »
Most educational!

Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

hermanm

  • Guest
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #8 on: April 30, 2010, 10:59:33 PM »
mmm, IC

Command: (vla-get-center obj)
#<variant 8197 ...>

Command: (type (vla-get-center obj))
variant

Command: (vlax-variant-type (vla-get-center obj))
8197

so, all we need is a LIST of variant types (exists somewhere handy, no doubt) & we can construct a decoder for the variant type which means something to LISP programmers (a.k.a. "humans")

Thx, Lee. :)

One o' these days, "we" will have an automatic decoder for AX typelib "documentation" which gives examples only in the obsolete language called VBA.

Said translator/decoder will be written in LISP (natch).

Doug Broad hinted at such in a post on a.a.c some time ago...

So, the concept exists...

@ MP:

they say memory is the first thing to go...and I can't remember wut goes next  8-)

« Last Edit: April 30, 2010, 11:11:41 PM by hermanm »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #9 on: April 30, 2010, 11:05:58 PM »

so, all we need is a LIST of variant types (exists somewhere handy, no doubt) & we can construct a decoder for the variant type which means something to LISP programmers (a.k.a. "humans")

vlax-safearray->list
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #10 on: April 30, 2010, 11:15:35 PM »
I've always Enjoyed the comments :-D
The code's pretty cool too !
Code: [Select]
(defun lisp-value (v)
   ;; 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.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #11 on: May 01, 2010, 12:22:12 AM »
^ one my personal favorite bits of code as well.  ...hey look, COND not OR. *LOL*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #12 on: May 01, 2010, 12:44:34 AM »
 
:-P

Want to borrow my t-shirt John ??

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.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #13 on: May 01, 2010, 02:43:52 AM »
Hi,

about variants and safearrays, you can see this thread.
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Values of VLAX-PUT & VLAX-GET ...
« Reply #14 on: May 01, 2010, 06:29:46 AM »
Thanks Michael - I suppose that fact reveals itself more prominently when interfacing with objects outside of AutoCAD.  :-)

I must say, that's great code Kerry!