Dear Bentley Community,
I have a macro which does some things and then opens the print dialog box. When the user clicks on the print dialog box and closes the window, I would like to display a messagebox. Can anyone provide code to caputre this window close event or prevent my code from continuing while the window is open?
Thanks in advance,
Christmas May
What happens if you record a VBA macro while opening/closing the print dialog? Does the recorded code tell you when the dialog is closed?
recording a VBA macro
Regards, Jon Summers LA Solutions
I won't be back in contact with a machine that has Microstation for a couple days. However, I did try this. . . it didn't seem to record much? I'll try again in a day or two.
Here is the code recorded when I close the plot dialog box.
Sub Macro1()
Dim startPoint As Point3d
Dim point As Point3d, point2 As Point3d
Dim lngTemp As Long
' Start a command
CadInputQueue.SendCommand "PRINT EXIT PLOTDLG"
CadInputQueue.SendCommand "MDL UNLOAD PLOTDLG"
CommandState.StartDefaultCommand
End Sub
Well, that doesn't really tell us much other than that the command to unload the PLOTDLG application was queued. You'll have to find another approach.
There are two things you could monitor …
You can check for the first easily enough. Here's how to check if an MDL app. is loaded.
Presumably you'll need to set up a timer and check periodically for the presence or absence of PLOTDLG.
It appears the function mdlSystem_getTaskStatistics requires two variables ( statisticsP and taskIdP). What are the options for the first variable statisticsP? The second variable is fairly self-explainatory.
Also, do you have a list of functions available in stdmdlbltin.dll?
Unknown said:What are the options for the first variable statisticsP?
The function mdlSystem_getTaskStatistics is documented in the MDL Help manual. However, for your purpose the variable is not used and is set to zero. The code in the link I cited shows how to use that function in VBA.
Unknown said:Do you have a list of functions available in stdmdlbltin.dll?
If you browse the MDL Help manual you will find several thousand functions. Some are implemented in stdmdlbltin.dll, others in one of the many DLLs delivered with MicroStation.
Where would I acquire a copy of the MDL Help manual?
Here is the code I have so far, and to the best of my knowledge it works as desired. If you have any comments/suggestions, then please feel free. . .
Option Explicit
Declare Function mdlSystem_getTaskStatistics Lib "stdmdlbltin.dll" (ByVal statisticsP As Long, ByVal taskIdP As String) As Long
Private Sub cPause(cSeconds As Single)
Dim cStartTime As Single Dim cFinishTime As Single 'Get the current number of seconds since the beginning of the day cStartTime = Timer cFinishTime = cStartTime + cSeconds 'Adjust for midnight If cFinishTime > 86400 Then cFinishTime = cFinishTime - 86400 Do Until Timer > cFinishTime DoEvents Loop End Sub
Sub Main() Dim cPlotDialog As Boolean 'Before MsgBox "Before" 'During CadInputQueue.SendCommand "DIALOG PLOT" MsgBox "During" 'After cPlotDialog = True Do While cPlotDialog = True If mdlSystem_getTaskStatistics(0, "PLOTDLG") = 0 Then cPlotDialog = True Else cPlotDialog = False End If 'Pause 0.1 seconds for user interface with Microstation (i.e. close the Plot Dialog box) cPause (0.1) Loop MsgBox "After"End Sub
You suggested monitoring two things. The first of which was monitoring if the PLOTDLG was loaded. Because a link to example code was provided, I used this method. However, I'm uncertain what you meant by monitoring if the the print dialog is open? What's the difference?
NEVERMIND. I now see there is a Microstation configuration variable MS_PLTDLG_UNLOADONCLOSE which somewhat ties the "close" operation to the "unload" operation. As you might have guessed mine was set so that closing the dialog unloaded the application. Why would you want the application to remain loaded? . . . I speculate it might improve system response time?
Sincerely,
Unknown said:Why would you want the application to remain loaded?
PLOTDLG.MA is MicroStation's printing application. The print dialog is the visible manifestation of that application.
If you browse the PLOTDLG keyins, you will find that printing can be controlled entirely through a set of commands. In other words, you might want PLOTDLG.MA with no visible interface if you (or a VBA or MDL or .NET application) want to create prints by sending a sequence of commands.
Plot Composer is an example of such an application.
Unknown said: Where would I acquire a copy of the MDL Help manual?
The MicroStation SDK is likely what you are looking for. The SDK for MicroStation V8 XM Edition (as well as for MicroStation V8i) can be downloaded from SELECTservices Online -- the SDK is a parallel download to the MicroStation product installation set. There is a recent version of the SDK available from www.bentley.com/developer and then following the "Software Developer Resources" link.