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

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 450
100 Answers 250 Likes 100 Comments First Anniversary
✭✭✭✭
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: 450
    100 Answers 250 Likes 100 Comments First Anniversary
    ✭✭✭✭
    Answer ✓
    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: 236
    50 Answers 100 Comments 100 Likes First Anniversary
    ✭✭✭✭
    Answer ✓

    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)