Skip to content

Favorites

PythonPart favorite files (.pyv) can contain parameters of a certain PythonPart (all of them or just a selection) together with their values. A typical use case for it is, when the user wants to place the PythonPart in the drawing file with the same parameters over and over again, but wants to save time by not having to input the same values every time.

The three buttons on the bottom left side of a property palette are responsible for saving and loading a favorite file as well as resetting the values in the palette to the defaults defined in the .pyp file.

Favorites

In a standard PythonPart this functionality works without further actions. In an Interactor the handling of favorite files must be implemented by the developer with the appropriate functions.

Favorite file in Interactor

The class BuildingElementListService provides methods for managing the favorite files. Use these methods inside special functions to properly handle the favorite files.

Example

The complete implementation of the favorites handling in an interactor PythonPart is shown in the example Line2DInteractor located in:

  • ..\etc\PythonPartsExampleScripts\InteractorExamples\Line2DInteractor.py
  • ..\etc\Examples\PythonParts\InteractorExamples\Line2DInteractor.pyp

Save favorite

To save the parameter values in the favorite file, implement the method execute_save_favorite in your interactor class. This method is called after the user have selected the saving path of the favorite file.

Example

def execute_save_favorite(self, file_name):
    """ save the favorite data """

    BuildingElementListService.write_to_file(file_name, self.build_ele_list)        

The member function write_to_file reads the data from build_ele_list and writes it into the favorite file.

Note

Parameter persistency is being considered, when saving the favorite file. Only parameters with the <Persistent> tag set to Favorite or ModelAndFavorite are being saved.

Read favorite

To read the parameter values from the favorite file, implement the function execute_load_favorite into your interactor class. This function is called after the user have selected the favorite file.

Example

def execute_load_favorite(self, file_name):
    """ load the favorite data """

    BuildingElementListService.read_from_file(file_name, self.build_ele_list)

    self.palette_service.update_palette(-1, True) #(1)!       
  1. Directly after reading the parameters the palette must be updated to see the new values

The method read_from_file reads the data from the favorite file and stores it into the build_ele_list.

Reset parameter values

When the user presses the reset button Reset parameter values the function reset_param_values is called. To actually reset the values in the property palette to the defaults from the .pyp file, this method must be implemented into the Interactor class.

Example

def reset_param_values(self, _build_ele_list): #(1)!
    """ reset the parameter values """

    BuildingElementListService.reset_param_values(self.build_ele_list) #(2)!

    palette_service.update_palette(-1, True) #(3)!
  1. Note that the old values from the property palette are being passed to the function...
  2. ... but we are not using them here as an argument for the reset funtion. We are reseting the actual building_element instead...
  3. ...and updating the palette directly aftewards.

Update parameter values

When the PythonPart is created as an interactor and the .pyp file is read outside the interactor in the PythonParts framework, saving and reading the favorite data is also executed in the framework.

To execute some additional functionality after reading the favorite data, the method update_after_favorite_read must be implemented into the Interactor class. This method is called after the name of the favorite file has been entered in the favorite file dialog and the data are read from the favorite file.

Example

def update_after_favorite_read(self):
    """
    Update the data after a favorite read
    """

    self.palette_service.update_palette(-1, True) #(1)!
  1. At least the update of the property palette should be done here

Default favorite file

The default favorite file of a PythonPart is saved under the following path:

..\Usr\local 1\tmp\_PythonPart_name_.pyv

Save default favorite

To save the current parameter values into the default favorite file in an Interactor PythonPart, use the method write_to_default_favorite_file.

Tip

We reccomend implementing the saving of the current parameter values in a default favorite file in the _del_ function of the interactor class, as this function is called after the PythonPart is terminated. Here is an example:

def __del__(self):
""" save the default favorite data """

    BuildingElementListService.write_to_default_favorite_file(build_ele_list)

Read default favorite

To read the parameter values from the default favorite file in an Interactor PythonPart, use the method read_from_default_favorite_file.

Tip

The best place to implement this method is directly after reading the data from the .pyp file.

result, build_ele_script, build_ele_list, control_props_list,    \
build_ele_composite, part_name, file_name = \
build_ele_service.read_data_from_pyp(pyp_path + "\\Line2DInteractor.pal", str_table_service.str_table, False,
                                          str_table_service.material_str_table)

if not result:
    return

BuildingElementListService.read_from_default_favorite_file(build_ele_list)

Read last input

In a standard PythonPart, it is possible to save the parameter values from the currently created PythonPart and use it as default values when accessing the PythonPart the next time. To enable this functionality, the tag <ReadLastInput> must be set to True in the <Script> section of the .pyp file:

<Script>
    <ReadLastInput>True</ReadLastInput>
</Script>

In this case, when starting a PythonPart, the framework looks for the default favorite file. If it exists, the parameter values from the file are used. Otherwise the defaults from the .pyp file are used. When terminating the PythonPart, the .pyv file with the current parameter values is saved automatically in this directory, overriding the old one.

In an interactor PythonPart this feature must be implemented by the developer.


  1. In a network installation expect here a username instead of local