Hi Guys,
I'm using Excel VBA to call Microstation and then from a list of directories open .pset files (previously created manually) contained within each directory. The intention is to open each pset, print to PDF and move onto the next PSET until all in the list are completed.
I have gotten the code to do exactly what I want, however the issue comes when the printorganizer attempts to print a PSET which references corrupt files/folders (in other words it hasn't been setup properly) . From what I can tell this causes a complete failure and the program hangs indefinitely, the message 'waiting for OLE automation etc.' comes up, in the end the excel application has to be closed through the task manager.
What form of error handling will manage this? Print organizer is called using key-in as I don't believe there are objects I can access and therefore I am unable to predict the error state.
Code below:
Sub RunPSets() Dim myDGN As New MicroStationDGN.Application Dim nFile As DesignFile Dim i As Integer Dim ws_FH As Worksheet Dim rngPSETs As Range Dim openPSETDIR As String Dim outputDir As String Dim userWarningList As String Dim answer As Integer Set ws_FH = Application.Worksheets("Fill History") Set rngPSETs = ws_FH.Range("M12:O100") Dim j As Integer outputDir = Main_Form.lblOutputDir.Caption If outputDir <> "" Then For j = 1 To rngPSETs.Rows.Count If rngPSETs.Cells(j, 1) <> "" Then userWarningList = userWarningList & rngPSETs.Cells(j, 1) & " " & rngPSETs.Cells(j, 2) & vbNewLine End If Next j Else MsgBox "Select output directory first!" Exit Sub End If answer = MsgBox("Print to PDF the following Isolations to:" & vbNewLine & outputDir & vbNewLine & vbNewLine & userWarningList, vbYesNo, "Print Isolations") If answer = vbYes Then Const PrintDriver As String = "MTM-PDF-Plotdrv.plt" 'Const PrintDriver As String = "pdf.pltcfg" 'myDGN.CadInputQueue.SendCommand "printorganizer exit" Set nFile = myDGN.OpenDesignFile("J:\Engineering Division\15 Design Production\Signalling\Isolations\- Source Files\Isolation Template.dgn", True) Main_Form.lblStatus.ForeColor = &H40C0& myDGN.CadInputQueue.SendKeyin "mdl load bentley.microstation.printorganizer.dll" 'myDGN.CadInputQueue.SendCommand "printorganizer new" Debug.Print "PRINTING STARTED" For i = 1 To rngPSETs.Rows.Count If rngPSETs.Cells(i, 1) <> "" Then openPSETDIR = rngPSETs.Cells(i, 3) Main_Form.lblStatus.Caption = "Printing....TBA: " & rngPSETs(i, 1) & " " & rngPSETs.Cells(i, 2) myDGN.CadInputQueue.SendKeyin "printorganizer open " & openPSETDIR Debug.Print "PSET OPENED: " & openPSETDIR myDGN.CadInputQueue.SendKeyin "printorganizer printerdriver " & PrintDriver myDGN.CadInputQueue.SendKeyin "printorganizer printdestination " & outputDir & "\" & rngPSETs.Cells(i, 1) & " " & rngPSETs.Cells(i, 2) & ".pdf" myDGN.CadInputQueue.SendKeyin "printorganizer print all" Debug.Print "Printed PSET: " & rngPSETs(i, 1) Main_Form.lblStatus.Caption = "TBA: " & rngPSETs(i, 1) & " " & rngPSETs.Cells(i, 2) & " printed." End If Next i nFile.Close Debug.Print "Printing FINISHED" Set myDGN = Nothing myDGN.Quit MsgBox "Printing has finished!" Else Exit Sub End If End Sub
Does anyone have any ideas how I can safe proof this automation from errors of this type?
Thanks
Regards
Boris
Boris Gabai said: the issue comes when the printorganizer attempts to print a PSET which references corrupt files/folders
Presumably that would also happen if you attempted to use that PSET manually? Post a question to the Printing Forum to see if they have any ideas.
Regards, Jon Summers LA Solutions
Hi Jon,
Yes, when the PSET is accessed manually it does not print - however it simply exists the printing process with an explanation provided by the Message Centre "Unable to find file C:\....".
When I try to automate using key-in, one of the instructions (printorganizer print all?) hangs indefinately. If I could have the code break out of that pset and move onto the next one that would be ideal.
How can I go about moving this thread into the Printing forum?
Boris Gabai said:when the PSET is accessed manually it does not print - however it simply exists the printing process
Create a log of the key-ins you queue to PSET (send them to the Message Center as Debug messages). Then test those key-ins by entering them manually.
Using VBA to queue key-ins should be an identical process to manual key-ins. It's odd that with VBA you cause PSET to crash but with manual key-ins it exits gracefully with a message.
Boris Gabai said:How can I go about moving this thread into the Printing forum?
Use the More|Move button on your OP.