GetAllPartFileFromDirectory Activity

Purpose: This activity gets all part files from a specified directory. It searches the directory and returns a dictionary of part files as a JSON string, where keys are file paths and values are file names. This is useful for batch processing multiple SolidWorks part files.

Input Properties

RootPath

Root directory path to search for part files. The activity will search this directory for SolidWorks part files.

Type: string

Required: Yes

Example: C:\Projects\SolidWorks\Parts or D:\CAD Files\Components

Output Properties

PartFiles

Dictionary of part files as JSON string. The format is a dictionary where keys are full file paths and values are file names.

Type: string

Note: If an error occurs or no files are found, this will contain an error message or an empty JSON object "{}".

Example: {"C:\\Parts\\Part1.SLDPRT": "Part1.SLDPRT", "C:\\Parts\\Part2.SLDPRT": "Part2.SLDPRT"}

Count

Number of part files found in the directory.

Type: int

Note: Will be 0 if no files are found or if an error occurs.

Usage Example

Scenario: Get all part files from a directory for batch processing

Configuration:
- RootPath: "C:\Projects\SolidWorks\Parts"

Result:
- PartFiles: "{\"C:\\\\Projects\\\\SolidWorks\\\\Parts\\\\Part1.SLDPRT\": \"Part1.SLDPRT\", \"C:\\\\Projects\\\\SolidWorks\\\\Parts\\\\Part2.SLDPRT\": \"Part2.SLDPRT\"}"
- Count: 2

Next Steps:
Parse the JSON string to get individual file paths, then use OpenSolidWorksFile activity to open each file for processing.

Error Handling

Important: The activity handles errors gracefully:

  • If RootPath is null or empty, PartFiles will be set to "{}" and Count will be 0
  • If the path is invalid (does not exist or is inaccessible), an ArgumentException will be caught and PartFiles will contain: "Error: Invalid path - {error message}"
  • Any other unexpected errors will be caught and PartFiles will contain: "Error: {error message}"
  • When errors occur, Count will be set to 0

Always check the Count output to verify files were found, and check that PartFiles doesn't start with "Error:" before parsing the JSON.

Important Notes

  • The directory path must be accessible from the server/workflow execution environment
  • The activity searches for SolidWorks part files (typically .SLDPRT extension)
  • The returned JSON is formatted with indentation for readability
  • Use the Count output to verify files were found before processing
  • The JSON string can be parsed using JSON parsing activities or in subsequent workflow steps
  • File paths in the JSON use escaped backslashes (e.g., C:\\Path\\File.SLDPRT)
  • This activity only discovers files - it does not open them. Use OpenSolidWorksFile to open each file

Related Activities