SetDocumentUnitSystem Activity
Purpose: This activity sets the unit system of a SolidWorks document. The unit system determines how dimensions, mass properties, and other measurements are displayed and calculated. This is important for ensuring consistency across documents and for calculations that depend on specific units.
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"
Unit system to set. This is an integer value representing the unit system type.
Type: int
Default: 0 (MKS)
The valid values are:
0- MKS (Meter, Kilogram, Second)1- CGS (Centimeter, Gram, Second)2- FPS (Foot, Pound, Second)3- IPS (Inch, Pound, Second)4- MMGS (Millimeter, Gram, Second)
Output Properties
Indicates whether the unit system was set successfully.
Type: bool
Note: Returns false if the document ID is invalid, if the unit system value is invalid, or if an error occurs during the operation.
Usage Example
Scenario: Set a document to use metric units (MMGS) Configuration: - DocumentId: "doc-12345" - UnitSystem: 4 (MMGS) Result: - Success: true (if unit system was set successfully) Next Steps: After setting the unit system, volume and surface area calculations will use the specified units.
Error Handling
Important: The activity handles errors gracefully:
- If the document ID is invalid or the document cannot be found, an
InvalidOperationExceptionwill be caught andSuccesswill be set tofalse - If the unit system value is out of range or invalid,
Successwill be set tofalse - Any other unexpected errors will be caught and
Successwill be set tofalse
Always check the Success output to ensure the unit system was set correctly before performing calculations that depend on units.
Important Notes
- The document must be open in SolidWorks and accessible via the DocumentId
- Setting the unit system affects all measurements in the document, including dimensions, volume, surface area, and mass properties
- Use MMGS (4) for metric manufacturing (millimeters, grams, seconds)
- Use IPS (3) for imperial manufacturing (inches, pounds, seconds)
- Use MKS (0) for scientific/engineering applications (meters, kilograms, seconds)
- Changing the unit system does not convert existing dimensions - it only affects how new values are interpreted
- Set the unit system before performing volume or surface area calculations to ensure consistent units
- This is particularly important when working with documents from different sources or standards
Related Activities
- GetVolume - Get volume (units depend on unit system)
- GetSurfaceArea - Get surface area (units depend on unit system)
- ExtractPartData - Extract part data (units depend on unit system)
- OpenSolidWorksFile - Open a SolidWorks file to get a DocumentId