GetFeatureByName Activity
Purpose: This activity searches for a feature in a SolidWorks part document by its name and returns feature information as JSON. It's useful for checking if specific features exist, retrieving feature properties, or validating feature tree structure.
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"
Name of the feature to find. This should match the exact feature name as it appears in the feature tree.
Type: string
Required: Yes
Example: "Boss-Extrude1" or "Cut-Extrude2" or "Fillet1"
Output Properties
The feature information as JSON string. Contains details about the feature including whether it was found, feature type, properties, and other relevant information.
Type: string
Note: If the feature is not found or an error occurs, the JSON will contain an error object with "Found": false and an "Error" property.
Example: {"Name": "Boss-Extrude1", "Found": true, "Type": "Extrude", ...}
Indicates whether the feature was found in the document.
Type: bool
Note: Returns true if the feature exists, false if not found or if an error occurred.
Usage Example
Scenario: Check if a specific feature exists in a part
Configuration:
- DocumentId: "doc-12345"
- FeatureName: "Boss-Extrude1"
Result:
- FeatureFound: true
- FeatureInfo: "{\"Name\": \"Boss-Extrude1\", \"Found\": true, \"Type\": \"Extrude\", ...}"
Scenario: Feature not found
Configuration:
- DocumentId: "doc-12345"
- FeatureName: "NonExistentFeature"
Result:
- FeatureFound: false
- FeatureInfo: "{\"Name\": \"NonExistentFeature\", \"Found\": false, ...}"
Error Handling
Important: The activity handles errors gracefully:
- If the document ID is invalid or the document cannot be found, an
InvalidOperationExceptionwill be caught andFeatureInfowill contain an error object with"Found": falseand an "Error" property - If the feature name is not found,
FeatureFoundwill befalseandFeatureInfowill indicate the feature was not found - Any other unexpected errors will be caught and
FeatureInfowill contain an error object with"Found": falseand"Error": "Unexpected error: {error message}"
Always check the FeatureFound output before using the FeatureInfo data. Review the FeatureInfo JSON for detailed error information if FeatureFound is false.
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
- Feature names are case-sensitive and must match exactly as they appear in the feature tree
- Feature names in SolidWorks typically follow patterns like "Boss-Extrude1", "Cut-Extrude2", "Fillet1", etc.
- The feature must exist in the feature tree for it to be found
- Use this activity to validate feature existence before performing operations that depend on specific features
- The FeatureInfo JSON contains detailed information about the feature, including type and properties
Related Activities
- HasFeatureTreeErrors - Check if the part has any feature tree errors
- ExtractPartData - Extract comprehensive part data
- OpenSolidWorksFile - Open a SolidWorks file to get a DocumentId