Extract information on boundary conditions in Mechanical

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 864
500 Comments Photogenic Name Dropper Solution Developer Community of Practice Member
✭✭✭✭

Is there a script to get boundary conditions defined in Mechanical, know the values of the applied forces and the unit system that is used to define these conditions ?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 864
    500 Comments Photogenic Name Dropper Solution Developer Community of Practice Member
    ✭✭✭✭
    edited September 2023

    Here is an example.
    The dummy model used is:

    This scripts prints out the requested information:

     # Get analysis
    analysis = ExtAPI.DataModel.Project.Model.Analyses[1]
    # Grab different types of boundary conditions
    forces = analysis.GetChildren(DataModelObjectCategory.Force, True)
    pressures= analysis.GetChildren(DataModelObjectCategory.Pressure, True)
    # Extract and print info on forces
    for f in forces:
        print("Force named: " + f.Name + " is defined by: " + str(f.DefineBy))
        if f.DefineBy == LoadDefineBy.Components:
            print('Force values are: ' + 'X: ' + str(f.XComponent) + ' Y: '+ str(f.YComponent) + ' Y=Z: '+ str(f.ZComponent))
        if f.DefineBy == LoadDefineBy.Vector:
            print('Force magnitude is: ' + str(f.Magnitude))
    
    # Extract and print info on pressures
    for p in pressures:
        print("Pressure named: " + p.Name)
        if p.DefineBy == LoadDefineBy.NormalToOrTangential:
            print('Pressure magnitude is: ' + str(p.Magnitude))
    

    There are also some methods that can be used to separate the value itself from the unit system.
    For example:

    for p in pressures:
        print("Pressure named: " + p.Name)
        if p.DefineBy == LoadDefineBy.NormalToOrTangential:
            p_as_tabular_data = p.Magnitude.Output.DiscreteValues
            for quantity in p_as_tabular_data:
                print(quantity.Value)
                print(quantity.Unit)