GetPartMaterial Activity
Purpose: This activity gets the material name assigned to a SolidWorks part document. The material name indicates which material library entry is applied to the part, which is important for mass properties, rendering, and manufacturing information.
Input Properties
ID of an open SolidWorks document. This should be the document ID returned by activities like OpenSolidWorksFile or GetActiveDoc.
Type: string
Required: Yes
Example: "doc-12345"
Output Properties
The material name of the part. This is the name of the material from the SolidWorks material library that is assigned to the part.
Type: string
Note: If an error occurs, this will contain an error message starting with "Error: " or "Unexpected error: ". If no material is assigned, it may return an empty string or a default value.
Example: "Steel" or "Aluminum 6061" or "Plastic - ABS"
Usage Example
Scenario: Get the material assigned to a part Configuration: - DocumentId: "doc-12345" Result: - MaterialName: "Steel" (or error message if failed) Next Steps: Use the MaterialName for validation, reporting, or to determine appropriate manufacturing processes.
Error Handling
Important: The activity handles errors gracefully:
- If the document ID is invalid or the document cannot be found, an
InvalidOperationExceptionwill be caught andMaterialNamewill contain:"Error: {error message}" - If the material cannot be retrieved,
MaterialNamewill contain an error message - Any other unexpected errors will be caught and
MaterialNamewill contain:"Unexpected error: {error message}"
Always check the MaterialName output to ensure it doesn't start with "Error:" before using it in subsequent activities.
Important Notes
- The document must be a SolidWorks part document (not an assembly or drawing)
- The document must be open in SolidWorks and accessible via the DocumentId
- The material name comes from the SolidWorks material library that is assigned to the part
- If no material is assigned to the part, the result may be empty or indicate no material
- Material names are typically formatted like "Steel", "Aluminum 6061", or "Plastic - ABS"
- The material affects mass properties calculations and rendering appearance
- Use this activity to validate material assignments or extract material information for reports
Related Activities
- ExtractPartData - Extract comprehensive part data including material
- GetVolume - Get the volume of a part (affected by material density)
- OpenSolidWorksFile - Open a SolidWorks file to get a DocumentId