How to create input and output Parameters in WB Parameter Set?

Options
Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 416
First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
edited June 2023 in Structures

How to create input and output Parameters in WB Parameter Set?

Tagged:

Answers

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 416
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    Answer ✓
    Options
    my_parameter_1 = Parameters.CreateParameter(
        IsOutput=False,
        DisplayText="my_parameter")
    designPoint = Parameters.GetDesignPoint(Name="0")
    designPoint.SetParameterExpression(
        Parameter=my_parameter_1 ,
        Expression="P1 * 4")
    my_parameter_2 = Parameters.CreateParameter(
        IsOutput=True,
        Expression="P2 / 3",
        DisplayText="my_expression")
    
  • M
    M Member, Employee Posts: 230
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓
    Options

    You can also use values in Mechanical (inputs or outputs) and write them to the WB parameters.

    You have to do a bit of substitution to get the values into the command. I used the replace function of python.

    Example in Mechanical using an UDF scoped to a named areas, with the area calculated from the named selection.

    import wbjn
    
    myUDF = Model.Analyses[0].Solution.Children[3]
    myUDF_Loc = myUDF .Location
    myUDF_Loc_Area = myUDF_Loc.PropertyByName('AreaOfFaces').StringValue
    area_str = myUDF_Loc_Area.split()[0]
    
    cmd = """returnValue(Parameters.CreateParameter(IsOutput=True,Expression="placeholder",DisplayText="Area"))""".replace('placeholder',area_str)
    cmd = cmd.replace('Area','Area ' + myUDF_Loc.Name)
    newP=wbjn.ExecuteCommand(ExtAPI,cmd)