Create interactor PythonPart¶
The interactor PythonPart has the same file structure as a standard PythonPart. To make the interactor visible for the PythonParts framework, the following tag must be set in the xxx.pyp file:
One of the following create_interactor functions must then be implemented in the xxx.py file:
Using the first function, the PythonPart framework performs the following steps:
read the parameters from the xxx.pyp file
assign the values from the last input to the parameters (if tag <ReadLastInput> is set) in the input mode
assign the values from a selected PythonPart to the parameters when starting an input by Match from the context menu or double right click
assign the values from the selected PythonPart to the parameters in the modification mode
def create_interactor(coord_input: AllplanIFW.CoordinateInput,
pyp_path: str,
global_str_table_service: StringTableService,
build_ele_list: List[BuildingElement],
build_ele_composite: BuildingElementComposite,
control_props_list: List[ControlProperties],
modify_uuid_list: list):
"""
Create the interactor
Args:
coord_input: coordinate input
pyp_path: path of the pyp file
global_str_table_service: global string table service for default strings
build_ele_list: building element list
build_ele_composite: building element composite
control_props_list: control properties list
modify_uuid_list: UUIDs of the existing elements in the modification mode
Returns:
Created interactor object
"""
return Interactor(coord_input, pyp_path, global_str_table_service, build_ele_list,
build_ele_composite, control_props_list, modify_uuid_list)
class Interactor():
"""
Definition of class Interactor
"""
def __init__(self,
coord_input: AllplanIFW.CoordinateInput,
pyp_path: str,
build_ele_list: List[BuildingElement],
build_ele_composite: BuildingElementComposite,
control_props_list: List[ControlProperties],
modify_uuid_list: list):
An example is given in the files
…\etc\Examples\PythonParts\InteractorExamples\LinesFromFileInteractor.pyp…\etc\PythonPartsExampleScripts\InteractorExamples\LinesFromFileInteractor.py
The second function gives the PythonPart all control over the workflow, but isn’t usable for a PythonPart that should have modification functionality. The xxx.pyp only needs to consist of the <Script> tag.
def create_interactor(coord_input: AllplanIFW.CoordinateInput,
pyp_path: str,
global_str_table_service: StringTableService):
"""
Create the interactor
Args:
coord_input: coordinate input
pyp_path: path of the pyp file
global_str_table_service: global string table service for default strings
Returns:
Created interactor object
"""
return Interactor(coord_input, pyp_path, global_str_table_service)
class Interactor():
"""
Definition of class Interactor
"""
def __init__(self,
coord_input: AllplanIFW.CoordinateInput,
pyp_path: str,
global_str_table_service: StringTableService):
The complete workflow, including reading the data, displaying the property palette, … is now available in the xxx.py file. If more than one property palettes are required during the workflow, for each property palette an own file with the needed parameter can be created. We recommend to use the extension .pal.
An example is given in the files
…\etc\Examples\PythonParts\InteractorExamples\Elements3DInteractor.pyp…\etc\PythonPartsExampleScripts\InteractorExamples\Elements3DInteractor.py