Monthly Archives January 2025

UNDER_CONSTRUCTION

Posted by Nabil Kherouf
on January 28, 2025
Comments Off on UNDER_CONSTRUCTION

Automatic Plotting of DGN/DWG files into PDF files using Bentley InterPlot (UNDER CONSTRUCTION)

Background

Per one of our client’s request, we created a self-service C#.NET web portal that enables remote field personnel to launch job orders to select a set of desired set of DGN/DWG drawings, create individual PDF outputs for each drawing, and then programmatically combine all PDFs into one multi-page file that gets emailed back to user.

To accomplish this we used the Bentley InterPlot plotting utility, Mfilemon an open source Windows print monitor (“print to file”) and GhostScipt an open source PostScript interpreter to create PDF files from InterPlot output. GhostScipt does also offer a combine command that we used to merge all the individual PDFs into one multi-page file. 

To process jobs in a timely manner, we used HangFire, an open-source framework that allows developers to schedule and manage background jobs in .NET and .NET Core.  

Introduction

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"

Setting up the print monitors in iPlot

Continue Reading
MENU