Problem statement: telecom field personnel needed a way to automate creation of PDF files of DGN/DWG/Raster drawings and have them delivered to at the job site electronically.
Current workflow: The approach to obtaining a set of paper drawings was to request a set prints through a web portal the night before then drive to the nearest service center to pick up the paper print set before heading to the job site – a very inefficient process.
Initially, InterPlot Organizer was considered as a means to launch batch plot requests, but it did not have the ability to remotely submit job requests. Thus a new method of creating PDF output on-demand was needed.
Solution: We created a C#/.NET Windows Service server-based PDF Plotting Solution that runs in the background monitoring for plot requests. When a plot request is detected in the specified input folder, the plotting request is put into a queue of jobs that get executed in the order received. The PDF Plotting Solution manages creation of the PDF output using the following software packages:
- Bentley InterPlot is launched to create PostScript output which is converted to PDF using Ghostscript
- GhostScript is used to create individual PDF output files from PostScript files generated by InterPlot. It is also used to combine individual PDF files into a multi-page PDF
- mfilemon, an open source Windows print monitor, is used to direct plotting output from InterPlot to GhostScript to create the PDF output
- HangFire, open source Windows C#/.Net on server side background queue processing package enqueues and prioritizes multiple plotting requests. It also provides an interactive console of current job in the queue
- Windows .Net System.Net.Mail.MailMessage class to email multi-page PDF to field personnel
First step in the plotting process is to use Bentley InterPlot which requires the execution of 3 commands to generate the PDF intended from a DGN/DWG: iPlot Create, iPlot Generate, and iPlot Submit. These 3 commands have to be preceded by the PrePlot command which performs the prerequisites needed for the iPlot commands to run successfully namely attaching the .cit raster ref file, border-size analysis, and loading of the settings file.
Running the PrePlot command:
Following is the command needed to run PREPLOT:
"...\ustation.exe" -wapreplot -wupreplot dgn_dwg_filename
The following code shows the creation and the launching of a windows process in C# that runs the command above:
/*----------------------------------------------------------------------+
| Name Run_PrePLot |
| |
| Desc Runs PrePlot on curr dgn file. |
| |
| Author Nabil 03/24 |
+----------------------------------------------------------------------*/
[AutomaticRetry(Attempts = 0)]
public RETURN_VAL Run_PrePLot(string file)
{
Process process = new Process();
try
{
string file_with_ext = Path.GetFileName(file);
process.StartInfo.FileName = ConfigurationManager.AppSettings["USTATION_EXE"]; //Path where the uStation.exe is
process.StartInfo.WorkingDirectory = tmp_processing_dir;
process.StartInfo.Arguments = "-wapreplot -wupreplot " + file_with_ext;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
log.Info(" Running preplot: " + process.StartInfo.FileName + " " + process.StartInfo.Arguments);
using (Process myProcess = Process.Start(process.StartInfo))
{
myProcess.WaitForExit(-1);
log.Info(" Exit code: " + myProcess.ExitCode);
while (!myProcess.StandardOutput.EndOfStream)
{
string line = myProcess.StandardOutput.ReadLine();
log.Info(" " + line);
}
while (!myProcess.StandardError.EndOfStream)
{
string line = myProcess.StandardError.ReadLine();
log.Info(" " + line);
}
if (myProcess.ExitCode != 0)
{
mcs_logger.Warn("Process exited with code: " + myProcess.ExitCode + ". " + myProcess.StartInfo.FileName + " " + myProcess.StartInfo.Arguments);
return RETURN_VAL.WARNING;
}
}
}
catch (Exception ex)
{
log.Error(" Unable to run uStation/Preplot: " + process.StartInfo.FileName + "\n Exception: " + ex.Message);
return RETURN_VAL.FATAL_ERROR;
}
return RETURN_VAL.SUCCESS;
}
Running the iPlot commands:
The following commands show the arguments needed to run the 3 iPlot Commands:
"...\iplot.exe" -create -design="filename.dwg" -region=[""] -view=1 -settings="settings_file.cit" output_filename
"...\iplot.exe" -generate output_filename
"...\iplot.exe" -submit
After running these commands, the PDF for the specified DGN/DWG file will be successfully created provided that printer monitor (MFilemon and GhostScript) have been set up properly. We will explain here-after how to properly set up the file monitor in IPlot but first let’s run the GhostScript command to combine the generated PDFs.
Combining the individual PDFs using GhostScript:
The following GhostScript command will combine the PDFs specified :
"C:\Program Files\gs\gs10.01.2\bin\gswin64" -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=\"" + combined_pdf_name + "\"" + " pdf_file1.pdf pdf_file2.pdf pdf_file3.pdf pdf_file4.pdf"