Get maximum force value of a bar - Python

alexander.silvaGA9XG
Explorer

Get maximum force value of a bar - Python

alexander.silvaGA9XG
Explorer
Explorer

Hi there,
How can I get the maximum and minimum force of a bar? I can get the global maximum values but not for individual elements.

def populateBarTableFromRobot(self😞
try:
rob_app = win32com.client.Dispatch("Robot.Application")
BarCollection = rob_app.Project.Structure.Selections.Get(1)
CaseCollection = rob_app.Project.Structure.Selections.Get(2)
BarForces = rob_app.Project.Structure.Results.Bars.Forces

if BarCollection.Count > 0:
self.setRowCount(BarCollection.Count)

for i in range(1, BarCollection.Count + 1😞
element_number = BarCollection.Get(i)
bar = rob_app.Project.Structure.Bars.Get(element_number)
es = rob_app.CmpntFactory.Create(42)
es.ValueType = 169 # References for MY
es.Selection.Set(1, bar)
es.Selection.Set(2, CaseCollection.GetAll)
try:
# Get max and min MY values for the bar
my_max = rob_app.Project.Structure.Results.Extremes.MaxValue(es).Value
my_min = rob_app.Project.Structure.Results.Extremes.MinValue(es).Value
print(f'Element: {element_number}, MY Max: {my_max.Value}, MY Min: {my_min.Value}')
except Exception as e:
print(f"Error retrieving MY extremes for element {element_number}: {e}")
else:
print("No elements selected in the model.")

except Exception as e:
print(f"Error: {e}")
finally:
if 'rob_app' in locals():
del rob_app

Reply
150 Views
1 Reply
Reply (1)

Stephane.kapetanovic
Mentor
Mentor

hi @alexander.silvaGA9XG 

try "like" this :

    try:
        rob_app = win32com.client.Dispatch("Robot.Application")

        structure = rob_app.Project.Structure
        selections = structure.Selections
        bar_sel = selections.Get(1)  # IRobotObjectType.I_OT_BAR
        b_sel = selections.Create(1) # IRobotObjectType.I_OT_BAR
        cas_sel = selections.Get(2)  # IRobotObjectType.I_OT_CASE

        bar_selected = bar_sel.Count > 0
        cas_selected = cas_sel.Count > 0

        if bar_selected and cas_selected:
            extremes = structure.Results.Extremes
            extreme_params = rob_app.CmpntFactory.Create(42)  # IRobotComponentType.I_CT_EXTREME_PARAMS
            extreme_params.ValueType = 169  # IRobotExtremeValueType.I_EVT_FORCE_BAR_MY
            extreme_params.Selection.Set(2, cas_sel)  # IRobotObjectType.I_OT_CASE
            extreme_params.BarDivision = 10

            for i in range(1, bar_sel.Count + 1):
                b_nbr = bar_sel.Get(i)
                b_sel.Clear()
                b_sel.AddOne(b_nbr)
                extreme_params.Selection.Set(1, b_sel)  # IRobotObjectType.I_OT_BAR

                try:
                    my_max = extremes.MaxValue(extreme_params)
                    my_min = extremes.MinValue(extreme_params)
                    print(f"Element: {b_nbr}, MY Max: {my_max.Value}, MY Min: {my_min.Value}")
                except Exception as ex:
                    print(f"Error retrieving MY extremes for element {b_nbr}: {ex}")

        else:
            msg = ""
            if not bar_selected:
                msg += "No bars"
            if not cas_selected:
                msg += (" and no" if msg else "No") + " cases"
            print(msg + " selected in the model.")

    except Exception as ex:
        print(f"Error: {ex}")
    
    finally:
        if 'rob_app' in locals():
            del rob_app  

Best Regards

 

 

0 Likes