Author Topic: Using VLA-ITEM  (Read 8625 times)

0 Members and 1 Guest are viewing this topic.

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Using VLA-ITEM
« Reply #15 on: February 05, 2010, 07:25:07 AM »
Lee Mac.

Completely off topic here: is that you in our avatar??

jb

p.s. No, that's NOT me in my avatar . . . ;)
James Buzbee
Windows 8

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Using VLA-ITEM
« Reply #16 on: February 05, 2010, 08:21:37 AM »
Ooo, I've never seen it used in that way before...

At a first glance, without testing anything, I thought that vlax-erased-p just checked the erased flag of an object, so if an item never existed in a collection, then I would assume it would error out...

EDIT:

Code: [Select]
(GetItem (vla-get-layers *doc) "Lee")
; error: unable to get ObjectID: "Lee"

Thanks Lee, that answers my question. Looks like gile has a keeper there. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Using VLA-ITEM
« Reply #17 on: February 05, 2010, 11:47:51 AM »
Lee Mac.

Completely off topic here: is that you in our avatar??

jb

p.s. No, that's NOT me in my avatar . . . ;)

Hey James,

No, not me in the avatar, but I do ride a CBR600F  :-)

hermanm

  • Guest
Re: Using VLA-ITEM
« Reply #18 on: February 08, 2010, 09:10:52 PM »
Don't forget vlax-map-collection

Being as how this is LISP, one might expect vlax-map-collection to behave similar to mapcar, but noooo :(

Code: [Select]
;;vlax-map-collection returns the collection object, not a list
;;you must build the list yourself as a side effect (yuck!)
;;so here is a simple wrapper which is proper LISP, i.e. function returns a useful value

(defun map-collection (obj func / return)
(vlax-map-collection obj
  '(lambda (obj / )
      (setq return (cons (func obj) return))
   )
)
return
)

;;equivalent
(vlax-for item collection
  (setq return (cons (func item) return))
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Using VLA-ITEM
« Reply #19 on: February 08, 2010, 10:05:40 PM »
and it's slower (well, marginally) as well as uglier :)

Code: [Select]
(defun getLockedLayers1 (/ layNames)
    (vlax-map-collection
        (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        '(lambda (x)
             (if (= (vla-get-lock x) :vlax-true)
                 (setq layNames (cons (vla-get-name x) layNames))
             )
         )
    )
    (reverse layNames)
)

(defun getLockedLayers2 (/ layNames)
    (vlax-for item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (if (= (vla-get-lock item) :vlax-true)
            (setq layNames (cons (vla-get-name item) layNames))
        )
    )
    (reverse layNames)
)

(benchmark '((getLockedLayers1)
                     (getLockedLayers2)
            )
)
;=> ("X_NoPlot" "x-T50" "x-T35" "x-T25")

Benchmarking [M.P. 2005 < revised kdub 2005>] ..........
Elapsed milliseconds for 128 iteration(s)/ relative Timing :

    (GETLOCKEDLAYERS1).....1703 / 1.0185 <slowest>
    (GETLOCKEDLAYERS2).....1672 / 1.0000 <fastest>
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Using VLA-ITEM
« Reply #20 on: February 08, 2010, 11:06:33 PM »
And what does this do for the time?  :evil:
Code: [Select]
(defun getLockedLayers1 (/ layNames)
    (vlax-map-collection (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (function (lambda (x)
             (if (= (vla-get-lock x) :vlax-true)
                 (setq layNames (cons (vla-get-name x) layNames))
             )
         ))
    )
    (reverse layNames)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Using VLA-ITEM
« Reply #21 on: February 09, 2010, 03:12:18 AM »
Yep .. good point !!

Benchmarking [M.P. 2005 < revised kdub 2005>] ..........
Elapsed milliseconds for 128 iteration(s) / relative Timing :
    (GETLOCKEDLAYERS1).....1172 / 1.0559 <slowest> ;<<<< using  vlax-map-collection
    (GETLOCKEDLAYERS2).....1125 / 1.0135                   ;<<<< using  vlax-for
    (GETLOCKEDLAYERS3).....1110 / 1.0000 <fastest>  ;<<<< using (function(lambda ... in place of '(lambda ...  with vlax-map-collection


but it's still ugly  :-P
... nah, it's not really  :)
« Last Edit: February 09, 2010, 03:27:58 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.