Hello there guys, Good day.
I have a project that watches a certain directory for DGN files to be printed as they are copied. I've read a couple of examples in VBA on how to print to PDF, but I'm having trouble distilling these examples into my code.
I've already written the code that does the monitoring, the only stuff that's missing is the code to print the DGN files to PDF.
Any help on this matter is highly appreciated.
Cheers,
Public Class DirectoryMonitor Dim FolderWatcher as FileSystemWatcher Public Sub New() 'Initialization FolderWatcher = New FileSystemWatcher("D:\PdfConversion", "*.dgn") FolderWatcher.IncludeSubdirectories = True 'Event handler for newly created files AddHandler FolderWatcher.Created, AddressOf FolderWatcher_Created End Sub Public Sub StartMonitoring() ' Start Watching FolderWatcher.EnableRaisingEvents = True End Sub Public Sub StopMonitoring() ' Stop Watching FolderWatcher.EnableRaisingEvents = False End Sub ' Call this function everytime a DGN file gets copied to the monitored folder. Private Sub FolderWatcher_Created(sender as Object, e As FileSystemEventArgs) Dim dgnFileName = e.FullPath ' Code to print to PDF should go here End Sub End Class
Rebuild your app. as a MicroStation AddIn (DLL), not an executable. Connect to MicroStaton using the MicroStationDGN.Application via a .NET InterOp. Now you can use the classes and methods provided by MicroStation VBA.
VBA help is comprehensive and includes many examples. What you need to do is queue the same print commands that you would use in MicroStation to create a PDF.
Regards, Jon Summers LA Solutions
Hello Jon,
Thanks for your advice, but rebuilding the app as an AddIn is not appropriate, I think. Since this app will implemented as a Windows Service for an In-House DGN to PDF conversion server.
I've tried fiddling with Microstation's Interop DLL, and I was able to generate PDFs from every DGN that is copied to the monitored folder. The only problem is, the output PDF gets saved to C:\Windows\SysWOW64.
Public Class DirectoryMonitor Dim FolderWatcher as FileSystemWatcher Dim App as Application; Public Sub New() 'Initialization FolderWatcher = New FileSystemWatcher("D:\PdfConversion", "*.dgn") FolderWatcher.IncludeSubdirectories = True 'Event handler for newly created files AddHandler FolderWatcher.Created, AddressOf FolderWatcher_Created App = new Application() App.ActiveWorkspace.AddConfigurationVariable("MS_PLTFILES", "D:\OutputPDF"); ' Set Output Folder End Sub Public Sub StartMonitoring() ' Start Watching FolderWatcher.EnableRaisingEvents = True End Sub Public Sub StopMonitoring() ' Stop Watching FolderWatcher.EnableRaisingEvents = False End Sub ' Call this function everytime a DGN file gets copied to the monitored folder. Private Sub FolderWatcher_Created(sender as Object, e As FileSystemEventArgs) Dim dgnFileName = e.FullPath Dim dgn = App.OpenDesignFile(dgnFileName, true) Dim paperSize = "ISO_A3" app.CadInputQueue.SendKeyin("MDL LOAD PLOTDLG") app.CadInputQueue.SendKeyin("PRINT DRIVER pdfx.pltcfg") app.CadInputQueue.SendKeyin("print boundary fit all") app.CadInputQueue.SendKeyin("print papername " & paperSize) app.CadInputQueue.SendKeyin("print colormode monochrome") app.CadInputQueue.SendKeyin("print maximize") app.CadInputQueue.SendKeyin("print execute " & System.IO.Path.GetFileName(dgnFileName) & ".pdf") End Sub End Class
Unknown said:The only problem is, the output PDF gets saved to C:\Windows\SysWOW64
MicroStation sends print output to a destination specified by configuration variables. See Printing Configuration Variables in MicroStation help.
Folder paths, such as MS_PLTFILES, must be terminated correctly...
App.ActiveWorkspace.AddConfigurationVariable( _
"MS_PLTFILES", "D:\OutputPDF\")
Unknown said: this app will implemented as a Windows Service for an In-House DGN to PDF conversion server.
this app will implemented as a Windows Service for an In-House DGN to PDF conversion server.
PMFJI, but you should take a look at the End-User License Agreement, particularly about the use of a desktop application as a server-based application. That said, we do have a server-based system that may provide the functionality you are looking for -- it is called ProjectWise InterPlot.
I see. This was being done in another company, so I thought it was a-ok to do something like this.
I will cease my activities, then.