Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
MicroStation
  • Product Communities
  • More
MicroStation
MicroStation Wiki Launching VBA Applications As Initapps Or Dgnapps [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. 

    Launching VBA Applications As Initapps Or Dgnapps [CS]

     

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

    By Bentley Technical Support Group
    07 October 2002

     

    http://selectservices.bentley.com/files/clientserver/downloads/Suh_autoload.zip

    MicroStation V8 allows users to run MDL applications at the startup of MicroStation using the MS_INITAPPS environment variable, and at the opening of a new design file with the MS_DGNAPPS variable. The delivered Runmacro MDL application allows you similar functionality for MicroStation BASIC macros. Now with MicroStation VBA, you can also emulate these options for users running MicroStation V8 version 08.00.02.20 or higher.

    Running VBA Application as an Initapp

    There are two major steps involved in setting up your application for the startup of MicroStation V8. The first is to create a subroutine called OnProjectLoad(). This is the routine that gets called when MicroStation loads a MicroStation VBA project:

    Option Explicit
    Sub OnProjectLoad()
    ' Start here
    MsgBox "MicroStation VBA Starting here"
    End Sub

    The next step is to check the Auto-Load option on in the VBA Project Manager.

    Now every time you start MicroStation, your MicroStation VBA Project will load automatically.

    Running VBA Application as a Dgnapp

    Setting a MicroStation VBA application to run as a Dgnapp will require you to implement the IPrimitive and ILocate events. This involves calling an instance of your class to monitor for the opening and closing of a design file. The first step is to insert a class module into your project and call it OpenClose:

    Next, you will need to go to the top of your Module code and declare a global class variable as follows:

    Option Explicit
    Dim oOpenClose As OpenClose

    The "Option Explicit" statement implies that the user must define each variable's datatype or you will receive an error when trying to run your code.

    Next, you want to create a new instance of the class object you just defined in your subroutine:

    Sub Main()
    Set oOpenClose = New OpenClose
    End Sub

    Now that we have created a new instance of the class, we need to link the class into the module to look for specific events. Go back to your class and type in the following statements:

    Option Explicit

    Dim WithEvents hooks As Application

    Private Sub Class_Initialize()

    Set hooks = Application

    End Sub

    The code you entered initializes the class to monitor events in MicroStation (in our case we want to look for opening and closing of the design files). Now we have to add the code for the events and for those operations we want to perform when the event occurs. The following code is used to monitor for the open event:

    Private Sub hooks_OnDesignFileOpened(ByVal dgnFileName As String)

    MsgBox "Opening DGN file " + dgnFileName

    End Sub

    This event will get called by your VBA application every time a new design file is opened. The class will provide the "dgnFileName" variable for you to use. Now we need to write the code for the close event:

    Private Sub hooks_OnDesignFileClosed(ByVal dgnFileName As String)

    MsgBox "Closing DGN file " + dgnFileName

    End Sub

    Now that we have our logic written, the final step is to ensure that the Auto-Load option for this project is checked for the Autoload.mvba example, or else we would need to manually load and run the project ourselves.

    In review, we now know how to create and automate VBA applications for Initapps and Dgnapps. They are a convenient and time-saving method to running VBA applications in MicroStation V8.

    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!

     

    • client server 2002
    • Archived Client Server
    • client server
    • Share
    • History
    • More
    • Cancel
    • Elisa McGraw Created by Elisa McGraw
    • When: Tue, Jul 14 2009 2:23 PM
    • Dan Koval Last revision by Bentley Colleague Dan Koval
    • When: Mon, Aug 26 2013 9:10 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