Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
MicroStation
  • Product Communities
  • More
MicroStation
MicroStation Wiki Working With Levels In MicroStation VBA [CS]
    • Sign in

    • +MicroStation Wiki
    • +Administration Wiki
    • +Annotations Wiki
    • +Bentley View Wiki
    • +MicroStation PowerDraft
    • -Programming Wiki
      • A class to help create and modify text element
      • A Complete Example
      • A MicroStation VBA Example With Bentley ProjectWise
      • AddIn Development Using VB.NET
      • C# .NET Template with IPrimitiveCommandEvents Class
      • Capturing Graphics in Dynamic Views
      • Compiling MDL Applications
      • Database Manipulation
      • Debugging Native Code MDL Applications
      • Developing Code in VBA
      • Developing MicroStation Applications For DWG Files
      • Drag and Drop in MicroStation
      • Error: "Cannot save changes to VBA project 'Support' because it is read-only"
      • Getting And Setting Elements Using Graphic Groups In VBA [CS]
      • Getting Started with Visual Basic
      • How To Write A Recursive Routine In MicroStation VBA [CS]
      • Introducing Segment3D Methods In MicroStation V8 2004 Edition
      • Known issues in MDL and MicroStationAPI
      • Launching VBA Applications As Initapps Or Dgnapps [CS]
      • Learning MicroStation Addins Step by Step
      • MDL - Getting Started With XAttributes In MicroStation V8 XM Edition
      • MDL - Native Code Application Development
      • MDL Or MicroStation BASIC Choosing The Right Tool [TN]
      • MFC Dialog And Native Window Support
      • Microsoft Office VBA Patch Utility
      • MicroStation BASIC FAQ
      • MicroStation BASIC Limits [FAQ]
      • MicroStation Developer Documentation and Example Code
      • MicroStation Programming Advice
      • MicroStation SDK
      • MicroStation V8 Programming Tools Readme
      • MicroStation V8 VBA Programming Resources [CS]
      • MicroStation V8 XM Edition View Code Updates
      • MicroStation VBA Resources Revisited [CS]
      • Migrating Dimension Code To MicroStation V8
      • Migrating MDL Applications To Native Code
      • Mouse Wheel Events And The Visual Basic 6.0 IDE
      • Porting MDL Applications To MicroStation V8
      • Reading Elements From A Microsoft Access Database With VBA [CS]
      • Running MDL Applications
      • Scanning For MicroStation V8 Elements In VBA [CS]
      • Unleash A Workspace Wizard Automating Workspace Creation With MicroStation V8 And VBA [CS]
      • Using VBA To Detect The Current Or Last Used Command
      • Using VBA To Programmatically Export A VBA Project [CS]
      • Using VBA To Programmatically Import A VBA Projects Components And References [CS]
      • VBA -- Creating A Complex Application
      • VBA Interface Error: failed creating the comp manager - 0x80040583
      • VBA interface error: unable to get IDE
      • vba recording
      • Working With Levels In MicroStation VBA [CS]
      • Writing An MDL Application To Output Custom Placemarks To Google Earth
      • [V8i C++] PointCloud IPointCloudChannelDisplayHandler
    • +Visualization Wiki

     
     Questions about this article, topic, or product? Click here. 

    Working With Levels In MicroStation VBA [CS]


     

    This Client Server article is republished in its entirety from 2003 for reference purposes.

    By Dan Tartaglia, Developer Support Analyst, Bentley Corporate Office
    25 June 2003

    Turning levels on and off

    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:

    • Level Display dialog box - this is used to turn on and turn off levels in a model (per each MicroStation View window).

    If you open the Level Manager, the other two settings are:

    • Global Display (Ctrl+E) - Indicates whether elements on the level are displayed. You can click the Global Display column to change the levels Display setting for all views in all models in the open DGN model.
    • Global Freeze - Indicates whether the level is frozen. If frozen, its elements are not displayed and they cannot be printed. A frozen level is similar to a level with the display off.

    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:

    1. Open a DGN that contains at least one level that is used in the active model. Make sure the level is not set as the active level.
    2. Center at least one element that is on the level in the active view window.
    3. Open the Level Manager and Level Display (Ctrl+E) dialog boxes.
    4. Disable the level's Global Freeze setting. Enable its Global Display setting and Level Display dialog box's setting.
    5. Enable the level's Global Freeze setting. The elements on this level will disappear.
    6. Try to change the level's Global Display setting. Notice that this setting has no effect (the level always stays off). This is because the level's Global Freeze setting is enabled.
    7. Try clicking the level from the Level Display dialog box. Its display cannot be turned on or off for the same reason.
    8. Disable the level's Global Freeze setting and try changing the level's display using the Global Display setting. You can now turn the level's display on or off.
    9. Disable the level's Global Display setting.
    10. Try clicking the level from the Level Display dialog box. Its display still cannot be turned on because the Global Display setting is disabled.
    11. Enable the level's Global Display setting and try changing the level's display from the Level Display dialog box. Now the level's display can now be changed to on or off.

    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.

    How to turn the display of levels to Off

    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.

    How to turn the display of levels to On

    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.

    To turn the display of the level to on, replace this code:

    ' 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

    What about Levels in a reference?

    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

    See Also

    Client Server Archive

    MicroStation Desktop TechNotes and FAQs

    Comments or Corrections?

    Bentley's Technical Support Group requests that you please confine any comments you have on this Wiki entry to this "Comments or Corrections?" section. THANK YOU!

     

     

    • Archived Client Server
    • client server
    • client server 2003
    • Share
    • History
    • More
    • Cancel
    • Elisa McGraw Created by Elisa McGraw
    • When: Wed, Jul 15 2009 4:09 PM
    • Dan Koval Last revision by Bentley Colleague Dan Koval
    • When: Mon, Aug 26 2013 9:48 AM
    • Revisions: 12
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2021 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies