Parameterize Bushing Joint.

This example shows how to parameterize Bushing Joint Stiffness and Damping coefficients. Insert a Python Code object under Model in the Tree. Specify Target Callback = After Mesh Generated.

Transparent

Then, delete all the default code added in Script and copy/paste the following code:

def after_mesh_generated(this,mesh_object):# Do not edit this line
    
    jointValueKX = this.GetCustomPropertyByPath("Joint Selection/Stiffness per unit X").Value
    jointValueKY = this.GetCustomPropertyByPath("Joint Selection/Stiffness per unit Y").Value
    jointValueKZ = this.GetCustomPropertyByPath("Joint Selection/Stiffness per unit Z").Value

    jointValueDX = this.GetCustomPropertyByPath("Joint Selection/Damping per unit X").Value
    jointValueDY = this.GetCustomPropertyByPath("Joint Selection/Damping per unit Y").Value
    jointValueDZ = this.GetCustomPropertyByPath("Joint Selection/Damping per unit Z").Value
    
    my_joint = this.GetCustomPropertyByPath("Joint Selection/Joint Selection").ValueString
    my_joint_Tree = DataModel.GetObjectsByName(my_joint)[0]
    joint_tree = my_joint_Tree.BushingWorksheet
    
    joint_tree.SetBushingStiffnessPerUnitX(0,float(jointValueKX))
    joint_tree.SetBushingStiffnessPerUnitY(1,float(jointValueKY))
    joint_tree.SetBushingStiffnessPerUnitZ(2,float(jointValueKZ))

    joint_tree.SetBushingDampingPerUnitX(0,float(jointValueDX))
    joint_tree.SetBushingDampingPerUnitY(1,float(jointValueDY))
    joint_tree.SetBushingDampingPerUnitZ(2,float(jointValueDZ))

Transparent

Now, paste the following code under Property Provider:

#PROPERTY PROVIDER
def reload_props():
    this.PropertyProvider = None
    provider = Provider()
    
    group = provider.AddGroup("Joint Selection")
    double_prop = group.AddProperty("Stiffness per unit X", Control.Double)
    double_prop.CanParameterize = True
    double_prop.ValidRange = (0., 4.0e9)
    
    double_prop2 = group.AddProperty("Stiffness per unit Y", Control.Double)
    double_prop2.CanParameterize = True
    double_prop2.ValidRange = (0., 4.0e9)
    
    double_prop3 = group.AddProperty("Stiffness per unit Z", Control.Double)
    double_prop3.CanParameterize = True
    double_prop3.ValidRange = (0., 4.0e9)
    
    double_prop4 = group.AddProperty("Damping per unit X", Control.Double)
    double_prop4.CanParameterize = True
    double_prop4.ValidRange = (0., 4.0e9)
    
    double_prop5 = group.AddProperty("Damping per unit Y", Control.Double)
    double_prop5.CanParameterize = True
    double_prop5.ValidRange = (0., 4.0e9)
    
    double_prop6 = group.AddProperty("Damping per unit Z", Control.Double)
    double_prop6.CanParameterize = True
    double_prop6.ValidRange = (0., 4.0e9)
    
    
    this.PropertyProvider = provider
    options_prop = group.AddProperty("Joint Selection", Control.Options)
    my_joints_dict = {}
    joints = DataModel.GetObjectsByType(DataModelObjectCategory.Joint)
    for index,joint in enumerate(joints): my_joints_dict.Add(index+1,joint.Name)
    options_prop.Options = my_joints_dict
    
    this.PropertyProvider = provider



# region Property Provider Template
from Ansys.ACT.Mechanical.AdditionalProperties import PropertyProviderAdapter
from Ansys.ACT.Mechanical.AdditionalProperties import *
from mech_templates import property_templates
property_templates.set_ext_api(ExtAPI)
class Provider(Ansys.ACT.Interfaces.Mechanical.IPropertyProvider):
    # region These are callbacks that as a user you may want to modify to get specific behavior
    def IsValid(self, prop):
        """
        Called when checking the validity of a property, with the property instance.
        """
        # for double property use the ValidRange property to check validity
        if(isinstance(prop, DoubleProperty)):
            return prop.ValidRange[0] <= prop.Value and prop.ValidRange[1] >= prop.Value
        return True
    def IsReadOnly(self, prop):
        """
        Called when checking if a property should be readonly, with the property instance.
        """
        return False
    def IsVisible(self, prop):
        """
        Called when checking if a property should be visible, with the property instance.
        """
        return True
    def SetValue(self, prop, val):
        """
        Allows you to override the setter of the Value property on the property instance. 
        Keyword Arguments:
            prop -- property of which the value is being set
            val -- the value that was set
        Returns:
            The value that the Value property should be set to
        """
        return val
    def GetValue(self, prop, val):
        """
        Allows you to override the getter of the Value property on the property instance. 
        Keyword Arguments:
            prop -- property of which the value is being set
            val -- current value of the Value property
        Returns:
            The value that the getter on the internal value should return
        """
        return val
    # endregion   
    # structures that hold property instances
    prop_list = []
    prop_map = {}
    prop_groups = set()
    class __AnsGroup():
        """
        Helper group class to group properties, and provides methods to add properties to groups.
        """
        provider = None
        def __init__(self,name=None, provider=None):
            self.name = name
            self.provider = provider
        def __AddScopingProperty(self, name):
            """
            Adds a scoping property with a given name to this group.
            Keyword Arguments : 
                name -- unique name for the scoping property
            """
            scoping_prop = property_templates.ScopingProperty(name, self.name)
            for prop in scoping_prop.GetGroupedProps():
                self.provider.AddProperty(prop)
            return scoping_prop.GetGroupedProps()
        def AddProperty(self, name=None, prop_control=None, module_name=None):
            """
            Creates an instance of the property and connects delgates in 
            the associated Property Propvider.

            Keyword Arguments : 
                name -- unique name for the scoping property
                prop_control -- one of the built in controls, or extended controls
                module_name -- module where the control is defined
            """
            #special case for scoping property
            if(prop_control == "Scoping" and module_name == "property_templates"):
                return self.__AddScopingProperty(name)
            #if no module_name is passed, use the globals in current module
            #that has the built in controls imported
            prop_mod_globals = None
            if(module_name != None):
                if(module_name not in globals()):
                    raise Exception("Unknown module : " + module_name)   
                prop_mod_globals = globals()[module_name].get_globals()
            else:
                prop_mod_globals = globals()
            #class name is built based on control + "Property"
            #    Double - > DoubleProperty
            prop_class_name = str(prop_control) + "Property"
            if(prop_class_name not in prop_mod_globals):
                raise Exception("Unknown property class : " + prop_class_name)
            #instantiate the property based on module and class name
            prop = prop_mod_globals[prop_class_name](self.name + "/" + name, self.name)
            if(prop == None):
                raise Exception("Issue while creating the property instance.")
            #set the delegates to property provider functions
            prop.IsValidCallback = self.provider.IsValid
            prop.IsReadOnlyCallback = self.provider.IsReadOnly
            prop.IsVisibleCallback = self.provider.IsVisible
            prop.GetValueCallback = self.provider.GetValue
            prop.SetValueCallback = self.provider.SetValue
            #as a default make the property name the property display name
            prop.DisplayName = name
            #add property to the provider
            self.provider.AddProperty(prop)
            return prop
    def __init__(self):
        pass
    def GetProperties(self):
        """
        Returns a list of properties in the order that they were added to the property provider. 
        """
        return [self.prop_map[propName] for propName in self.prop_list]
    def AddGroup(self, name=None):
        """
        Creates an instance of helper group class and returns it.
        """
        if name in self.prop_groups:
            raise Exception("Group with name " + name + " already exists, please use a unique group name.")
        #keep groups names so we can make sure no duplicate groups are added
        self.prop_groups.add(name)
        return self.__AnsGroup(name, self)
    def AddProperty(self, prop):
        """
        Method used by the helper group class to add the property to the data-structure holding
        the property instances.
        """
        if(prop.Name in self.prop_map):
            raise Exception("Property name must be unique, property with name '" + prop.Name + "' already exisits.")
        self.prop_list.append(prop.Name)
        self.prop_map[prop.Name] = prop
reload_props()

Transparent

Now, Reload Properties:

Transparent

Define the properties, select bushing from the Joint Selection dropdown. Right mouse click on the Python Code object and click Connect.

Transparent

Generate Mesh and check that the stiffness/damping coefficients changed!

Transparent Transparent