Layer control by VBA

Discussion in 'AutoCAD' started by A-DESIGN, Aug 26, 2004.

  1. A-DESIGN

    A-DESIGN Guest

    Hi,
    Can you please give me an example to show how I can rename,change the color
    and turn on or off a layer by VBA?Thanks
     
    A-DESIGN, Aug 26, 2004
    #1
  2. A-DESIGN

    Matt W Guest

    Here ya go... (watch for word wrap)

    '===========================================
    Public Sub RenameLayer()
    ThisDrawing.Layers("OLD LAYER NAME").Name = "NEW LAYER NAME"
    End Sub
    '===========================================
    Public Sub TurnOffLayer()
    ' Turn off layer 0
    ThisDrawing.Layers("0").LayerOn = False
    End Sub
    '===========================================
    Public Sub TurnOnLayer()
    ' Turn on layer 0
    ThisDrawing.Layers("0").LayerOn = True
    End Sub
    '===========================================
    Public Sub ChangeLayerColor()
    ' Change the color of layer 0 to red
    Dim lay As AcadLayer
    Dim color As AcadAcCmColor

    Set color = New AcadAcCmColor
    With color
    .ColorMethod = acColorMethodByACI
    .ColorIndex = "1"
    End With

    Set lay = ThisDrawing.Layers("0")
    lay.TrueColor = color
    End Sub

    --
    Matt W

    The difference between genius and stupidity is that genius has its limits.
    | Hi,
    | Can you please give me an example to show how I can rename,change the
    color
    | and turn on or off a layer by VBA?Thanks
    |
    |
     
    Matt W, Aug 26, 2004
    #2
  3. A-DESIGN

    A-DESIGN Guest

    Thanks Matt,
     
    A-DESIGN, Aug 26, 2004
    #3
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.