You are currently reviewing an older revision of this page.
This Client Server article is republished in its entirety from 2004 for reference purposes.
Before we go into detail on using MicroStation VBA, let's review how to turn a level on or off from within MicroStation V8. There are three settings that we need to modify. The first setting is:
If you open the Level Manager, the other two settings are:
Figure 1 shows the hierarchy of our level structure concerning the display of the elements:
Figure 1: Level structure concerning the display of the elements
It's easy to turn off a level in any of the above three settings using VBA, because if any one of the above settings is set, the level will not be displayed. Turning a level on can be tricky, because all three settings need to be set to display the level's elements.
As an exercise, do the following steps to see how each of the three settings affects each other:
You should now see how these three settings affect one another in the order shown in Figure 1. We need to modify these settings in our VBA application.
As I explained, any three of the settings that are shown in Figure 1 can be used to turn off the display of a level. Typically, the Level Display dialog box setting is the most commonly used for this purpose. Figure 2 will show what VBA properties are needed to set these three settings:
IsDisplayedInView Property Read/Write Boolean (syntax) object.IsDisplayedInView (View)[= Boolean] (usage) oLevel.IsDisplayedInView(oView) = False
IsDisplayed Property Read/Write Boolean (syntax) object.IsDisplayed [= Boolean] (usage) oLevel.IsDisplayed = False
IsFrozen Property Read/Write Boolean (syntax) object.IsFrozen [= Boolean] (usage) oLevel.IsFrozen = True
Figure 2: The properties of the Level Object concerned with their display
The below example will turn off the three Level Object properties as shown in Figure 2 for the level "Bentley." The example will show you how to use all three of these properties, however, in a real world application you would normally use only one of the properties (most likely, the IsDisplayedInView Property).
* Tip: If a statement in a VBA macro begins with an apostrophe, it is only a comment. A lot of comments are added to these examples to explain what they do.
'-----------------------------------------------------------------------+ ' ' name LevelOffExample ' ' author BSI 06/2003 ' '-----------------------------------------------------------------------+ Sub LevelOffExample() Dim oLevel As Level Dim oLevels As Levels Dim oView As View Dim viewIndex As Integer Dim levelName As String ' We're going to change the display of this level levelName = "Bentley" ' Sets the view object to View window 1 viewIndex = 1 Set oView = ActiveDesignFile.Views(viewIndex) ' Set the level's object with all the levels in the DGN Set oLevels = ActiveDesignFile.Levels ' Iterate through all the levels For Each oLevel In oLevels ' Process the level if it is found If oLevel.Name = levelName Then ' Sets the Level Object Set oLevel = ActiveDesignFile.Levels(levelName) ' Sets the Level Display in View property (Level Display dialog) oLevel.IsDisplayedInView(oView) = False ' Sets the Global Display property (Level Manager dialog box) oLevel.IsDisplayed = False ' Sets the Global Freeze property (Level Manager dialog box) oLevel.IsFrozen = True End If Next oLevel ' Writes the change oLevels.Rewrite ' Redraws the View windows RedrawAllViews End Sub
* All example code in this article can be copy/pasted into a MSVBA Project and should work correctly. The example code is created on V8 version 08.01.01.09.
To turn on the display of a level, all three of the settings will need to be set to display the level's elements. If any one of the settings is not set correctly, the level will not display. The information and properties in Figure 2 are also valid for turning a level on, just as it was for turning a level off. Besides the three Level properties, the rest of the code is exactly the same as the LevelOffExample() example.
' Sets the Level Display in View property (Level Display dialog) oLevel.IsDisplayedInView(oView) = False ' Sets the Global Display property (Level Manager dialog box) oLevel.IsDisplayed = False ' Sets the Global Freeze property (Level Manager dialog box) oLevel.IsFrozen = True With this code: ' Make sure the Level Display property is True If oLevel.IsDisplayedInView(oView) = False Then oLevel.IsDisplayedInView(oView) = True End If ' Make sure the Global Display property is True If oLevel.IsDisplayed = False Then oLevel.IsDisplayed = True End If ' Make sure the Global Freeze property is False If oLevel.IsFrozen = True Then oLevel.IsFrozen = False End If
The same logic will work with levels in a reference attachment as well. The below example will change the display to on for the specified reference level "Bentley:" '-----------------------------------------------------------------------+ ' ' name RefLevelOnExample ' ' author BSI 06/2003 ' '-----------------------------------------------------------------------+ Sub RefLevelOnExample() Dim oLevel As Level Dim oLevels As Levels Dim oView As View Dim viewIndex As Integer Dim levelName As String Dim oAttachment As Attachment Dim oAttachments As Attachments ' We're going to change the display of this level levelName = "Bentley" ' Sets the view object to View window 1 viewIndex = 1 Set oView = ActiveDesignFile.Views(viewIndex) Set oAttachments = ActiveModelReference.Attachments ' Iterate through each Reference For Each oAttachment In oAttachments ' Set the Level's object with all the levels in the reference Set oLevels = oAttachment.Levels ' Iterate through all the levels For Each oLevel In oLevels ' Process the level if it is found If oLevel.Name = levelName Then ' Sets the Level Object Set oLevel = oAttachment.Levels(levelName) ' Make sure the Level Display property is True If oLevel.IsDisplayedInView(oView) = False Then oLevel.IsDisplayedInView(oView) = True End If ' Make sure the Global Display property is True If oLevel.IsDisplayed = False Then oLevel.IsDisplayed = True End If ' Make sure the Global Freeze property is False If oLevel.IsFrozen = True Then oLevel.IsFrozen = False End If ' Rewrite the level status to the file oAttachment.Levels.Rewrite End If Next oLevel Next ' Send the command to Save Settings CadInputQueue.SendCommand "fileDesign" ' Redraws the View windows RedrawAllViews End Sub
Client Server Archive