MicroStation VBA for AutoCAD Users30 Apr, 2003 By: Barry Bowen
Common language automates tasks.
CAD departments often must exchange drawing files between AutoCAD and MicroStation. You may use subcontractors who work with MicroStation or have clients who require final as-builts in MicroStation. However it happens, when you find yourself in this situation, VBA (Visual BASIC for Applications) can help automate manual tasks.
MicroStation can't execute AutoLISP programs, but it does include a VBA interface similar to AutoCAD's. Both programs use Microsoft's Visual BASIC editor, where you can create VBA macros and more complex VBA projects with dialog box user interfaces. If you are new to MicroStation and not familiar with its commands, enter the VBA Macro Recorder.
This feature is provided with MicroStation to help you write VBA macros more quickly and easily. Although the code that it records may not be suitable for immediate playback, you can later revise the code to be more user friendly. This feature is extremely useful when I'm not familiar with a command structure. Autodesk should consider it for AutoCAD's future.
RECORD A VBA MACRO IN MICROSTATION
From the MicroStation Utilities menu, choose Macro | Create Basic Macro. In the Create Macro dialog box, name the macro, type a
The recording process begins with the VCR-like buttons on the macro control panel. MicroStation now watches and records all your actions. Start performing the actions you want to record-selecting tools, placing elements, opening and closing dialog boxes, and so forth.
When you have performed all of the actions to be recorded, click the stop button in the control panel or select the pause button to temporarily suspend recording. Once recording stops, the control panel closes and the macro program ends.
This is the first step in creating a prototype VBA program that you can shape into its final form using the VBA editor. As an example, I placed a smartline between two randomly selected points, which was recorded in the code in the box at right.
As you can see, the macro generator records the exact locations of the points selected for the line. Every time the macro runs, the line appears in the exact same location. Therefore, to make the program more usable, you must edit the basic program.
To edit the macro, select Utilities | Macro | MicroStation Basic. The Macros dialog box appears with a list of macros for execution or editing. Select the macro you want, and then click Edit to open the Basic Editor that shows the recorded code.
RUN A VBA MACRO
Once you write the macro, you run it to execute the instructions. This is the same as playing back a VBA macro that was recorded using the Record feature. From within the editor, select the Run menu, then choose Run Sub | User Form.
That's itMicroStation makes it easy to get started creating VBA macros without knowing the MicroStation BASIC language extensions. In future articles we'll explore the VBA connection in more detail.