ANSYS ACT Console Snippets

So this is just a quick post to point out a handy feature in ANSYS Workbench, the ACT Console. There are times when you want some functionality in Mechanical that just is not yet there. In this example, a customer wanted the ability to get a text list of all the Named Selections in his model.  A quick Python script does just that.

import string,re

a=ExtAPI.DataModel.AnalysisList[0]  #Get the first Analysis if multiple are present 
workingdir=a.WorkingDir 
path=workingdir.split("\\\\") 

#Put the output file in the "user_files" directory for the project. 
userdir=string.join(path[:len(path)-4],"\\\\")+"\\\\user_files"  

#Use the name of the system in case the snippet is 
#used on multiple independent systems in the project. 
system_name=re.sub(" ","_",a.Name)  
model = ExtAPI.DataModel.Project.Model 
nsels = model.NamedSelections                  #Get the list of Named Selections 

if nsels:    #Do this if there are any Named Selections
     f=open("%s\\\\%s_named_selections_checked.txt"%(userdir,system_name), "w") 
     for child in nsels.Children:
        f.write("%s\n"%child.Name)
     f.close()

So to use a piece of Python code, like this, we use the ACT Console in Mechanical. To access the ACT Console in Mechanical 17.0, or later, just hit this icon in the toolbar.

The Console allows you to type, or paste, text directly into the black command line at the bottom.  But if we are going to reuse this code, then the use of Snippets is the way to go. In R17.0 they were called ‘Bookmarks’, but they worked the same way.

When you add a Snippet, a new window allows you to name the snippet and type in, or paste in, your code.

When you hit Apply, your named snippet is added to the list

From then on, to use the snippet you just click on it, and hit ‘Enter’. The text is basically, repasted into the command window, so you can set any variables needed prior to hitting your snippet.

The snippets are persistent and remain in the console, so they are available for all new projects. Using snippets is a great way to reduce time for repetitive tasks, without having to create a full blown ACT extension.

Happy coding!

Webinars: Overview of Add-On Products that Work with ANSYS Mechanical

PADT-Webinar-LogoWith the introduction of the new ANSYS Mechanical Enterprise, many add-on products that had to be purchased separate, are now included. In these webinars PADT’s engineers will provide an overview of the key applications that users now have easy access to.

Each product will be reviewed by one of PADT’s engineers. The will share the functionality of each tool, discuss some lessons we have learned in using and supporting each tool, and provide a short demonstration. Each session will have time for Questions and Answers.

ANSYS-Footer-RBD-STR-ACT

Sign up for the one you want, or all three. Everyone that registers will receive a link to the recording and to a copy of the slides. So register even if you can not make the specific dates.

Here are the times and links to register:

Overview of ANSYS Rigid Body Dynamics (RBD) and ANSYS Explicit STR
May 19, 2016 (Thu)
11:00 am MST & PDT / 12:00 pm MDT

      REGISTER

Overview of ANSYS SpaceClaim and ANSYS AIM
May 24, 2016 (Tue)
11:00 am MST & PDT / 12:00 pm MDT

    REGISTER

Overview of ANSYS Customization Toolkit (ACT) and ANSYS DesignXplorer (DX)
May 26, 2016 (Thu)
11:00 am MST & PDT / 12:00 pm MDT

     REGISTER

We hope to see you online.  If you have any questions, contact us at support@padtinc.com or call 480.813.4884.

ANSYS_Mechanical_Header