convert random variant list to same list but non-variants

Discussion in 'AutoCAD' started by James Maeding, Mar 17, 2005.

  1. I use VB to make arrays and need to convert the safearrays to lists, then any variant values to normal lisp values.
    So assuming you have a list with sublists and so on, how would you do this?
    I could do it for a list that I knew the structure of, but I'd like a function that handles any list.

    This has to to an easy mapcar lambda thingy.
    any takers (givers actually)?
    thx
    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Mar 17, 2005
    #1
  2. I did some more thinking,a dn came to the conclusion this has to involve the Apply function.
    I also should mention the list I want to convert may have variants and may have non-variants.
    I am not sure if Apply wants a simple list as its food or if it can crunch through a list of nested lists...
    thx

    James Maeding <jmaeding at hunsaker dot com>
    |>I use VB to make arrays and need to convert the safearrays to lists, then any variant values to normal lisp values.
    |>So assuming you have a list with sublists and so on, how would you do this?
    |>I could do it for a list that I knew the structure of, but I'd like a function that handles any list.
    |>
    |>This has to to an easy mapcar lambda thingy.
    |>any takers (givers actually)?
    |>thx
    |>James Maeding
    |>jmaeding at hunsaker dot com
    |>Civil Engineer/Programmer

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Mar 18, 2005
    #2
  3. James Maeding

    Doug Broad Guest

    This might give you a start:
    Vladimir Nesterovsky Apr 6 2002, 6:08 pm show options

    Newsgroups: autodesk.autocad.customization
    From: "Vladimir Nesterovsky" <> - Find messages by this author
    Date: Sat, 6 Apr 2002 18:42:59 -0800
    Local: Sat, Apr 6 2002 6:42 pm
    Subject: Re: safearray value
    Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse

    Put it throught this function:


    (defun lisp-value (v) ; the Holy Graal 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)))
     
    Doug Broad, Mar 18, 2005
    #3
  4. Thanks Doug.
    I had written this while waiting for any replies:

    ;CONVERT ANY VARIANT VALUES TO NORMAL VALUES
    ;(CONVERT-VARIANTS (LIST (VLAX-MAKE-VARIANT "A") (LIST (VLAX-MAKE-VARIANT "E") (VLAX-MAKE-VARIANT "F"))))
    ;(CONVERT-VARIANTS (LIST "A" (LIST "E" "f")))

    (DEFUN CONVERT-VARIANTS (IN-LIST / X NEW-LIST)
    (SETQ NEW-LIST (mapcar '(lambda (x)
    (COND
    ((= (TYPE x) 'LIST)
    (CONVERT-VARIANTS X)
    )
    ((= (TYPE x) 'VARIANT)
    (vlax-variant-value X)
    )
    (1 X)
    )
    )
    IN-LIST
    )
    )
    NEW-LIST
    )

    I think it works. I don't trust myself though because it was too easy.
    I guess it all works because any time it hits a "sub" list, it digs in and solves it.

    Pretty cool because this lisp can be converted to do anything to each value in a random list.
    thx

    James Maeding <jmaeding at hunsaker dot com>
    |>I use VB to make arrays and need to convert the safearrays to lists, then any variant values to normal lisp values.
    |>So assuming you have a list with sublists and so on, how would you do this?
    |>I could do it for a list that I knew the structure of, but I'd like a function that handles any list.
    |>
    |>This has to to an easy mapcar lambda thingy.
    |>any takers (givers actually)?
    |>thx
    |>James Maeding
    |>jmaeding at hunsaker dot com
    |>Civil Engineer/Programmer

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Mar 18, 2005
    #4
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.