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

Member, Moderator, Employee Posts: 479
100 Answers 250 Likes 100 Comments Second Anniversary
✭✭✭✭
edited June 2023 in Structures

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

Tagged:

Answers

  • Member, Moderator, Employee Posts: 479
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    Answer ✓
    1. my_parameter_1 = Parameters.CreateParameter(
    2. IsOutput=False,
    3. DisplayText="my_parameter")
    4. designPoint = Parameters.GetDesignPoint(Name="0")
    5. designPoint.SetParameterExpression(
    6. Parameter=my_parameter_1 ,
    7. Expression="P1 * 4")
    8. my_parameter_2 = Parameters.CreateParameter(
    9. IsOutput=True,
    10. Expression="P2 / 3",
    11. DisplayText="my_expression")
  • Member, Employee Posts: 252
    50 Answers 100 Comments 100 Likes Second 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.

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

Welcome!

It looks like you're new here. Sign in or register to get started.