Questions similar to this appear on the Bentley Discussion Groups. These problems appeared in the VBA discussion group.
Q
A
A TextElement 's Boundary is a UDT with Low and High components, each a Point3d.
If the TextElement is not rotated, then these points can be used to construct a rectangle that represents the
TextElement 's boundary.
There's an undocumented configuration variable _dgnfile.
It's updated automatically each time you open a DGN file.
It points to the active DGN file's location.
So the answer to the question is simple: evaluate_dgnfile …
' ---------------------------------------------------------------------
' ShowCurrentDgnFile
' Shows how to find the current DGN file path
' ---------------------------------------------------------------------
Sub ShowCurrentDgnFile()
Dim path As String
Const CurrentFile As String = "$(_dgnfile)"
path = ActiveWorkspace.ExpandConfigurationVariable(CurrentFile)
Debug.Print "Variable '" & CurrentFile & "' evaluates to " & path
End Sub
There's an undocumented configuration variable _dgnfile.
It's updated automatically each time you open a DGN file.
It points to the active DGN file's location.
So the answer to the question is simple: evaluate_dgnfile …
' ---------------------------------------------------------------------
' ShowCurrentDgnFolder
' Shows how to find the current DGN file folder
' ---------------------------------------------------------------------
Sub ShowCurrentDgnFolder()
Dim path As String
Const CurrentFolder As String = "$(_dgndir)"
path = ActiveWorkspace.ExpandConfigurationVariable(CurrentFolder)
Debug.Print "Variable '" & CurrentFolder & "' evaluates to " & path
End Sub
MicroStation looks for DGN files in the folders indicated by configuration variable MS_DEF.
There's more information about configuration variables and configuration files in MicroStation help.
MS_DEF points to a single folder or a list of folders.
You would normally set MS_DEF per project, in your
project configuration file or perhaps your user configuration file.
MicroStation is the executing application that hosts your VBA run-time environment.
Every application that hosts VBA has an Application object.
The Application object has a Path property.
So, whether you're writing VBA for MicroStation, Excel, Word, or something else, you can find the host's location
using Application.Path …
Dim path As String path = Application.path Debug.Print "Application.Path '" & path & "'"
MicroStation stores VBA projects in various locations.
Those locations may be in one of MicroStation's workspace folders
(e.g. \Bentley\MicroStation\WorkSpace\System\Vba) or in your own project-specific folders.
See configuration variable MS_VBASEARCHDIRECTORIES in MicroStation VBA help for more information.
You may want to find the location of your VBA project at run-time.
By default, VBA provides to way to find the location of the executing project at run-time.
However, that information is available via the deftly-named Microsoft Visual Basic for Applications Extensibility 5.3.
This is a VBA project, which you can find in C:\Documents and Settings\All Users\Application Data\Bentley\MicroStation\WorkSpace\System\Vba.
Use the VBE IDE menu Tools|References to pop the VBA References dialog.
Browse through the list to find the VBE Extensibility module and check the box to add it to your project …
Now you've referenced the VBE Extensibility module, you can use it in your code. In this example, we want to get the location of the currently-executing VBA code …
' --------------------------------------------------------------------- ' ShowVbaProjectFolder ' Shows how to find the folder where your VBA Project is located. ' This is different to the Application.Path, which is the folder ' where the executable that hosts the VBA run-time is located ' ' The code that gets the VBA Project path requires a reference to ' another project, 'Microsoft Visual Basic for Applications Extensibility 5.3'. ' You reference another project using the VBA IDE menu Tools|References ' ---------------------------------------------------------------------Sub ShowVbaProjectFolder() Dim path As String path = Application.path Debug.Print "Application.Path '" & path & "'"' The next statement uses the VBE Project referenceDim oVB As VBProject Set oVB = ExecutingVBProject path = oVB.FileName Debug.Print "VBA Project path '" & path & "'" End Sub