Variants - why?

Discussion in 'AutoCAD' started by LTravis, Jul 20, 2004.

  1. LTravis

    LTravis Guest

    I have a question regarding the general nature of variants, and forgive me
    if it sounds very basic but I would like to be clear on it. Regarding
    variants, they are described as "self-defining structures that can contain
    different types of data". Now, responsible programming practice suggests
    you specify the type of data the variant holds (i.e. "double"). Well, if
    that's the case, why are variants even needed? For example, a Vlisp point
    has to be a variant containing an array of doubles. Why doesn't
    Vlisp/ActiveX just allow the data type to be a simple array of doubles
    without being "wrapped" in this "extra" data structure?

    Thanks for any input,
    LT
     
    LTravis, Jul 20, 2004
    #1
  2. LTravis

    ECCAD Guest

    I think this has to do with the structure of the language..
    In VLisp, there is no 'place' to define data types..e.g. no DIM statement area. The 'variant' structure allows for many 'types' of data to be stored and used. Arrays of point values are just (one) type.

    Bob
     
    ECCAD, Jul 20, 2004
    #2
  3. LTravis

    LTravis Guest

    Thanks, Bob. That basically answers my question. It still seems like extra
    steps to me, though. The fact that the user has to *always* wrap his data
    type with a variant type tell me that maybe Vlisp should just automatically
    handle creating the variant without the programmer having to be burdened
    with it. Either that or perhaps Vlisp *should* have a dim statement.

    Thanks again,
    LT


    area. The 'variant' structure allows for many 'types' of data to be stored
    and used. Arrays of point values are just (one) type.
     
    LTravis, Jul 20, 2004
    #3
  4. LTravis

    Joe Burke Guest

    LT,

    A variant wrapper isn't required for a point (your example) depending on which vlisp
    functions are used. For instance:

    Command: (setq vobj (vlax-ename->vla-object
    (car (entsel "Select line: "))))

    Select line: #<VLA-OBJECT IAcadLine 0ab1df44>

    Command: (vla-get-startpoint vobj)
    #<variant 8197 ...> ;returns a variant

    Command: (vlax-get vobj 'startpoint)
    (7.90699 44.7369 0.0) ;returns a list of reals

    Likewise:

    ;requires a variant argument
    Command: (vla-put-startpoint vobj (vlax-3D-point '(7.0 34.0 0.0)))
    nil

    ;accepts a list of reals
    Command: (vlax-put vobj 'startpoint '(7.0 34.0 0.0))
    nil

    Try using the vlax-get, vlax-put and vlax-invoke functions. The arguments supplied
    and the data types returned are pretty much the same as vanilla LISP. Note, these
    functions require quoted symbols, such as 'StartPoint.

    HTH
    Joe Burke
     
    Joe Burke, Jul 21, 2004
    #4
  5. LTravis

    LTravis Guest

    Very nice. Thanks, Joe - I will add this to my arsenal.

    LT
     
    LTravis, Jul 21, 2004
    #5
  6. LTravis

    Joe Burke Guest

    You're welcome.

    Joe Burke
     
    Joe Burke, Jul 22, 2004
    #6
  7. LTravis

    BTO Guest

    Command: (setq vobj (vlax-ename->vla-object
    just to add,
    (vlax-get-property vobj 'startpoint) returns a variant
    as unfortunately it's show in help

    Bruno Toniutti
     
    BTO, Jul 29, 2004
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.