SpaceClaim Online Help
You are here: Customizing SpaceClaim > Scripting

Scripting

 

Refer to the Class LibraryClosed 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.

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:

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 FillClosed 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.

 

The example below shows six holes power-selected, filled and recorded.

   
The script is then run on a different model and 12 holes with the same diameter are filled.

 

Re-importing models

Scripting supports recording and playback for imported models with persistent ID maps. This allows the following:

 

  1. Start recording
  2. Import a model from another CAD system
  3. Make changes to the imported model
  4. Save the script
  5. Import a new version of the model (i.e. it was changed and saved in the source system)
  6. Playback the script on the new version

Notes:

Limitations:

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.

To create a snippet, use the following template XML and change the Title, Description, and Code.

 

ClosedSnippet example

Script Groups

Scripts can be saved to GroupsClosed 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 PanelClosed.

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

  1. Create a Script group
  2. Right-click in the Groups Panel and choose Create Parameter from the menu
  3. The parameter is created with a default name and a default value of zero
  4. Rename the Parameter
ClosedScript Group and Parameter example

 

 

 


© Copyright 2017 SpaceClaim Corporation. All rights reserved.