array help please...

Discussion in 'AutoCAD' started by Devin, Feb 17, 2004.

  1. Devin

    Devin Guest

    There's a function to turn an array into a list. But is there a function to
    turn a list into an array? Perhaps I should make one?

    TIA,

    Devin
     
    Devin, Feb 17, 2004
    #1
  2. Search google for (defun list->variant
     
    Jason Piercey, Feb 17, 2004
    #2
  3. Devin

    Devin Guest

    Thanks Jason,

    I searched through the items listed and found a couple. The only problem is
    that they had no depth. Please see the following:

    (defun List->Variant (vtype inlist)
    (vlax-make-variant
    (vlax-safearray-fill
    (vlax-make-safearray
    vtype
    (cons 0 (1- (length inlist)))
    )
    inlist
    )
    )
    )

    if my lists contain lists, or variable data types then I'm out of luck. Do
    you personally know of any function that is a 'smart' function to perform
    this action?
     
    Devin, Feb 17, 2004
    #3
  4. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; list2var.lsp
    ;; copyright 2002 www.caddzone.com
    ;;
    ;; Function: (list->variant <list>)
    ;;
    ;; converts <list> to a variant array,
    ;; including nested lists. Supports
    ;; strings, integers, reals, points,
    ;; entity names, Nil, and lists containing
    ;; any of same. Nil is converted to EMPTY.
    ;;
    ;; Caveat: A list of 2 or 3 doubles
    ;; is interpreted as a coordinate and
    ;; converted to an array of doubles.

    (defun list->variant (lst)
    (if lst
    (list->variant-aux lst)
    (vlax-make-variant nil)
    )
    )

    (defun list->variant-aux (lst)
    (vlax-make-variant
    (vlax-safearray-fill
    (vlax-make-safearray
    vlax-vbVariant
    (cons 0 (1- (length lst)))
    )
    (mapcar
    '(lambda (elem)
    (cond
    ( (eq (type elem) 'ename)
    (vlax-ename->vla-object elem))
    ( (isPoint elem)
    (vlax-3d-point elem))
    ( (listp elem)
    (list->variant elem))
    (t elem)
    )
    )
    lst
    )
    )
    )
    )

    (defun IsPoint (x)
    (and (listp x)
    (> 4 (length x) 1)
    (vl-every
    '(lambda (o)
    (eq (type o) 'real)
    )
    x
    )
    )
    )

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;





    AcadX for AutoCAD 2004 Beta 1
    http://mysite.verizon.net/~vze2vjds/acadx/AcadX16.zip
     
    Tony Tanzillo, Feb 17, 2004
    #4
  5. Devin

    Devin Guest

    Thanks Tony,

    I noticed it's copyrighted...
    does that mean I can't sell it with my functions?

    Devin
     
    Devin, Feb 19, 2004
    #5
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.