+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Senior Member
    Using
    AutoCAD 2009
    Join Date
    May 2008
    Location
    Philadelphia, Pa.
    Posts
    407

    Default Change Layer Prefixs and Layer Names

    Registered forum members do not see this ad.

    Hi
    I helped a CADTutor member the other day via a pvt message and I thought it might be good to share it with everyone else.

    The first Sub will change the layer prefix (From - To)

    The second Sub will iterate through the layer collection and ask users if they want to change layer names.

    Both filter out Layer 0 and and the second one also filters out 0 and layers with the prefix that you give it. It probably could also be tweaked to work with wild cards, I haven't tried it.

    ML

    Code:
    Sub ChangeLayerNamePrefix()
     
     Dim lay As AcadLayer
     Dim cwLayNames As String
     Dim ncwLayNames As String
     
    'Update Layer name prefixs
     For Each lay In ThisDrawing.Layers
      If Not lay.Name = "0" Then 'Filter out Layer 0
       cwLayNames = lay.Name
       'Starting from char 1 of the layer name, if string CW- exists then
        If InStr(1, cwLayNames, "CW-", vbTextCompare) Then
        'In string variable cwLayerName, replace CW- w\ ATT-
         ncwLayNames = Replace(cwLayNames, "CW-", "ATT-", , , vbTextCompare)
         lay.Name = ncwLayNames
         Debug.Print "Layer " & cwLayNames & " has been changed to " & ncwLayNames
        End If
       End If
     Next lay
     
     Set lay = Nothing
     
    'Call ChangeLayerName
     
    End Sub
    Code:
    Sub ChangeLayerName()
    Dim lay As AcadLayer
    Dim layName As String
     
    For Each lay In ThisDrawing.Layers
     If Not lay.Name = "0" Then 'Filter out Layer 0
     'Filter out all layers with the prefix ATT-
      If Not InStr(1, lay.Name, "ATT-", vbTextCompare) > 0 Then
    Repeatlay:
      'Return to user, layers to renamed
       If MsgBox("The layer " & lay.Name & " is a non standard layer," & vbCrLf & _
       "do you want to rename this layer?", vbYesNo, "cwLayers") = vbYes Then
       'Prompt the user for new layer name
        layName = InputBox("Enter new layer name for layer " & vbCrLf & lay.Name)
         If layName = "" Then
          MsgBox "All layers must have a name, " & vbCrLf & "Please Click No " & _
          "if you do not want to rename layer: " & vbCrLf & lay.Name, vbCritical
          GoTo Repeatlay
         End If
         lay.Name = layName
         Debug.Print layName
        End If
       End If
     End If
    Next lay
    Set lay = Nothing
     
    End Sub

  2. #2
    Quantum Mechanic ReMark's Avatar
    Computer Details
    ReMark's Computer Details
    Operating System:
    Windows 7 Pro 64-bit
    Computer:
    Thinkmate
    Motherboard:
    Intel DX58SO2 LGA1366 X58
    CPU:
    Intel i7-960 Quad-core 3.20GHz 8MB cache
    RAM:
    12GB (3x4GB) PC3-106000 DDR3
    Graphics:
    nVidia Quadro K4200, 4GB GDDR5
    Primary Storage:
    150GB Velocipraptor 10,000 rpm
    Secondary Storage:
    none
    Monitor:
    Dell P24LLH - 24" wide screen LCD
    Discipline
    See details...
    ReMark's Discipline Details
    Occupation
    CAD Draftsman/Designer...chemical manufacturing.
    Discipline
    See details below.
    Details
    I work for a specialty chemical manufacturer. I do a little bit of everything from P&IDs to civil to architectural and structural.
    Using
    AutoCAD 2018
    Join Date
    Nov 2005
    Location
    Norwalk, CT USofA
    Posts
    46,380

    Default

    Thank you ML0940 for sharing your code with us. I'm sure there are those of us that will find this routine quite helpful.
    "I have only come here seeking knowledge. Things they wouldn't teach me of in college." The Police

    Eat brains...gain more knowledge!

    I'm now a full member of the Society for the Promotion of Mediocrity in CAD. Standards? We don't need no stinkin' standards! Take whatever advice I offer and do the opposite.

  3. #3
    Senior Member
    Using
    AutoCAD 2009
    Join Date
    May 2008
    Location
    Philadelphia, Pa.
    Posts
    407

    Default

    Registered forum members do not see this ad.

    Hi Remark

    Sure, no problem!

    Thank you for the appreciation

    I helped someone privately which I did not mind but after looking at the code tonight, I thought that it is only fair that others see it as well.

    I hope that others will find it useful or even suggest other ways of using it.

    Enjoy!

    Any questions, for free to ask

    ML

Similar Threads

  1. Change layer and return to layer using button
    By Vigilante in forum AutoCAD General
    Replies: 19
    Last Post: 6th Sep 2007, 07:01 pm
  2. Layer Names
    By greenbigg in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 26th Dec 2006, 06:35 pm
  3. Changing layer names
    By Alan Cullen in forum AutoCAD Drawing Management & Output
    Replies: 12
    Last Post: 9th Oct 2006, 12:03 am
  4. Layer names
    By RHOS1355 in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 27th Jun 2006, 11:19 pm
  5. Importing Layer Names
    By blueroly in forum AutoCAD Drawing Management & Output
    Replies: 3
    Last Post: 21st Oct 2005, 03:06 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts