SpaceClaim Online Help
|
|
Scripting
|
Refer to the Class for a detailed description of the API. A copy of the Class Library compiled help file (.chm) is included in the installation. The path will be similar to the paths shown below and will change according to the version you are using.
For SpaceClaim: C:\Program Files\SpaceClaim 2016.2\SpaceClaim.Api.V15
For SCDM: C:\Program Files\ANSYS Inc\v172\scdm\SpaceClaim.Api.V15
You can also download the latest version here: https://s3.amazonaws.com/help.spaceclaim.com/downloads/API_Scripting_Class_Library.chm.
If you have trouble viewing the file, check the file properties to see if it needs to be Unblocked.
|
You can work with SpaceClaim programmatically using Python. A built-in script editor allows you to create and run scripts to perform repetitive tasks and work with models and geometry.
Use File>New>Script to begin a new script.
When running SpaceClaim within AIM, use Model>Show Script Editor to begin a new script.
Use File>Open to open an existing script file (*.scscript, *.py).
When you exit SpaceClaim with an open script, you are asked if you want to save the existing script.
Script Editor
The Script Editor has the following functions.
- Open Script -Loads a script from a file
- Save Script -Saves the current script to a file
- Save Script As - Saves the current script by specifying a destination
- Clear - Clears the Script Editor
- Record - Code for scriptable actions performed in SpaceClaim is written in the script window
- Insert Code Snippet - Presents the Snippet dropdown at the cursor in the script window
- Insert Selection - Pastes the current selection as script in the script window. The selection can be identified by:
- ID - The internal ID of each selected entities
- Index - The internal index of each selected entity
- Ray - The internal ray fire point and direction
- Smart Variable - Combines the other methods to make selections persist better when replaying scripts
Smart Variable selection is needed to make selections more stable for replaying changes. A Smart Variable selection stores more information than any of the other types and is much more robust in matching the selected entity during geometry changes.
The image below shows how each selection is scripted for the same selected face. Notice that the Smart Variable selection uses a variable called “Face1”

- Smart Variables have a dropdown GUI, on mouse-over, for investigating references beyond the in-graphics highlighting.

- Find/Replace - Opens a Find and Replace dialog
- Run Next - Executes the next line of the script
- Run Script - Executes the entire script from the top.
Script is written in the main Script Window but can also be entered as single commands in the command line.
Intellisense is included in the editor to assist with entering commands.
The editor supports the following shortcuts:
- Ctrl+K = Comment
- Ctrl+Shift+K = Uncomment
Results of running a script, including error and warnings, are written to the Output Window.
Power Selection and Smart Variables
Power Selection is recorded and, when using Smart Variables, can be used to perform similar operations on multiple bodies.
For example, you can record the power-selection of holes with a certain diameter, and then the filling of those holes with the tool. That script can then be used to fill holes of the same size in other models, even if the number of holes is different.
Re-importing models
Scripting supports recording and playback for imported models with persistent ID maps. This allows the following:
- Start recording
- Import a model from another CAD system
- Make changes to the imported model
- Save the script
- Import a new version of the model (i.e. it was changed and saved in the source system)
- Playback the script on the new version
Notes:
- The import of the model needs to be recorded so that the ID Map is inserted in the script
- The ID Map makes the script binary so that it can only be edited in SpaceClaim
- To import a new version, you need to make sure that the correct version number is called for in the script
Limitations:
- hierarchy in the source system cannot change between imports
- Part names in sub-assemblies cannot change between imports
- The following file types are currently supported
- Spatial IOP Translators
- Part Manager Plugin Translators
- NX
- Pro/E
- CATIA V5
- Inventor
- DesignModeler
Snippets
Snippets are chunks of code that can be inserted into your script. They are presented in a dropdown folder browser with tooltip help describing the function of each Snippet.
You can write your own Snippets and add them to a custom snippet directory. Use the Support Files Paths set in SpaceClaim Options > Support Files to create a directory for storing your Snippets.
- The directory will appear in the Snippets fly-out menu in the Script Editor
- Snippets need to be saved as XML files containing the snippet code and other information (Title, Description, etc.)
To create a snippet, use the following template XML and change the Title, Description, and Code.
This example shows how to use a Code Snippet to create a simple gear.
The model already contains a cylindrical shaft, which could also be constructed using a script.
Open the Examples folder and select the gear Snippet.
The Snippet code loads into the Script Editor window.
Click the Run Script button to build the gear.
Script Groups
Scripts can be saved to to store them in the model. In the Script Editor, open the dropdown menu on the Save button and check Save Script to Group. Click the Save button to create the group and add it to the Scripts folder in the Groups .
Script Parameters
Variables used in scripts can be saved to Parameter Groups. This allows you to easily modify the values without editing the script.
To create a Parameter group
- Create a Script group
- Right-click in the Groups Panel and choose Create Parameter from the menu
- The parameter is created with a default name and a default value of zero
- Rename the Parameter
This example shows how Parameter Groups can be used to modify the parameters of the Gear script.
- Insert the Gear snippet into an empty script.
- Save the script to a Script Group.
- Create a Parameter group as described above and name it "Teeth".
- Look for the variable "nTeeth" in the script and edit it as shown below.

- Click the 'Teeth' Parameter in the Groups Panel and change it to the original value of 20.
- Right-click on the Script Group and choose Run Script from the menu to create a 20-tooth gear.

- Expand the Script Group node in the Groups Panel and see that it displays the current value of the Teeth parameter.

- By default, scripts run after you change a parameter value. Right-click on the Script Group and choose Pause from the menu keep the script from running until you explicitly run it. The script icon in the Groups Panel now has a 'paused' icon.
- Change the Teeth parameter to 40 and see that the script group now has a yellow triangle in the Groups Panel to indicate that the Teeth parameter has changed.

- The snippet does not delete the current gear before it creates a new one. So, delete the current gear and rerun the script to create a 40-tooth gear.

- Right-click in the Groups Panel and create a new Parameter named "oRadius".
- Find the 'oRadius' variable in the script and edit as you did for the Teeth parameter.
- Change the parameter value to 0.02 to match the initial value in the script.
- Right-click on the parameter and change the units to Length.

- Notice that the Parameter value changes to "20mm", indicating that the script assumes length units of Meters.

- Change the value to 30mm and change the number of teeth back to 20
- Delete the current gear
- Run the script to create a gear with 20 teeth and an outside radius of 30mm.

© Copyright 2017 SpaceClaim Corporation. All rights reserved.