February 28, 2017
Geometry scripting, macros and batch files are great ways to automate repetitive tasks or reduce a complicated workflow to a single mouse click. Although you may have never written or recorded your own script, there’s a good chance you’ve benefited from one created by someone else.
Ansys SpaceClaim recently introduced a geometry scripting environment that further eases common geometry related tasks. More specifically, it’s a simple way to record or write a set of commands that will automate repetitive tasks or make complicated workflows easy. It also serves as a method of extending the user interface to make otherwise impossible geometry by expanding the different things you can do with geometry. From replaying recorded changes on imported models to parameterizing variables only thought possible in a feature-based system, scripting is a powerful ally in making smart, robust geometry.
The scripting environment in ANSYS SpaceClaim is
an easy way to construct and edit models without having
extensive programming experience.
If you are new to scripting, I’d suggest learning a little about the Python programming language and what it can do. Scripting in the SpaceClaim environment uses IronPython, which is an open source language built on Python. Some understanding of the syntax and what is expected with commands will help you hit the ground running.
My second suggestion would be to record yourself using SpaceClaim. Just as you may have used a macro before in other popular applications, SpaceClaim will record each modeling step you perform and capture all necessary parameters required to repeat your operation. For example, as you use tools like Pull or Move on your model, you’ll see your script start to get populated. This will help you to better understand the syntax used to capture your steps. Play around with adjusting values and replay your actions on other models or a blank screen. You’ll see the operations being performed very quickly. When I was a novice to scripting this helped me get started and made scripting less intimidating.
Lastly, if you already have some experience with scripting in SpaceClaim, you’ll appreciate that in Ansys SpaceClaim 18 we’ve populated prerecorded snippets of scripts that you can use to call common actions. These could be as simple as creating primitive shapes, saving/opening files or using some popular commands like Fill.
Inserting snippets, or reusing previous scripts, saves time when
you need to provide code for common tasks such as saving
or opening documents, to name a few.
A great example of when you might want to use scripting is to record procedures that could be difficult for a direct modeler like SpaceClaim to create. Typically, these might be actions like blending or shelling that should be done after a geometry is created or modified.
To make a sample script, download here. Simply followed the steps outlined above. First I recorded myself making the basic shape of the fitting I was trying to define. In this case I needed to make a fitting between an ellipse and a circle.
Without the use of scripting, the edits to geometry created via sweeps or blends can be complicated.
Recording modeling operations creates all lines of code needed for
editing or replaying a script.
I then defined script parameters for use in my script that would also be accessible in the “groups” panel of the SpaceClaim interface. The great thing about placing parameters in the groups panel is that they can be used in Ansys DesignXplorer to drive an optimization. In this case we may be concerned with the flow through the fitting.
The same parameters used in the script environment can be used in
SpaceClaim and DesignXplorer.
Changing a parameter in SpaceClaim will instantly update or rebuild
the entire model.
To recap the three main points above and help you make the most of scripting in SpaceClaim, I encourage you to learn about the open source programming language called IronPython, record your actions in SpaceClaim and take advantage of prerecorded snippets. These three things will get you off to a quick start in making some exciting scripts. So whether you’re creating parameters for optimization, automating repetitive tasks or creating quick geometry templates, check out the wide range of capabilities now open to you through scripting in SpaceClaim.
To learn more about geometry scripting check out Ansys SpaceClaim or view our recorded webinar, Handling Rapid Model Changes with Ansys SpaceClaim Scripting.