Migrate parameter¶
When a PythonPart is extended by renaming, adding, deleting, … of parameters, it’s possible to migrate the parameter data from an older PythonPart object version to the new parameter structure.
To do this, the function
def migrate_parameter(parameter_list: List[str],
version : float):
""" migrate the parameter
Args:
parameter_list: parameter list
version: PythonPart version
"""
must be added to the py file of the PythonPart.
A necessary migration can be checked by the version number of the PythonPart object.
if version < 1.9:
return
The conversion of the parameters can be done by using the functions of BuildingElementMigrationUtil or by a custom migration implementation.
In this case, the parameter Minor has been renamed to MinorRadius and the parameter Major was replaced with the parameter MajorDiameter. If a data conversion of the parameter is necessary, a conversion function can be used.
#--------------------- transfer the data to the new parameter names
BuildingElementMigrationUtil.transfer_parameter_value(parameter_list, "", "Minor", "", "MinorRadius")
BuildingElementMigrationUtil.transfer_parameter_value(parameter_list, "", "Major", "", "MajorDiameter",
lambda value: str(float(value) * 2))
The complete implementation of the parameter migration is shown in the example Cone. The file Cone.py is located in the folder
..\etc\PythonPartsExampleScripts\GeometryExamples