ExportDrawingToPDF Activity

Purpose: This activity exports a SolidWorks drawing document to PDF format. It can export all sheets to a single PDF file or export each sheet to a separate PDF file. The activity handles document validation, PDF generation, and provides detailed error reporting for troubleshooting.

Input Properties

DocumentId

ID of an open SolidWorks drawing document. This should be the document ID returned by activities like OpenSolidWorksFile or GetActiveDoc.

Type: string

Required: Yes

Example: "doc-12345"

SavePath

The file path or folder path where the PDF(s) should be saved. For single PDF export (ExportSeparateSheets = false), provide the full file path. For separate PDFs (ExportSeparateSheets = true), provide a folder path or base file path - individual PDF files will be created with names based on the base filename and sheet names.

Type: string

Required: Yes

Example (Single PDF): "C:\Output\MyDrawing.pdf" or "C:\Output\MyDrawing"

Example (Separate PDFs): "C:\Output" or "C:\Output\MyDrawing"

ExportSeparateSheets

If true, exports each sheet to a separate PDF file. If false, exports all sheets to a single PDF file. When exporting separate PDFs, each file will be named using the format: {baseFileName}_{sheetName}.pdf, where invalid filename characters in sheet names are replaced with underscores.

Type: bool

Default: false

Required: No

Example: true (for separate PDFs) or false (for single PDF)

Output Properties

Result

For single PDF export (ExportSeparateSheets = false): Full path of the exported PDF file, or empty string if export failed. For separate PDFs (ExportSeparateSheets = true): JSON string containing a dictionary where keys are sheet names and values are the corresponding PDF file paths (empty string if that sheet's export failed).

Type: string

Note: For separate PDFs, the result is a JSON string in the format: {"Sheet1": "C:\\Output\\MyDrawing_Sheet1.pdf", "Sheet2": "C:\\Output\\MyDrawing_Sheet2.pdf"}. If a sheet export fails, its value will be an empty string. If export fails completely, this will be empty string or "{}".

Example (Single PDF): "C:\Output\MyDrawing.pdf"

Example (Separate PDFs): {"Sheet1": "C:\\Output\\MyDrawing_Sheet1.pdf", "Sheet2": "C:\\Output\\MyDrawing_Sheet2.pdf"}

Success

True if the export was successful, false otherwise. For separate PDFs, this will be true if at least one sheet was successfully exported.

Type: bool

Note: Always check this output to verify the export operation succeeded before using the Result output.

ErrorMessage

Error message if export failed, empty string if successful. Contains detailed error information to help troubleshoot issues.

Type: string

Note: Error messages may include: "DocumentId is required.", "SavePath is required.", "Error: {SolidWorks error message}", "Unexpected error: {exception message}", "Failed to export drawing to PDF.", "All sheet exports failed.", or "No sheets found or export failed."

Usage Example

Scenario: Export all sheets from a drawing to a single PDF file

Configuration:
- DocumentId: "doc-12345"
- SavePath: "C:\Output\MyDrawing.pdf"
- ExportSeparateSheets: false

Result:
- Result: "C:\Output\MyDrawing.pdf"
- Success: true
- ErrorMessage: ""
Scenario: Export each sheet to a separate PDF file

Configuration:
- DocumentId: "doc-12345"
- SavePath: "C:\Output\MyDrawing"
- ExportSeparateSheets: true

Result:
- Result: "{\"Sheet1\": \"C:\\\\Output\\\\MyDrawing_Sheet1.pdf\", \"Sheet2\": \"C:\\\\Output\\\\MyDrawing_Sheet2.pdf\"}"
- Success: true
- ErrorMessage: ""

Error Handling

Important: The activity handles errors gracefully:

  • If DocumentId is empty or null, validation error will be caught and ErrorMessage will contain: "DocumentId is required."
  • If SavePath is empty or null, validation error will be caught and ErrorMessage will contain: "SavePath is required."
  • If the document is not found or not a drawing document, InvalidOperationException will be caught and ErrorMessage will contain: "Error: {error message}"
  • If the PDF export fails, ErrorMessage will contain: "Failed to export drawing to PDF." (single PDF) or "All sheet exports failed." (separate PDFs)
  • If no sheets are found when exporting separate PDFs, ErrorMessage will contain: "No sheets found or export failed."
  • If any other unexpected error occurs, Exception will be caught and ErrorMessage will contain: "Unexpected error: {exception message}"

Always check the Success output to ensure the export operation completed successfully before using the Result output.

Important Notes

  • The drawing document must be open in SolidWorks and registered in the document management system (via activities like OpenSolidWorksFile or GetActiveDoc)
  • The document must be a drawing document type - part or assembly documents will cause an error
  • For single PDF export, the file path extension will be automatically changed to .pdf if not already present
  • For separate PDFs, sheet names are sanitized for use in filenames - invalid filename characters are replaced with underscores
  • If the output directory does not exist for separate PDFs, it will be created automatically
  • Existing PDF files with the same name will be automatically deleted before export
  • When exporting separate PDFs, the Success output will be true if at least one sheet was successfully exported, even if some sheets failed
  • For separate PDFs, check the JSON result dictionary to see which specific sheets succeeded or failed (empty string value indicates failure for that sheet)
  • This activity does not register new documents - it only uses the provided document ID to access an already-open drawing document

Related Activities