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

Ayush Kumar
Member, Moderator, Employee Posts: 479
✭✭✭✭
Answers
-
- 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")
0 -
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)
2