Jump to content

Get layers with certain text (VBA)


Recommended Posts

Posted

Hi. Right now, I am trying to return any layer name via debug.print function with the certain text in it. For example if there were 10 different layers then I only want to display layers containing the text string "local" in the layer name. Does anyone know how to go about doing this? Help is much appreciated.

Posted (edited)

You can access the layer table pretty easy just looking for it now and make a list of your layer names and then you can step through this list and search within each layer name for a match to your text and then do your thing using vla would be the way to go the layer name is a bit easier to retrive than old lisp.

 

Found (tblnext "layer") repeated it will walk through your layers (cadr (tblnext "layer")) or (assoc 2 (tblnext "layer"))

 

Search for any lee mac or alanjt program doing layer stuff here they will all read the layer table generally at the start.

 

Sorry you want it in vba

 

Dont have a layer but here is blocks layers are done similar

 

FilterDXFCode(0) = 0

FilterDXFVal(0) = "INSERT"

Set SS = ThisDrawing.SelectionSets.Add("mysel")

SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFVal

For Cntr = 0 To SS.Count - 1

If SS.Item(Cntr).Name = BLOCK_NAME Then change this to look for your partial layer name

Else: End If

Next Cntr

Edited by BIGAL
added vba
Posted

While Visual LISP and VBA both use the ActiveX COM API, I am not versed in VBA syntax.

 

However, using Visual LISP, this is one method (of many) to return a list of layer names containing 'local':

 

(defun c:TEST (/ layerName layerList)
 (vl-load-com)
 (cond
   (*activeDoc*)
   ((setq *activeDoc* (vla-get-activedocument (vlax-get-acad-object)))))
 (vlax-for lay (vla-get-layers *activeDoc*)
   (if (wcmatch (setq layerName (strcase (vla-get-name lay))) "*LOCAL*")
     (setq layerList (cons layerName layerList))))
 (setq layerList layerList)) ;_end defun

 

 

 

Maybe one of the Guru's can offer you better advice...? (nothing against ya' Bigal)

 

Hope this helps!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...