Writing a SolidWorks Simulation application typically involves:
Instantiating a SolidWorks connection.
Getting the COSMOSWorks object.
Getting the model document object. Opening a document is required before trying to create a study.
Using the study manager object to create a study.
After creating a study, you can use the SolidWorks Simulation API to:
When appropriate, the Simulation API returns an error status code. Sometimes, directly returning a status code is not possible. When appropriate, the SolidWorks Simulation API returns an error code (a 32-bit value) which is 0 for success and non-0 for error.
SolidWorks Simulation recommends that you use the intrinsic Visual Basic Err object to get rich error information. In this case, the Err.number field does not correspond directly to the SolidWorks Simulation error code, but mappings back to the error code are provided. The Err.Description field contains a descriptive text field indicating the error. Better tracing of errors can be done through the Err object.
In Visual Basic, error handling can easily be accomplished with the On Error Resume Next statement.
The use of persistent IDs is more likely to get the proper entities' selections when the geometry of the model is changed. An executable (pidcollector.exe) is provided in install_dir\api to help you get the persistent IDs of selected entities.
- Returns valid PIDs only from models that are created in the current release.
- Does not return valid PIDs from models created in previous releases.
- Does not return valid PIDS from models created in previous releases that have been saved in the current release.
To use pidcollector.exe:
- Double-click pidcollector.exe while SolidWorks is running and a SolidWorks document is active.
- Make a selection in the document and click Copy PIDS to clipboard in the PID Collector dialog.
- Paste the text copied to the clipboard into your application.
- Edit the pasted text as needed.
- Repeat steps 2 through 4 for each selection for which you want its PID.