You are currently reviewing an older revision of this page.
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
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
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 PropertyRead/Write Boolean(syntax) object.IsDisplayedInView (View)[= Boolean](usage) oLevel.IsDisplayedInView(oView) = False
IsDisplayed PropertyRead/Write Boolean(syntax) object.IsDisplayed [= Boolean](usage) oLevel.IsDisplayed = False
IsFrozen PropertyRead/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 LevelDim oLevels As LevelsDim oView As ViewDim viewIndex As IntegerDim levelName As String' We're going to change the display of this levellevelName = "Bentley"' Sets the view object to View window 1viewIndex = 1Set oView = ActiveDesignFile.Views(viewIndex)' Set the level's object with all the levels in the DGNSet oLevels = ActiveDesignFile.Levels' Iterate through all the levelsFor Each oLevel In oLevels' Process the level if it is foundIf oLevel.Name = levelName Then' Sets the Level ObjectSet 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 = TrueEnd IfNext oLevel' Writes the changeoLevels.Rewrite' Redraws the View windowsRedrawAllViewsEnd 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 = TrueWith this code: ' Make sure the Level Display property is TrueIf oLevel.IsDisplayedInView(oView) = False ThenoLevel.IsDisplayedInView(oView) = TrueEnd If' Make sure the Global Display property is TrueIf oLevel.IsDisplayed = False ThenoLevel.IsDisplayed = TrueEnd If' Make sure the Global Freeze property is FalseIf oLevel.IsFrozen = True ThenoLevel.IsFrozen = FalseEnd 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 LevelDim oLevels As LevelsDim oView As ViewDim viewIndex As IntegerDim levelName As StringDim oAttachment As AttachmentDim oAttachments As Attachments' We're going to change the display of this levellevelName = "Bentley"' Sets the view object to View window 1viewIndex = 1Set oView = ActiveDesignFile.Views(viewIndex)Set oAttachments = ActiveModelReference.Attachments' Iterate through each ReferenceFor Each oAttachment In oAttachments' Set the Level's object with all the levels in the referenceSet oLevels = oAttachment.Levels' Iterate through all the levelsFor Each oLevel In oLevels' Process the level if it is foundIf oLevel.Name = levelName Then ' Sets the Level ObjectSet oLevel = oAttachment.Levels(levelName)' Make sure the Level Display property is TrueIf oLevel.IsDisplayedInView(oView) = False ThenoLevel.IsDisplayedInView(oView) = TrueEnd If' Make sure the Global Display property is TrueIf oLevel.IsDisplayed = False ThenoLevel.IsDisplayed = TrueEnd If' Make sure the Global Freeze property is FalseIf oLevel.IsFrozen = True ThenoLevel.IsFrozen = FalseEnd If' Rewrite the level status to the fileoAttachment.Levels.RewriteEnd IfNext oLevelNext' Send the command to Save SettingsCadInputQueue.SendCommand "fileDesign"' Redraws the View windowsRedrawAllViewsEnd Sub
Client Server Archive
MicroStation Desktop TechNotes and FAQs
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!