Archive | August 2013

Transparent Dialogs

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.

td01

Go to Workspace | Preferences | Look and Feel. Check the box, “All modeless dialogs use the same transparency”.

td02

Click OK. Click Stop in the VBA Project Manager (the square white button).

td03

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.

td04

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.

td05

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.

td06

td07

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 mstefanchuk@cadmanage.com.

photogeoDWG

VBA Custom Configs

by Mark Stefanchuk, cadmanage.com

I’m not really a big fan of increasing the number of MicroStation config variables. Where possible, try to use built in variables. For example, you can use CreateCellElement3

with just the name of the cell as long as the cell library is defined in MS_CELLLIST. You might have something that looks like this in your VB code.

oCell = MainForm.oMSApp.CreateCellElement3(MainForm.uc_o.txtCameraName.Text, Point, True)

This is from a VB.Net example, that’s why the MicroStation Application object is included.

Here’s how I might define MS_CELLLIST for use with photogeoDGN.

CADMANAGE = C:/ProgramData/Cadmanage/PhotogeoDGN/Contents/
MS_ADDINPATH < $(CADMANAGE)Windows/8.11/
MS_CELLLIST < $(CADMANAGE)Resources/*.cel

Sometimes however, it is necessary to identify a special folder or some other resource in your custom program. For example, your program might include a catalog file that provides some engineering data that your program will associate with a cell. You could decide to put this in a resources folder that is always in the install directory. But, a better solution might be to let the end user decide where she wants to save the resource. In this case the resource or file is one that MicroStation doesn’t know anything about, but your program has to be able to find. To fix that we could define the following,

CMRI_CATALOG = $(CADMANAGE)Resources/testcatalog.xml

Put the variable in one of MicroStation’s configuration files, like your UCF. Now, to access the variable from your custom VBA program you need to use ConfigurationVariableValue. Here’s how to do that in VBA.

Sub testConfig()
Debug.Print ActiveWorkspace.ConfigurationVariableValue("CMRI_CATALOG")
End Sub

The example will print the value of the configuration variable in the VBA IDE’s immediate window.

C:\ProgramData\Cadmanage\PhotogeoDGN\Contents\Resources\testcatalog.xml

Use this expansion to open the file, or in this case define your XML document object.

As long as the variable name is different than any other MicroStation config variable, you can use it, but I would recommend  including a prefix. In the previous example, I used CMRI (for CAD Management Resources, Inc). This just helps to avoid variable conflicts.

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 mstefanchuk@cadmanage.com.

photogeoDWG

photoDGN Beta

The National Map Viewer

There’s a great resource for those of you who use U.S. imagery in their projects. The National Map Viewer is a great resource. Also, be sure to check out Brian Hailey’s post from last year – An Alternative to Google Earth. He highlights the accuracy issue and provides some instruction for using the national map viewer (previously called seamless viewer). Brian includes a link in his article to a Being Civil post that provides detail for this issue. Check it out.