How do you use an asterisk to search for layers using VBA?

How do you use an asterisk to search for layers using VBA?

JustinSider
Enthusiast Enthusiast
1,561 Views
2 Replies
Message 1 of 3

How do you use an asterisk to search for layers using VBA?

JustinSider
Enthusiast
Enthusiast

Hi guys, I thought this would be easy but it's just not working for me and I've searched the help, these forums and I can't find anything. 

 

When you search for a layer in CAD, if you put *TEXT* any layer with TEXT in the name will appear.  This doesn't work when writing code though!!   My example is shown below which doesn't work......  without the asterisk (*) it will change the layer "New" to "MEPHAN" but I want all layers with the word "New" to be changed to "MEPHAN".. (example "xref_New", "New_copy", etc).  The asterisk is supposed to be for a string of characters, don't see why it doesn't work.  Also, is there any character for a sequence of numbers?  the (#) symbol only works for single numbers.

 

Dim oLayers As AcadLayers
Set oLayers = ThisDrawing.Layers
Dim oLayer As AcadLayer
Dim ent As AcadEntity


For Each ent In ThisDrawing.ModelSpace
If ent.Layer = "*New*" Then
ent.Layer = "MEPHAN"
End If

Next

 

Thanks for any input!!

 

0 Likes
Accepted solutions (1)
1,562 Views
2 Replies
Replies (2)
Message 2 of 3

Ed__Jobe
Mentor
Mentor
Accepted solution

If ent.Layer = "*New*" Then

Notice the "=", its doing exactly what its supposed to do. You need to learn the functions for working with strings. In the vba help, look up "strings, manipulating" in the index. It lists the various string functions. Use the "Like" operator instead of the "=" operator. Help on Like has info on wildcards.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 3 of 3

JustinSider
Enthusiast
Enthusiast

YEs!  ****, I remember reading this in my book.... Okay I got this now, thanks a bunch!!

0 Likes