Author Topic: retreive list of names of all layers in active drawing for wcmatch  (Read 2397 times)

0 Members and 1 Guest are viewing this topic.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
is it possible to setq a list of names of all the layers in the active drawing to use as a check for wcmatch?

lays will be a string entered by user
lay_list, the list of layer names

(if (wcmatch lays lay_list)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: retreive list of names of all layers in active drawing for wcmatch
« Reply #1 on: April 11, 2008, 05:12:38 PM »
Alan, because this sort of list is needed frequently I have some stuff in my library to deal with it.

firstly, name the collections

Code: [Select]
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(or g:AcadApplication
    (setq g:AcadApplication (vlax-get-acad-object)))

(or g:ActiveDocument
    (setq g:ActiveDocument (vla-get-activedocument g:AcadApplication)))

(or g:Layers
    (setq g:Layers (vla-get-layers g:ActiveDocument)))


(or g:Blocks
     (setq g:Blocks (vla-get-blocks g:ActiveDocument)))
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;


Then, a routine to iterate over the collections, extracting the names
Code: [Select]
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;; Return list of all collection member names
;;;
(DEFUN KDUB:ListCollectionMemberNames (collection / itemname returnvalue)
   (SETQ returnvalue '())
   (VLAX-FOR each collection
      (SETQ itemname    (VLA-GET-NAME each)
            returnvalue (CONS itemname returnvalue)
      )
   )
   (REVERSE returnvalue)
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;

So that this becomes possible in your code

Code: [Select]
(setq Layer-List (KDUB:ListCollectionMemberNames g:Layers))


 (setq Block-List (KDUB:ListCollectionMemberNames g:Blocks)) 



or in your particular case ;

(if (wcmatch "MyLayerName" (KDUB:ListCollectionMemberNames g:Layers))
;;>>

added: fixed the global variable initialisation  :-(
« Last Edit: April 11, 2008, 07:30:47 PM 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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: retreive list of names of all layers in active drawing for wcmatch
« Reply #2 on: April 11, 2008, 07:16:11 PM »
holy crap, lol. that's quite a mouthful. :)

it's funny, i was just trying to end an issue of my layer isolate (by name, not pick) of if i accidentally screw up my name (ie: 8storm* instead of *storm* or i try and isolate a layer that actually just doesn't exist - we are always getting surveyors that give their boundary some crazy creative name) which i do from time to time, it wouldn't go on with the routine and turn all my layers off.

i can't thank you enough.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: retreive list of names of all layers in active drawing for wcmatch
« Reply #3 on: April 11, 2008, 07:35:39 PM »
For a simple test, perhaps try something like this ;

using the library function ;
Code: [Select]
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
;; Returns VLA-OBJECT or NIL

(DEFUN KDUB:AssertItem (collection item / returnvalue)
   (IF (NOT (VL-CATCH-ALL-ERROR-P
               (SETQ returnvalue (VL-CATCH-ALL-APPLY 'VLA-ITEM
                                                     (LIST collection item)
                                 )
               )
            )
       )
      returnvalue
   )
)
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;

Your Testing code :-
Code: [Select]
(if (setq layerObj (KDUB:AssertItem g:Layers "MyLayerName")))

;; do mojo here ...

)
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.