Jump to content

Recommended Posts

Posted

Strange Name of Thread :)

 

No problem , I have seen these functions used in a routine and I did read them in Cad's Help but it wasn't that clear enough to me to get them well .

 

So anybody would help me with them ? .

 

vlax-make-safearray
vlax-make-variant

 

Many thanks.

 

Michaels

Posted (edited)

As a brief answer: You can use them when creating a Variant data type which may perhaps consist of an array (safearray) of Doubles - as an example, this is used when creating objects using VL which require an array of points, such as an LWPolyline or 3DPolyline:

 

(setq l '((1. 0. 0.) (0. 1. 0.) (0. 0. 1)))

(vla-Add3DPoly
 (vla-get-ModelSpace
   (vla-get-ActiveDocument
     (vlax-get-acad-object)
   )
 )
 (vlax-make-variant
   (vlax-safearray-fill
     (vlax-make-safearray vlax-vbDouble
       (cons 0 (1- (* 3 (length l))))
     )
     (apply 'append l)
   )
 )
)

In the above code, I am creating a Variant of 'Array' type (vlax-vbArray) containing a 1-dimensional array of Doubles, encoding the coordinates of the vertices of the Polyline created.

 

The variant data type is also used in cases so that one can pass mixed data types (such as when working with XData) in a static typed environment (such as in VB(A) and those languages using the COM interop). LISP is quite special in that you can have a list containing mixed data types (strings, doubles, integers etc), whereas other languages require an array to be static typed, i.e. contain data all of the same type (due to the memory allocation used, different data types are allocated difference amounts of memory). Hence, by using variants, which may contain various data types, one can then create an array of variants - and hence effectively pass an array of mixed data types.

 

If you have ever looked into learning a lower level language such as C/C++, you will observe that array may be constructed, but one of the major dangers of using such data types is that you can overwrite any data stored in memory located next to the array should you accidentally overstep the bounds of the array. The safearray is 'safe' in that you can't overstep the bounds in this way.

 

I've really only covered the tip of the iceberg, and my post isn't really all that structured - the VLIDE Help docs are much better in this way. Also, if others think there is erroneous information in my post, please do chime in, I'm happy to be corrected for my own sake as well as others reading this post.

 

Maybe see here also:

 

http://www.theswamp.org/index.php?topic=31674.0

Edited by Lee Mac
Posted

Thank you Lee .

 

When should I use function ( vlax-make-variant ) and why should I safearray them? is it only for building lots of coordinate points to use them as vertices ?

 

Thanks

Posted
When should I use function ( vlax-make-variant )

 

As I demonstrated, to create a variant:

 

...
 ([color=red][b]vlax-make-variant[/b][/color]
   (vlax-safearray-fill
...
 )
)

 

and why should I safearray them?

 

To create a variant of vlax-vbArray (safearray) type.

 

...is it only for building lots of coordinate points to use them as vertices ?

 

No:

 

The variant data type is also used in cases so that one can pass mixed data types (such as when working with XData)...

 

Did you even read this?

 

Posted

Why should we transfer objects to Variant ?

 

I mean what's the benefit of that ?

 

Thankxxxxxxxxxxxx :)

Posted
Why should we transfer objects to Variant ?

 

I mean what's the benefit of that ?

 

Read the above posts ^^ :)

Posted
Read the above posts ^^ :)

 

Since that the main topic is new to me , it seems diffecult to specify the right answer. :)

 

Do I deserve the answer ?

 

Thankxxxxx

Posted

As Lee's explained ... the variant and safearray is only used for interacting with ActiveX objects. Some of their methods and properties take variants and / or arrays as arguments, some have variants and / or arrays as results. AutoLisp does not have such variable types, so you need to be able to create and convert these when you're using ActiveX. Therefore you have these functions. Usually when ActiveX uses an array, it uses an array encased inside a variant - that's why you usually have a variant of array type.

 

You could go ahead and use a safearray / variant for any purpose you please, but there's usually an easier and more efficient way using Lisp's direct types (String, Integer, Real, List). No-one's stopping you, and there's no reason you must not. It's up to you. But when you work with ActiveX, it's sometimes the only choice you have.

 

There are the undocumented vlax-get, vlax-put and vlax-invoke functions. These "usually" convert to and from these types automatically. E.g. when obtaining the attributes of a block reference, the vla-GetAttributes would result in a variant containing a safearray of objects. But if you use (vlax-invoke ... 'GetAttributes) it converts that directly into a list of objects. There are scenarios where these undocumented functions don't work so well though, e.g. with indexed properties. So it's not always possible to never use safearrays / variants.

Posted

Thank you Mr irneb for your clarifications.

 

Appreciated.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...