You are currently reviewing an older revision of this page.
The naming of a subroutine generally does not matter. One exception, however, is the name OnProjectLoad. If a subroutine gets this name, it is automatically started as soon as it is loaded.
This makes it much easier to use when you start MicroStation to load a VBA project because not only does it load, it runs.
Here this is a small example:
Sub OnProjectLoad () MsgBox "Hello, I was just loaded" ActiveWorkspace.AddConfigurationVariable "new_variable", "testvalue", True End Sub
If a dialog box is opened, it means that the subroutine has executed. A configuration variable is then set and written in the UCF file. For this subroutine is executed automatically at startup, this project needs to be loaded automatically. It must be listed in the variables MS_VBAAUTOLOADPROJECTS.
You can also edit the variable or simply make a hook in the project editor as shown circled here:
When you restart Microstation, the OnProjectLoad routine is automaticall loaded and executed, as can be seen below:
Not only does this screenshot show that the routine was executed, but that the subroutine is already running during the startup of Microstation.
Behind the message box is still the splashscreen of Microstation, so the subroutine has already been carried out before the Microstation Manager to select a drawing appears.
It is important at this point to note that although commands can be executed, commands relating to the contents of a drawing leads to errors. It is still possible, however, but the installation of an event handler that catches the opening of a drawing is required. More information about this can be found in the following article.