[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


VBA layer control

Posted on 2006-05-24
Medium Priority
Last Modified: 2012-06-22
I have the following VBA script which I wnat to have run when I open a drawing:

This is in ThisDrawing:
Option Explicit

Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
   If UCase(CommandName) Like "OPEN" _
    Or UCase(CommandName) Like "CLOSE" Then
               Call SetLayers
   End If
End Sub

This is in Module1:
Option Explicit
Public Sub SetLayers()

Dim objLayer As AcadLayer
Dim vMatchStrings(0 To 3) As String
Dim sMatchString  'must be declared as variant

vMatchStrings(0) = "RM*"
vMatchStrings(1) = "GROS*"
vMatchStrings(3) = "XREF"
vMatchStrings(2) = "*WALL*"

    For Each objLayer In ThisDrawing.Layers
    For Each sMatchString In vMatchStrings
    If objLayer.Name Like sMatchString Then
            objLayer.LayerOn = True
        If objLayer.Freeze = True Then
           objLayer.Freeze = False
        End If
            Exit For
            objLayer.LayerOn = False
        End If
        'Debug.Print objLayer.Name
    'ThisDrawing.Regen True
End Sub

When I first open a drawing it does not run on the drawing being opened. After I open a drawing and then open another drawing it runs on the previous open drawing.
Question by:fusebox
1 Comment
LVL 14

Accepted Solution

Tommy Kinard earned 2000 total points
ID: 16762875
Your code should be in the Private Sub AcadDocument_BeginClose() for the close event.
In the open you could place it in the activate but the problem there is it will fire everytime you pick the drawing.



Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month19 days, 21 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question