How do I parametrize a layered section?

Aria
Aria Member, Employee Posts: 64
First Anniversary Ansys Employee First Answer Name Dropper
edited June 2023 in Structures

I want to parametrize the angle and thickness of the plies in the Mechanical object "Layered Section".

How can I do that?


Answers

  • Aria
    Aria Member, Employee Posts: 64
    First Anniversary Ansys Employee First Answer Name Dropper
    edited March 2023

    This is achieved using a Python Code object.

    First we create property groups for the layer we want to scope, then a property group for the parameters.

    We want to define the input parameters as parametrizable. We first locate the Layered Section object in question and walk through the layers. For each layer, we can create a parameter for the thickness and angle respectively.

    We create another property to retrieve the first Layered Section object in the Mechanical Tree, Tree, and store it as a dictionary where the key is the name (for the user to identify) and the object ID, which will later be used for the callback to edit the Layered Section Object.

    These are the reload_props() function used and any dependency function.

    Note that the Provider class has been omitted in the code snippet below.

    def reload_props():
        this.PropertyProvider = None
        provider = Provider()
        
        
        group_1 = provider.AddGroup("Layered Selection Object")
        options_prop = group_1.AddProperty("Select Layered Section Object", Control.Options)
    
        group_2 = provider.AddGroup("Parameters")
        unit_length = DataModel.CurrentUnitFromQuantityName("Length")
        unit_angle = DataModel.CurrentUnitFromQuantityName("Angle")
        layered_sections = DataModel.GetObjectsByType(DataModelObjectCategory.LayeredSection)
        unsup_ls = [x for x in layered_sections if x.Suppressed == False]
        if unsup_ls:
            my_ls = unsup_ls[0]
            options_name = my_ls.Name + " [" + my_ls.ObjectId.ToString() + "]"
            options_prop.Options = {1 : options_name}
            options_prop.Value = 1
            rows = my_ls.Layers.RowCount
            for layer_no in range(rows):
                header_thk = "Layer " + str(layer_no+1) + " thk " + "(" + unit_length + ")"
                header_angle = "Layer " + str(layer_no+1) + " angle " + "(" + unit_angle + ")"
              
                param_thk = group_2.AddProperty(header_thk,Control.Double)
                param_thk.CanParameterize = True
    
                param_angle = group_2.AddProperty(header_angle,Control.Double)
                param_angle.CanParameterize = True
        
        this.PropertyProvider = provider
    

    Then, we we set the Target Callback to trigger "After Object Changed" in which the callback will be triggered when DX feeds the parameter to the Python code object during the design parametrization process.

    The function will retrieve the Layered Section object the user picked in the drop down menu and retrieve the object ID, then walk through the layers to edit them, one by one.












    def after_object_changed(this, object_changed, property_name):# Do not edit this line
        import re
        import time
    
        unit_length = DataModel.CurrentUnitFromQuantityName("Length")
        unit_angle = DataModel.CurrentUnitFromQuantityName("Angle")
        layer_obj_prop = this.GetCustomPropertyByPath("Layered Selection Object/Select Layered Section Object")
        if layer_obj_prop:
            if layer_obj_prop.ValueString is not None:
                s = layer_obj_prop.ValueString
                objId = re.search(r"\[([A-Za-z0-9_]+)\]", s).group(1)
                ls_obj = DataModel.GetObjectById(float(objId))
                if ls_obj:
                    rows = ls_obj.Layers.RowCount
                    for layer_no in range(rows):
                        header_thk = "Layer " + str(layer_no+1) + " thk " + "(" + unit_length + ")"
                        param_thk = this.GetCustomPropertyByPath("Parameters/" + header_thk).Value
                        if param_thk:
                            ls_obj.Layers.SetThickness(layer_no,param_thk)
            
                        header_angle = "Layer " + str(layer_no+1) + " angle " + "(" + unit_angle + ")"
                        param_angle = this.GetCustomPropertyByPath("Parameters/" + header_angle).Value
                        if param_angle:
                            ls_obj.Layers.SetAngle(layer_no,param_angle)
    

     Now, the worksheet in the Layered Section will be edited each time the values in the property group which contain the Parameters are modified. The python code object itself is located in the Model-tree.