How to access the scaling for different steps of x dependent pressure values

maxmohr
maxmohr Member Posts: 2
First Comment
**

Hello,

I have written the following script to assign x dependent pressure values to some faces.

pf = analysis.AddPressure()

        Ansys.ACT.Automation.Mechanical.LoadHelper.SwitchToTabular(pf)

        pf.IndependentVariable = LoadVariableVariationType.XValue

        pf.XYZFunctionCoordinateSystem = ExtAPI.DataModel.GetObjectsByName("COS_CC(Mechanical Model)")[0]

        pf.Magnitude.Inputs[0].DiscreteValues = [Quantity(xi) for xi in x]

        pf.Magnitude.Output.DiscreteValues = [Quantity(pii) for pii in val]

I'd like to scale these inputs for different time steps. How do I do that with scripting?

I'd like to edit the following table

Answers

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 125
    100 Comments Second Anniversary 5 Answers Solution Developer Community of Practice Member
    ✭✭✭✭

    Partial answer:

    pf.GraphControlsXAxis = LoadVariableVariationType.Time

    I am not sure what scale factor actually does. It is only for visualization?

  • maxmohr
    maxmohr Member Posts: 2
    First Comment
    **

    The scale factor scales the input for the different steps. If the scale factor is 1, the pressure is exactly what what specified in the XDependent data. If the scale factor is 2, the pressure is doubled.

    I was also able to change the GraphControlXAxis. Though how do I change the scale factors for the different steps?

  • Tasos
    Tasos Member, Employee Posts: 11
    Name Dropper 5 Likes First Comment Photogenic
    ✭✭✭

    Maybe someone at the @AKD-Scripting-Team knows about this.
    I was informed that a similar question has been asked in the Scripting TIG, perhaps we should also post the answer here when there is one.

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 125
    100 Comments Second Anniversary 5 Answers Solution Developer Community of Practice Member
    ✭✭✭✭
    edited December 2024

    @maxmohr I do not think there is any exposed API to change that scale factor.

    I have created a solution which would work only in the GUI mode. Please note that this is using internal/upsupported APIs which may change in future. Hope it helps.

    # Pressure.Activate(), The solution works only when mechanical is opened.
    Pane=ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.TabularData)
    Con = Pane.ControlUnknown
    
    # Storing info to use later
    info_dict = {}
    headers = []
    for C in range(1,Con.ColumnsCount+1):
        add_header = True
        header = ""
        for R in range(1,Con.RowsCount+1):
            Text = Con.cell(R,C).Text
            if Text!=None:
                if header:
                    info_dict[header].append(Text)
                if add_header:
                    header = Text
                    headers.append(header)
                    info_dict[header] = []
            add_header = False
    print(info_dict)
    
    # Change scale for Step 1 and Time 1
    target_steps = '1'
    target_time = '1.'
    target_scale = '4.'
    print(headers.index('Scale') + 2)
    # Find the index where both conditions are met
    for i, (step, time) in enumerate(zip(info_dict['Steps'], info_dict['Time [s]'])):
        if step == target_steps and time == target_time:
            scale_factor = info_dict['Scale'][i]
            MyCell = Con.cell(i + 2, headers.index('Scale') + 2)
            Con.TriggerBeforeEdit(MyCell)
            MyCell.Text = target_scale
            Con.TriggerAfterEdit(MyCell)
            #print(i + 2, headers.index('Scale') + 2)
            break
    else:
        print("No matching entry found.")