??? Automating DWG to PDF Conversion using Powershell
Jo?o Gabriel dos Reis Hermida Macêdo
Software Developer | Nodejs | Typescript | .NET | C# | FastAPI | Python
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
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"
}
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
3D Administrator | Developer | BIM
1 个月Parabéns! Boa abordagem.