Original Article Date: January 2004
Updated: December 2010
Gerald Hernandez, president of Geospatial Paradigm Solutions, Inc., contributed this slick VBA macro that will execute a set of commands every time a design file is opened and/or closed in MicroStation V8. He also discusses how to customize this little application to suit your own needs. Very Cool!
In response to a recent posting on Bentley's discussion groups, I prepared a VBA macro that executes a set of commands upon opening and closing design files. You are free to download the AutoRun.mvba project and modify to suit your needs. This macro was intentionally written using VBA equivalents of familiar MBE (MicroStation Basic Extensions) style commands to execute standard MicroStation key-ins. This is to aid those who are familiar with key-in scripts and/or MBE to make the transition to VBA. This sample will by no means teach you VBA, but hopefully you will notice your wealth of scripting knowledge is still valuable. In addition, it makes the code very short and understandable to almost anyone. The code is also heavily commented with just about everything you need to know.The sample macro with this article performs the following functions:Upon opening a file:It will close all views except for View 1, maximize the size of View 1 and finally executes a Fit All command.Upon closing a file:It will detach any and all reference files.Of course the idea is that you could customize this macro to perform just about any thing you like. The section of particular interest will be the following methods in the clsDGNOpenClose Class:Private Sub m_OpenCloseHooks_OnDesignFileOpened(ByVal DesignFileName As String)Private Sub m_OpenCloseHooks_OnDesignFileClosed(ByVal DesignFileName As String)To get this project to be automatically loaded and run when you start MicroStation, perform the following:
The results of this little macro will be evident immediately and will run on every file you open or close.Due to the powerful nature of this program, read and take heed to all warnings as outlined in the code. It is strongly advised that you thoroughly test this application before deploying it in production.
This program is supplied as is. Geospatial Paradigm Solutions, Inc. disclaims all warranties, express or implied, including, without limitation, the warranties of merchantability and of fitness of this program for any purpose. Geospatial Paradigm Solutions, Inc. assumes no liability for damages direct, indirect, or consequential, which may result from the use of this program. Geospatial Paradigm Solutions, Inc. does not warrant this program. Use this program at your own risk.
AskInga Article #174