by Mark Stefanchuk, cadmanage.com
I was playing around with MicroStation preferences the other day and something was bugging me. Turning on/off dialog transparency was clumsy. I know it’s a user preference and that it’s normally on or normally off, but opening the preferences dialog, finding the transparency preference seemed to be more cumbersome than it should be. It was definitely not quick. In this case I just want to switch on/off the dialog transparency without having to go through the steps of opening checking and clicking ok – just to turn transparency on. Call me lazy.
So, to shorten the steps, I used the VBA macro recorder to capture the actions needed to turn on transparency.
To record the macro, open the VBA Project Manager dialog – Utilities | Macro | Project Manager. The project manager dialog will open. Select the Default project in the VBA Project Manager. Click the red circle to start recording.
Go to Workspace | Preferences | Look and Feel. Check the box, “All modeless dialogs use the same transparency”.
Click OK. Click Stop in the VBA Project Manager (the square white button).
I then cleaned up (deleted) all of the extra lines of code that the recorder adds. That is, the lines we don’t need.
This records the steps in your VBA. It creates a new Macro and a Macro Handler (to control the dialog box). The recording process adds a lot of extra code that we don’t need. You can remove the extra code. Your code will look similar to the following when you are done.
Sub Macro1() 'turn on dialog transparency Dim modalHandler As New Macro1ModalHandler AddModalDialogEventsHandler modalHandler CadInputQueue.SendCommand "MDL SILENTLOAD USERPREF" RemoveModalDialogEventsHandler modalHandler End Sub
And the handler will look similar to the following.
Implements IModalDialogEvents Private Sub IModalDialogEvents_OnDialogClosed _ (ByVal DialogBoxName As String, _ ByVal DialogResult As MsdDialogBoxResult) End Sub Private Sub IModalDialogEvents_OnDialogOpened _ (ByVal DialogBoxName As String, _ DialogResult As MsdDialogBoxResult) If DialogBoxName = "Preferences [untitled]" Then ' Set a variable associated with a dialog box SetCExpressionValue "savePrefs.addFlags.dialogsUseSameTranparency", 1, "USERPREF" ' Remove the following line to let the user close the dialog box. DialogResult = msdDialogBoxResultOK End If ' Preferences [untitled] End Sub
The Macro is saved in Module1 and the handler is saved in the Class Module folder of the VBA. The macro opens the preferences dialog. It also starts and stops the event handler. The handler does the work. It turns on the transparency. All of this is built for you when you record the macro. All you have to do is remove the code that you don’t need.
Next, we want a command to turn off the transparency. Just copy Macro1 and rename it as Macro2. Change Macro1ModalHandler to Macro2ModalHandler.
Sub Macro2() 'turn on dialog transparency Dim modalHandler As New Macro2ModalHandler AddModalDialogEventsHandler modalHandler CadInputQueue.SendCommand "MDL SILENTLOAD USERPREF" RemoveModalDialogEventsHandler modalHandler End Sub
Now, create a new class module called Macro2ModalHandler. Copy the contents of Macro1ModalHandler to this new class module. Finally, in the line that starts with SetCExpressionValue, change the 1 to a 0 (i.e. on to off). Like this.
Private Sub IModalDialogEvents_OnDialogOpened _ (ByVal DialogBoxName As String, _ DialogResult As MsdDialogBoxResult) If DialogBoxName = "Preferences [untitled]" Then ' Set a variable associated with a dialog box SetCExpressionValue "savePrefs.addFlags.dialogsUseSameTranparency", 0, "USERPREF" ' Remove the following line to let the user close the dialog box. DialogResult = msdDialogBoxResultOK End If ' Preferences [untitled] End Sub
The last thing we want to do is add these commands to the UI so that we have and easy way to run the commands.To do this I added a new dgnlib to my workspace. I’m using the default untitled workspace, so I added the dgnlib to $(MS)\Workspace\projects\untitled\DGNLIB\. While in the dgnlib, open the Customize dialog box – Workspace | Customize. Add a new toolbox and two new tools. Change the names as shown in the image below.
On the first tool change the Key-in to vba run macro1. This will run the macro that turns off dialog transparency. On the second tool change the Key-in to “vba run macro2”. I’ve also changed the icon. The default tool icon is the wrench. You can select any icon you want. I just took a couple of icons from ustation.rsc (tools I don’t use very often).
Now, right click on the new toolbox name and select “Open Tool Box”.This is what mine looks like.
You can dock this on your MicroStation window. I dock mine at the top so that I can quickly access these buttons. So, now I can control dialog transparency without multiple clicks.
About Mark Stefanchuk: Mark is a VP and senior consultant with CAD Management Resources, Inc. He divides his time between developing innovative custom software solutions and helping clients navigate complex design automation environments. If you would like to find out how he can assist you with your design technology he can be reached directly at firstname.lastname@example.org.