??? Automating DWG to PDF Conversion using Powershell

??? Automating DWG to PDF Conversion using Powershell

The Convert-DwgToPdf is a PowerShell script designed to automate the conversion of .dwg files to .pdf. In scenarios where programming languages cannot be installed due to security restrictions or when AutoCAD licenses are unavailable, this solution becomes essential. By leveraging DWG True View, file conversion is possible without relying on heavy software or AutoCAD licenses.

Author: Jo?o Gabriel dos Reis Hermida Macêdo

E-mail: [email protected]

References: Amyuni Forum


Benefits of the Solution

This solution automates the batch conversion of files, saving time and reducing human error, which is crucial in production and engineering workflows.


How the Script Works with DWG True View

The integration with DWG True View is achieved through command-line instructions that utilize a predefined plotting function to automatically save the DWG files as PDFs. The process starts with the core PLOT command, which sets up essential printing parameters for the conversion.

Commands used in the DWG TrueView script:

;BEGIN SCRIPT
PLOT
Y
MODEL
DWG To PDF.pc3
ANSI A (11.00 x 8.50 Inches)
Inches
Landscape
No
Extents
Fit
Center
Yes
.
Yes
_quit
;END SCRIPT
        

  1. PLOT: This command initiates the plot or print process.
  2. Y: Confirms that the plot should be printed.
  3. MODEL: Specifies the model space for the plot (where the drawing resides).
  4. DWG To PDF.pc3: Selects the plotting configuration file, which defines settings for outputting to PDF.
  5. ANSI A (11.00 x 8.50 Inches): Sets the paper size to ANSI A (letter size).
  6. Inches: Defines the unit of measurement for the plot.
  7. Landscape: Sets the page orientation to landscape.
  8. No: Disables the option to scale the drawing automatically.
  9. Extents: Ensures the entire drawing fits within the printable area.
  10. Fit: Scales the drawing to fit the page.
  11. Center: Centers the drawing on the page.
  12. Yes: Confirms the plot settings and continues the process.
  13. _quit: Exits the script once the plot is complete.


Step-by-Step Execution Guide

1. Clone or Download the Repository:

Clone or download the Convert-DwgToPdf repository to your local machine.

2. Configure Settings File (config.json):

This file contains the essential parameters for the script to function correctly, including paths to input files, delimiters for CSV files, and the location of the DWG True View executable.

{

 "input-files-path": ".\\input\\ExportPDF.csv",

  "csv-delimiter": ";",

  "dwg-true-view-exe-path": "C:\\Program Files\\Autodesk\\DWG TrueViewpath\\dwgviewr.exe"

}        

  • input-files-path: This specifies the relative or absolute path to the CSV file that contains the information needed for the DWG to PDF conversion. Example: " .\\input\\ExportPDF.csv" (ensure that the file path is correct relative to where the script is located).

  • csv-delimiter: The delimiter used in the CSV file to separate fields.

  • dwg-true-view-exe-path: This is the path to the DWG TrueView executable (dwgviewr.exe). This application is used to open and plot DWG files in the script. Make sure that the path provided corresponds to the correct location where DWG TrueView is installed on your system. Example: "C:\\Program Files\\Autodesk\\DWG TrueViewpath\\dwgviewr.exe"

3. Configure the CSV File:

The script uses a CSV file to read conversion parameters such as input paths, plotting formats, output file names, and more. Ensure that the CSV file is configured correctly with the following columns:

- Document: The DWG file to be converted.

- Plot Format: Specify the paper size format (A4, ANSI A, etc.).

- Output Name: The name for the generated PDF file.

- Input Path: Full path to the DWG file.

- Output Path: Directory where the PDF will be saved.

4. Run the Script:

- Open PowerShell as an administrator.

- Navigate to the project directory.

- Run the script with the following command:

     .\Main.ps1           

5. Monitor Progress:

During execution, the script will process each DWG file according to the parameters specified in the CSV file. Logs will be generated for each conversion, providing real-time feedback.

6. Check Output:

After execution, the converted PDF files will be renamed according to the CSV configuration and moved to the specified output directory.

Error Handling

If an error occurs during the conversion process, the script will display a detailed error message to help resolve the issue.

Important Notes

- Ensure that PowerShell 7 or higher is installed.

- Double-check the CSV file configuration and paths before running the script.

This solution, available on GitHub, is a valuable resource for engineers facing similar challenges in their industries.

Feel free to clone the repository, explore the code, and contribute to improving the solution further.

GitHub Repository: Convert-DwgToPdf

Mateus Maciel

3D Administrator | Developer | BIM

1 个月

Parabéns! Boa abordagem.

要查看或添加评论,请登录

Jo?o Gabriel dos Reis Hermida Macêdo的更多文章

社区洞察

其他会员也浏览了