Vlisp question - what's right?

BillZ

Usenet Archive
Joined
Jul 9, 2003
Messages
1,001
Reaction score
0
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
 
Both are correct if they do the job. Even though I prefer the first one because I think it's more readable.
 
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
 
Thanks Joe,
I saw that post when I was still trying to figure out what vla was. B^))

Now it makes more sense.

Bill
 
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
 

Member Recommended

Back
Top