Property Controllers in ANSYS ACT

Categories:

Customizations developed using ANSYS ACT adhere closely to the user experience that is native to Mechanical and other Workbench apps.  Obviously, this is to be expected, but sometimes it can be a little challenging to fit a particular workflow into the “tree object” plus “object properties” model.   One way to broaden the available set of user experiences from which to construct a customized behavior is to use what are known as property controllers.

Property controllers are classes, which can be implemented either in C# or Python that are associated with a given property in the details pane of a given ACT object.  These classes allow the programmer to specialize the functionality and behavior of the particular property to which they are associated.  The association between a given property and its property controller is made in the ACT XML definition file.  For this article, like most of the ones I write on ACT, I will be using C# as the implementation language.

The degree to which any given property can be specialized by a property controller is quite vast.  Therefore, I won’t be able to touch on all of the possible combinations.  However, I will demonstrate two that I have found particularly useful in various ACT apps I’ve written.

The first is a custom “select” controller that allows the user to pick one of a set of given Mechanical objects.  For most customizations, perhaps the canonical example, is a select controller that allows a user to pick a particular coordinate system out of all of the defined coordinate systems in the model.  Yes, there is a template for this that ships with Mechanical, but I will show a given implementation.  Understanding how the controller works will enable you to apply the same technique to other object types, even other ACT objects within the same app.

The second is a way to “fly out” a dialog box that can contain additional custom controls, and that is “anchored” to the side of the given property box within the details pane.  This is useful for scenarios when we can’t easily fit a particular data entry within a given property field.  Tabular data is a prime example.  Again, there are some templates for this in Mechanical, but understanding how to build it up from scratch will allow you to apply the same principles to more complex dialogs.  This second example will be covered in a subsequent blog post.

Foundations

Before we dive into the individual examples above, let’s understand some of the basics of property controllers in general.  First, how do we associate a given property controller class with a particular property.  This is accomplished by using the “class” attribute in the property tag within the XML definition.  So, here is an example from an extension XML file:

<property name="EngineAxis" 
  caption="Coordinate System" 
  control="select"                         
  class="PADT.PropertyControllers.CoordinateSystemSelectController">
  <attributes type_filter="cylindrical"/>  
</property> 

You can see that we’ve added a “class” attribute inside the property tag and set it equal to a fully qualified class name.  All other property attributes are the same as with a typical property.  In order for this to work, however, we will need to implement a class called “CoordinateSystemSelectController” in the PADT.PropertyControllers namespace.

You will also notice that there is a nested <attributes> tag inside the <property> tag.  This can be used to pass additional configuration data to the controller as we will see.  Clearly, in this case, the additional data is designed to constrain the types of coordinate systems that will be populated within the control.

Example 1: Coordinate System Select Property Controller

The method by which behavior is customized for a given property is by implementing overrides for a series of virtual functions defined on the property itself.  These virtual functions allow us to hook into various points within the properties lifetime and operation.  The names for these virtual functions correspond to the callbacks listed in the ANSYS help for the <property> tag in the ACT XML reference manual.  The names are always lowercase.  Common ones that I use are functions such as “onactivate”, “onshow”, “isvalid”,”value2string” and “getvalue”.  Except for the “value2string” function, most of these are probably self-explanatory as to when they would fire.   For this controller, I’ll demonstrate a few of these functions including when and how to use the “value2string”.

Let’s begin with the “onactivate” function.  This function is called when the user “selects” or activates the property.  So, within this function is a good place to populate the list of currently available coordinate systems.  It is tempting to cache this list so that it doesn’t have to be recomputed.  However, if the user deletes, or adds a coordinate system after we have cached the list, we would not display it as an option the next time they activated this control.  Therefore, on each activation, we build up a list of available coordinate systems.  Here is the code:

You can see the parameters to this function are parameter representing the “tree object” to which this property is a member of that object’s details pane, and a parameter representing this “property”.  The second parameter might seem counterintuitive.  You might think that we are subclassing the property itself and thus this parameter would be redundant. (i.e, it would be equivalent to the “this” object).  However, we are not subclassing the property per say, but rather implementing a controller object that property itself makes calls against to modify its own behavior.  Sounds convoluted, I understand, but my guess is that this is what allows us to specify all of this within the extension XML file.  So, it’s a good thing.

Once we get into the function proper, on line 55 we clear out all of the items within this properties associated drop down control.  Then, in lines 56-58 we figure out what are the enum constants that represent the types of coordinate systems (cylindrical, Cartesian, etc…) that we would like to present to the user.  Note, our attribute “type_filter” could contain multiple types. Then, in lines 59-67, we iterate over all of the coordinate systems current defined in the Mechanical session and pick out the ones that are of the right type.  We then add them to the “options” property of this SimProperty object.  Note, however, that we don’t add the coordinate system objects themselves, but rather string representations of the object Ids.  This is important.  The reason we don’t add the name of the coordinate system is because names (or labels) in Mechanical are not required to be unique.  You can create five coordinate systems and name all of them “Bob”, Mechanical doesn’t care and will treat them as unique.  So, we need a unique attribute of the coordinate system to store in our list of options.  The object Id is guaranteed to be unique.  So, we store this instead.

The final bit of code in this function just makes sure to default select one coordinate system if the user hasn’t already selected one.  That functionality is on lines 69-83.  If the Value property is null, then the user (or this code) has not populated the select with a given coordinate system. So, if there are any coordinate systems that are appropriate we just find the first one and select it automatically.  Note, if the user later changes this to a different CSYS and this function fires a second time, it will not overwrite their choice because the null check will fail on line 69.  The reason for this behavior is because the extension for which this code was written made extensive use of a single cylindrical coordinate system in a number of different objects.  Typically the user would add just this one coordinate system in addition to the default global Cartesian system.  So, by adding this code, the user would not be required to select this coordinate system each time they added a new object, but rather, the tool would do it for them.

The next bit of code to examine is the “value2string” function, which is shown below:

You may recall from above that the data we store in the options property was a list of string representations of the various coordinate system Ids.  Now, if we didn’t implement this function, when the user interacted with the drop down control what they would see would be a list of numbers.  They might see a list like “42” “87” and “94”.  Clearly, it’s not very intuitive as to which coordinate system these numbers may refer. 

So, what the “value2string” function allows us to do is to transform the data that the property actually stores into a visual representation that is meaningful to the user.  However, this is purely a stateless transformation.  The actual data store in the property always remains the string representation of the object’s id.  So, you can think of this function as sitting between the internal code that pulls a value out of the property, and the internal code that renders that value to the screen.  In between these two calls, we have the opportunity to transform what gets rendered.

So, essentially what we do inside this function is parse the Id string back into an integer.  If that’s cool, we then lookup the particular mechanical tree object that has this given Id.  Finally, if everything is kosher with this object, we return the name of the object we looked up.  If at any point something goes wrong, we just return an empty string.

Now, when the user interacts with the property controller, the will see a list of names corresponding to the coordinate systems of the appropriate type.  If they sadistically named all of these coordinate systems the same name, then they will see a list with multiple entries of the same name.  However, each one in the list is a unique coordinate system.  How they figure out which one is the one they actually want is now their problem…

Finally, the last function we will look at is the “getvalue” function.  As the “value2string” function made the experience of the end user more palatable, so too the “getvalue” function makes the experience of the developer more palatable.  Essentially what it does is analogous to the “value2string” function, but rather than returning a string, it returns an actual coordinate system object that can be used in other places in the system.  It looks like the following:

As you can see, it is very similar to the “value2string” object, but instead of returning a string, it returns the actual tree object itself.  Note, you have to cast the return value at the caller site to the appropriate type, but meh… it’s still nice to have.

Finally, to see this property controller in action, I’ve taken a quick screen grab of the properties pane of an ACT object I’ve implemented.  This is a little symmetry object that implements a homebrewed CPCYC, but you can see the coordinate system object.

That’s all for this post.  Next time we’ll look at how to implement the flyout feature.  Good luck with your ACT programming needs.  Oh, and if you need some help, or ever want to have some ANSYS customization done for you, let us know.  We do all sorts of customization work from more run of the mill type

Categories

Certified Elite Channel Partner

Get Your Ansys Products & Support from the Engineers who Contribute to this Blog.

Product Development
Platinum Partner

Technical Expertise to Enable your Addictive Manufacturing Success.

PADT’s Pulse Newsletter

Keep up to date on what is going on at PADT by subscribing to our newsletter.


By submitting this form, you are consenting to receive marketing emails from: Phoenix Analysis and Design Technologies, 7755 S. Research Dr., Tempe, AZ, 85284, https://www.padtinc.com. You can revoke your consent to receive emails at any time by using the SafeUnsubscribe® link, found at the bottom of every email. Emails are serviced by Constant Contact

Share this post:

Upcoming Events

11/30/2022

SPEOS Updates in Ansys 2022 R2 - Webinar

11/23/2022

Simulation Best Practices for Electronics Reliability - Webinar

11/16/2022

Discovery Updates in Ansys 2022 R2

11/10/2022

VentureCafe Phoenix Panel: Venture Capital in AZ

11/08/2022

2022 GOVERNOR’S CELEBRATION OF INNOVATION AWARDS + TECH SHOWCASE

11/03/2022

VentureCafe Phoenix Panel: Angel Investment in AZ

11/02/2022

High & Low Frequency Electromagnetics Updates in Ansys 2022 R2

10/26/2022

Simulation Best Practices For Chip-Package-System Design & Development

10/20/2022

Nerdtoberfest 2022

10/19/2022

2022 Southern Arizona Tech + Business Expo

10/19/2022

LS-DYNA Updates in Ansys 2022 R2 - Webinar

10/17/2022

Experience Stratasys Truck Tour - Clearfield Utah

10/14/2022

ASU School of Manufacturing Systems and Networks - Formal Opening Cele

10/14/2022

Experience Stratasys Truck Tour - Midvale Utah

10/12/2022

Experience Stratasys Truck Tour - Littleton Colorado

10/06/2022

Fluids Updates in Ansys 2022 R2 - Webinar

10/05/2022

Experience Stratasys Truck Tour - Colorado Springs

09/29/2022

White Hat Life Science Investor Conference - 2022

09/28/2022

2022 AZBio Awards

09/28/2022

Simulation Best Practices for Rotating Machinery Design & Development

09/21/2022

ExperienceIT NM 2022

09/21/2022

Additive Updates in Ansys 2022 R2 - Webinar

09/14/2022

Rocky Mountain Life Sciences Investor & Partnering Conference

09/08/2022

Ansys Optics Simulation User Group Meeting - Virtual

09/08/2022

Ansys Optics Simulation User Group Meeting

09/07/2022

SI & PI Updates in Ansys 2022 R2 - Webinar

08/31/2022

Simulation Best Practices for Developing Medical Devices - Webinar

08/24/2022

Mechanical Updates in Ansys 2022 R2 - Webinar

08/10/2022

Tucson after5 Tech Mixer: Ruda-Cardinal

08/05/2022

Flagstaff Tech Tour, 2022

08/02/2022

2022 CEO Leadership Retreat

08/01/2022

2022 CEO Leadership Retreat

07/27/2022

Thermal Integrity Updates in Ansys 2022 R1 - Webinar

07/20/2022

Simulation Best Practices for the Pharmaceutical Industry - Webinar

07/14/2022

NCMS Technology Showcase: Corpus Christi Army Depot

07/13/2022

NCMS Technology Showcase: Corpus Christi Army Depot

07/13/2022

Additive & Structural Optimization Updates in Ansys 2022 R1 - Webinar

07/07/2022

Arizona AADM Conference, 2022

06/29/2022

LS-DYNA Updates & Advancements in Ansys 2022 R1 - Webinar

06/23/2022

Simulation Best Practices for Wind Turbine Design - Webinar

06/15/2022

MAPDL Updates & Advancements in Ansys 2022 R1 - Webinar

06/01/2022

Mechanical Updates in Ansys 2022 R1 - pt. 2 Webinar

05/26/2022

Modelling liquid cryogenic rocket engines in Flownex - Webinar

05/25/2022

SMR & Advanced Reactor 2022

05/25/2022

05/24/2022

SMR & Advanced Reactor 2022

05/19/2022

RAPID + tct 2022

05/19/2022

Venture Cafe Roundtable: AI & Healthcare

05/18/2022

Tucson after5 Tech Mixer: World View

05/18/2022

RAPID + tct 2022

More Info

05/18/2022

Signal & Power Integrity Updates in Ansys 2022 R1 - Webinar

05/18/2022

Simulation World 2022

05/17/2022

RAPID + tct 2022

05/11/2022

Experience Stratasys Manufacturing Virtual Event

05/04/2022

Mechanical Meshing Updates in Ansys 2022 R1 - Webinar

04/27/2022

04/22/2022

12TH ANNUAL TUCSON GOLF TOURNAMENT

04/21/2022

04/20/2022

Additional Fluids Updates in Ansys 2022 R1

04/20/2022

Experience Stratasys Tour – Tempe Arizona

04/18/2022

Experience Stratasys Tour - Flagstaff Arizona

04/14/2022

D&M West | MD&M West

04/13/2022

D&M West | MD&M West

04/13/2022

Experience Stratasys Tour - Albuquerque New Mexico

04/12/2022

D&M West | MD&M West

04/12/2022

Experience Stratasys Tour - Los Alamos New Mexico

04/12/2022

Optimizing Engineering Workflows f​​​​or Propulsion System Design

04/07/2022

Experience Stratasys Tour - Austin Texas

04/07/2022

37th Space Symposium - Arizona Space Industry

04/06/2022

Transforming Digital Engineering with Ansys Discovery 2022 R1

04/06/2022

37th Space Symposium - Arizona Space Industry

04/05/2022

37th Space Symposium - Arizona Space Industry

04/04/2022

37th Space Symposium - Arizona Space Industry

03/30/2022

Simulation Best Practices for Vehicle Engineering - Webinar

03/23/2022

03/23/2022

High & Low Frequency Electromagnetics Updates in Ansys 2022 R1

02/24/2022

Arizona Technology Council After 5 Tech Mixer "Pandemic Pivot Pizza Pa

02/23/2022

SciTech Festival: Spend an Hour with 3D Printing Experts

02/11/2022

Webinar: Mechanical overview for Ansys 2022 R1

More Info

02/09/2022

Webinar: Product Development 101 (FAKE)

02/08/2022

Webinar: Navigating the Additive Landscape

01/27/2022

Arizona Technology Council 1st Quarter VIP Tech Mixer

More Info

01/26/2022

Simulation Best Practices for Gas Turbine Design & Development - Webin

More Info

01/19/2022

Arizona Photonics Days

More Info

11/04/2021

ExperienceIT, New Mexico

More Info

11/03/2021

Additive Manufacturing & Structural Optimization in Ansys 2021 R2 - We

More Info

11/03/2021

Optics Valley Technical Series: The Future of Simulation in the Optics

More Info

11/02/2021

SBIR Liftoff AZTC Virtual Breakfast Series

More Info

10/10/2021

Stratasys Mobile Truck Stop - Tucson Arizona

More Info

Search in PADT site

Contact Us

Most of our customers receive their support over the phone or via email. Customers who are close by can also set up a face-to-face appointment with one of our engineers.

For most locations, simply contact us: