Vlisp question - what's right?

Discussion in 'AutoCAD' started by BillZ, Jan 14, 2004.

  1. BillZ

    BillZ Guest

    R2004:

    Is this the correct way to glean layer names using VL?

    (defun GetLayerNames ( / result )
    (vlax-for layer
    (vla-get-layers
    (vla-get-activedocument
    (vlax-get-acad-object)))
    (setq result (cons (vla-get-name layer) result))
    )
    (reverse result)
    )

    And, would this be a better/faster way?
    They both seem to get the job done.
    Or am I getting 2 different types of codes mixed up here.

    (defun GetLayerNames ( / result )
    (vlax-for layer
    (vlax-get-property
    (vlax-get-property
    (vlax-get-acad-object) 'ActiveDocument) 'Layers)
    (setq result (cons (vla-get-name layer) result))
    )
    (reverse result)
    )

    Just wondered why there are so many ways to do the same thing.
    I am pretty new to this VLA and VLAX stuff and would like to start on the right foot.

    Bill
     
    BillZ, Jan 14, 2004
    #1
  2. Both are correct if they do the job. Even though I prefer the first one
    because I think it's more readable.

    --
    Best Regards, Jimmy Bergmark
    CAD and Database Developer Manager at www.pharmadule-emtunga.com
    Take a look at
    JTB FlexReport (FLEXlm report tool) - www.jtbworld.com/jtbflexreport
    SmartPurger (Purges automatically) - www.jtbworld.com/?/smartpurger.htm
    or download some freeware at www.jtbworld.com
    More on AutoCAD 2004;
    www.jtbworld.com/autocad2004.htm
    www.jtbworld.com/autocad2004tips.htm
     
    Jimmy Bergmark, Jan 14, 2004
    #2
  3. BillZ

    Joe Burke Guest

    Hi Bill,

    If you haven't yet, try reading the thread titled "vlax-put-property usage"
    dated 1/3/2004.

    I don't think you'll find a consensus there regarding the two methods you
    mentioned. But personally I find John Uhden's advice excellent given my
    novice level of understanding with the vlisp stuff. It isn't just a question
    of code readability, as John points out. "I've found that (vlax-invoke),
    (vlax-get), and (vlax-put) work the best most of the time and avoid the
    tedium of dealing with safearrays and variants."

    Regards
    Joe Burke
     
    Joe Burke, Jan 14, 2004
    #3
  4. BillZ

    BillZ Guest

    Thanks Joe,
    I saw that post when I was still trying to figure out what vla was. B^))

    Now it makes more sense.

    Bill
     
    BillZ, Jan 14, 2004
    #4
  5. BillZ

    Joe Burke Guest

    Bill,

    You're welcome.

    I don't have a good handle on how other regular contributors here feel about
    this question. I've seen some posts by Michael Puckett (Google searching)
    strongly in favor of vlax get, put and invoke vs. vla specific functions. I
    certainly did not understand the difference when I began using this stuff,
    not so long ago.

    Regards
    Joe Burke
     
    Joe Burke, Jan 15, 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.