Running a keyin at startup

Is it possible to run a keyin at startup? I saw this AskInga article from 2002 that says one can create a txt file and then point the icon properties to it but I imagine that's pretty out of date by now?

Parents Reply Children
  • Is the autorun.mvba a generic file that calls out another key in file? Do i need to write autorun.mvba? I have a complex text file already written for a certain client and would like to just have it run that file via the pcf. It's a pain to try and use this through the shortcut icon. 

  • While It may be possible to have an AutoRun.mvba that called and executed a script, I couldn't tell you howe to do that, exactly.

    I have it run my key-ins directly. If you use the one from the links in this thread, you don't have to write it from scratch - you just have to edit it.

    Basically, you would load the MVBA through the project manager, highlight it in the list, then click the icon for Visual Basic editor which will open its own window.

    You want to edit the Class module of the AutoRun project - it's called "clsDGNOpenClose"

    There are two subroutines in this code that you will edit: m_OpenCloseHooks_OnDesignFileOpened and m_OpenCloseHooks_OnDesignFileClosed.
    These correspond to "commands I want to run any time I open a file" and "commands I want to run any time a file is closed"

    You can send input a few different ways, but if you already have your keyins figured out, you would add lines that look like

    CadInputQueue.SendKeyin "update fields"

    except that my "update fields" would be whatever your keyin string would be. You do need the "quote" marks.

    Once you've done that, you Save your updated macro.

    To make sure that it runs every time you use MicroStation, you can check the "Autoload" column in the VBA project manager. This will write the file name into your user configuration. Alternately, you can directly edit your configuration (UCF, PCF, etc.) to add the path and name of your MVBA to the MS_VBAAUTOLOADPROJECTS variable

    MaryB

    Power GeoPak 08.11.09.918
    Power InRoads 08.11.09.918
    OpenRoads Designer 2021 R2

        

  • There is a special feature of MicroStation VBA where if you have a subroutine named OnProjectLoad() it will be executed when ever that vba project is loaded (note it does not automatically run when a new file is opened, just when the vba is loaded).

    Additionally there is a key-in in MicroStation @"scriptfile" that will run the key-ins in the specified scriptfile. Scriptfile can be a complete path. Finally there is another key-in EXPAND KEYIN that lets you use Configuration variables in a keyin command. EXPAND KEYIN can be shortened to $.

    This vba:

    Sub OnProjectLoad()
    Dim scriptFile As String
    
    scriptFile = "path\to\script\file"
    '-- to run script file listed in variable STARTUP_KEYINS: scriptFile = "$(STARTUP_KEYINS)"
    CadInputQueue.SendCommand "$ @""" & scriptFile & """"
    
    End Sub

    will run the script file specified in the scriptFile string whenever the vba project is loaded. use MS_VBAAUTOLOADPROJECTS variable to automatically load the vba when MicroStation starts.

    If you also set a variable pointing to your script file in your configuration, for example: STARTUP_KEYINS = path\to\script.txt, and adjust the vba to use that variable.

    Summary:

    1. create vba with OnProjectLoad() subroutine
    2. set the vba to automatically load in your config with MS_VBAAUTOLOADPROJECTS variable
    3. define variable STARTUP_KEYINS as the path to the text file of key-ins you want to run

    If you want the key-ins to run anytime a dgn is loaded you'll need to use Mary's instructions to use clsDGNOpenClose

     

  • Thank you so much!!! This was very helpful and very easy to do. Much appreciated.