Specify and Parameterize Bolt Pretension Loads

Goal

The following script demonstrates how to automatically set and parametrize the Preload value of all the Bolt Pretension loads that are present in the analysis. Note that these loads need to have the same name to be updated by the script. See an example of the executed script below.

Code

def after_object_changed(this, object_changed, property_name):# Do not edit this line
    """
    Called after an object is changed.
    Keyword Arguments : 
        this -- the datamodel object instance of the python code object you are currently editing in the tree
        object_changed -- The object that was changed
        property_name -- The property that was changed
    """


    # To access properties created using the Property Provider, please use the following command.
    # this.GetCustomPropertyByPath("your_property_group_name/your_property_name")

    # To access scoping properties use the following to access geometry scoping and named selection respectively:
    # this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Geometry Selection")
    # this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Named Selection")

    if (object_changed.Name != this.Name):
        # The change is not on the Python code object, simply ignore
        return
    
    preload = this.GetCustomPropertyByPath("Parameters/Preload (N)").Value
    
    all_prets = DataModel.GetObjectsByName('Bolt Pretension')
    
    for prets in all_prets:
        times = range(1,prets.Parent.AnalysisSettings.NumberOfSteps+1)
        preload_vals=[]
        time_vals=[]
        for time in times:
            time_vals.append(Quantity(float(time), "sec"))
            preload_vals.append(Quantity(float(preload), "N"))
            
        prets.Preload.Inputs[0].DiscreteValues = time_vals
        prets.Preload.Output.DiscreteValues=preload_vals

Example

Here you can see the specified loading conditions.

Here is an example of the script with the corresponding Details of the Python object.

And here is a portion of the code that is included in the Property Provider pane for the example.

def reload_props():
    this.PropertyProvider = None
    """
    Sample code is provided below that shows how to:

        1. Create an instance of the Provider. The Provider class is used to add custom properties to the details.

        2. Use the Provider instance to add custom properties.

        3. Configure those custom properties.

    """

    # Create the property instance
    provider = Provider()

    # Create a group named Group 1.
    group = provider.AddGroup("Parameters")

    # Create a property with control type Expression and a property with control type Double, and add it to the Group 1
    double_prop = group.AddProperty("Preload (N)", Control.Double)

    # Configure the double property to be parameterizable. As a default the property will be an input parameter.
    # However, by updating the ParameterType property, it can be configured to be a output parameter as well.
    double_prop.CanParameterize = True
    double_prop.ParameterType = ParameterType.Input
    # Connects the provider instance back to the object by setting the PropertyProvider member on this, 'this' being the
    # current instance of the Python Code object.
    this.PropertyProvider = provider