Check Property Values

Goal

The following script demonstrates how to check a pressure quantity and the material of a body. The script outputs a message in the Mechanical Message pane.

Code

def before_solve(this, analysis):# Do not edit this line
    """
    Called before solving the parent analysis.
    Keyword Arguments : 
        this -- this python object
        analysis -- Static Structural
    """
    
    # This script shows how to check a pressure quantity and body material
    # Output of the script is a messages in Mechanical messages 
    
    # The script is working with 'before_solve' callback
    # The Python code object should be located under the analysis

    # Check if pressure value is 1 Mpa
    pres=ExtAPI.DataModel.GetObjectsByName('Pressure')[0] # Replace 'pressure' with the name of an existing load with magnitude
    if pres.Magnitude != Quantity(1.0,'MPa'):
        msg = Ansys.Mechanical.Application.Message('Pressure value is not correct - should be 1MPa', MessageSeverityType.Warning)
        ExtAPI.Application.Messages.Add(msg)	


    # Check body material
    body=ExtAPI.DataModel.GetObjectsByName(r'Component1\body')[0] # Replace 'Component1\body' with the name of an existing body
    msg = Ansys.Mechanical.Application.Message('Main body material is : '+body.Material, MessageSeverityType.Warning)
    ExtAPI.Application.Messages.Add(msg)