xref layer manipulation

Discussion in 'AutoCAD' started by Ryan, Dec 28, 2004.

  1. Ryan

    Ryan Guest

    I am having trouble trying to change xref layer colors. I want to change
    all xref layers with "wtr" in their name to a specified color. Here is what
    I have, can anyone tell me why it doesn't work?

    Public Sub xreflay()
    Dim oLayer As AcadLayer
    Dim oLayers As AcadLayers

    For Each oLayer In ThisDrawing.Layers
    If InStr(1, oLayer.Name, "*|*wtr*") = 0 Then
    oLayer.Color = 16
    Exit For
    End If
    Next oLayer

    End Sub

    Thanks...
     
    Ryan, Dec 28, 2004
    #1
  2. Ryan

    MP Guest

    well, for one thing you might want to review inStr function in help
    if you wanted to get a match you probably want "if ... >0 " - meaning you
    found a match
    instead of "if ... = 0 " meaning you didn't find a match
    also you want to look at Like function
    since InStr doesn't work with wildcards
    Like is the function you want to be using in this case.

    also given what you said you wanted to do, you need to lose the Exit for
    leaving it in there you will only change the first layer that matches the
    string(once you fix that code)

    something like
    For Each oLayer In ThisDrawing.Layers
    If oLayer.Name Like "*|*wtr*" Then
    oLayer.Color = 16
    End If
    Next oLayer

    Hth
    Mark
     
    MP, Dec 28, 2004
    #2
  3. Ryan

    Ryan Guest

    Thanks,

    I'm sorry I forgot to mention that I'm a novice...

    Also for anyone watching this thread the correct syntax is:

    For Each oLayer In ThisDrawing.Layers
    If oLayer.Name Like "*|*" & "*WTR*" Then
    oLayer.Color = 16
    End If
    Next oLayer
     
    Ryan, Dec 28, 2004
    #3
  4. Ryan

    MP Guest

    just curious, did you find a difference between
    "*|*" & "*WTR*"
    and
    "*|*WTR*"
    ?
     
    MP, Dec 29, 2004
    #4
  5. Ryan

    caduser77 Guest

    Yes,

    "*|*" & "*WTR*" worked,

    "*|*WTR*" didn't work...

    Why, I don't know...
     
    caduser77, Dec 29, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.