Videos > Robust Workflows - Using SpaceClaim Scripting with Ansys Mechanical
Nov 4, 2023

Robust Workflows - Using SpaceClaim Scripting with Ansys Mechanical

Hello everyone, my name is Samuel Lopez. I am an applications engineer at Ozen Engineering, Inc. Today, I'm going to talk about space plane scripting.

Introduction to SpaceClaim Scripting

For those who watched our recent video on parameterization, you know we mentioned the ability to parameterize certain features using space plane scripting. The workflow looks a bit different from what we did in that video, so I'd like to introduce space plane scripting and describe its features and capabilities before diving into how we can use it to parameterize different elements.

What is SpaceClaim Scripting?

SpaceClaim has a feature that allows us to create or modify geometry using scripting. This means that instead of manually drawing geometry by sketching, extruding, and modifying, we can automate the process through scripting. This capability is also available in ANSYS Discovery, which looks similar to SpaceClaim. However, since most users are more familiar with SpaceClaim, I'll present this information in that platform. Note that this information can be applied directly to the Discovery platform as well.

Getting Started with Scripting

  1. Open your model and click on File, then New, and select Script.
  2. A window will open to track your scripting activities. This is where you write your script.
  3. The scripting language used is IronPython. There are many resources available for learning Python, but even if you're not proficient, you can still use SpaceClaim Scripting to create or edit geometry.

Recording Function

The recording function allows you to record actions within the GUI so that the scripting software can write out commands for you. It can write them in two ways:

  • Normal: A short summary of the required commands.
  • Verbose: Includes all commands for the smaller details required to perform the same command in the GUI.

Command Generation Methods

There are three ways to generate commands using the recording feature:

  • Smart Variables: Creates metadata for parts, used to execute commands. Metadata is powerful but can be inefficient.
  • Index: Based on a hierarchy, providing a more structured command generation.
  • Ray: Based on location, specifying where to create a plane, for example.

Creating Models with SpaceClaim Scripting

Let's explore how to use SpaceClaim scripting to our advantage by creating models.

Sketching and Extruding

  1. Use the Plane Tool to create a plane by selecting the Z-axis, which gives an X, Y plane.
  2. Turn on the recorder and sketch an arbitrary rectangle on the plane.
  3. Use the Pull Tool to extrude the sketch, turning it into a 3D surface.

Parameterization

To relate this to parameterization, we can expose variables in the script. For example, instead of using fixed numbers for points, define variables like pt1_x and pt1_y. This makes the script more robust and allows for easy changes to geometry.

Leveraging SpaceClaim Scripting for Simulation

With a basic understanding of SpaceClaim scripting, let's see how it can be used for simulation.

Example: Heat Exchanger Model

I've created a simplified version of a heat exchanger model, similar to a previous parameterization example. At the top of the script, I've exposed parameters used in that example. Instead of defining them in Workbench, I'm manually exposing them here for easier adjustments.

Using Name Selections in Mechanical

By leveraging name selections and the workflow in Mechanical, we can run various iterations quickly. Name selections are collections of bodies or surfaces used for boundary conditions or other features. For example:

  • All Bodies: Used for the physics region, selecting all bodies with a size greater than 0 cubic millimeters.
  • Specific Surfaces: Select faces based on size and location criteria to apply boundary conditions like temperature or convection.

Iterating with SpaceClaim Scripting

To iterate using SpaceClaim scripting, adjust parameters in the script and regenerate the model. Update the geometry in Mechanical to reflect changes, and all boundary conditions and settings remain constant. This allows for quick iterations and simulations.

Conclusion

By using SpaceClaim scripting alongside name selections and Mechanical, we can automate simulations and create different parameters efficiently. If you have any questions, feel free to leave them in the comments section of this video. Additional material on ANSYS scripting and SpaceClaim scripting is available on the ANSYS website. For more information, please reach out to your account manager. Thank you for your time, and talk to you later. Bye.

[This was auto-generated. There may be mispellings.]

Hi everyone, my name is Samuel Lopez. I am an applications engineer at Ozen Engineering, and today I'm going to be talking to everybody about SpaceClaim scripting.

For anyone who saw our video on parameterization, you know that in that video we alluded to being able to parameterize certain features using SpaceClaim scripting.

The overall workflow looks a little bit different from what we did in that video, so I'd like to introduce SpaceClaim scripting and describe all of its features and capabilities before we get into how we can use it to parameterize different things.

SpaceClaim has a feature inherent to it that allows us to create or modify geometry using a scripting feature. This means that instead of having to manually sketch and extrude geometry, we can automate that process by means of scripting.

This capability is also available in ANSYS Discovery and looks much the same way. However, since ANSYS Discovery is newer and most users are probably more familiar with SpaceClaim, I wanted to present this information in the more familiar platform.

To get started with scripting within SpaceClaim, open up your model and click on File, then New, then Script. This will open up a window where you can write your script. The syntax or language that SpaceClaim scripting uses is Iron Python.

Even for users who may not be proficient in using Python, it's still possible to take advantage of some of the features in SpaceClaim Scripting by using the recording function.

This function allows you to record the different things that you're doing in the GUI, and it will write out the commands for you. There are two ways to generate commands with the recording feature: normal and verbose.

Normal will give you a summary of the commands required for a feature, while verbose will include all the commands for all the smaller details. Enough of an introduction. Let me show you how we can use this to our advantage by creating models.

We'll start by going to our sketch tool and changing the recorder to smart variable. Then, we'll click on sketch mode and click on the plane we just created. We'll draw an arbitrary rectangle on that plane, and now we have populated more commands.

These commands are what are used to sketch this rectangle. These commands can be repeated automatically, allowing us to generate the same exact body in the same position. This is helpful when running multiple iterations on the same model.

The more variables we expose and use in our commands, the more robust we can make our script and the more features we can change on our geometry. Now that we have the basic idea for how SpaceClaim scripting works, let me show you a fully scripted out model.

I've exposed many of the same parameters used in the parameterization example and instead of having them be directly defined from within Workbench, I'm manually exposing them here so that I can come back and adjust them.

Once I have all my variables set and run this script, I can generate a solid model and bring it into my mechanical model in Workbench. From here, I can leverage the capabilities of both name selections and the workflow within Workbench to fully flesh out my model and workflow.

Name selections are a collection of different bodies or surfaces that we can then use to apply as boundary conditions or for other types of features.

By defining these selections based on parameters that we know are going to stay the same every single time, we can easily refresh the model and run it again in Workbench without having to set it up every single time.

By leveraging the capabilities of SpaceClaim scripting, name selections, and Workbench, we can run through a variety of iterations very quickly.

The goal is to allow us to make a lot of changes quickly from within the geometry environment, so that we can then go back and run several iterations on it.