Edit name of entity when using @ParamsFromFile

When using @ParamsFromFile, the name of the created entity automatically becomes equal to the filename. It would be nice if during upload it is possible to change this name. I ran into the following two use cases:

  • The file extension is included by default. When visualising geffiles the .GEF extension can cause labels to overlap even though the extension adds no beneficial information to the user.
  • When downloading .GEF files from the BRO they are often named something like CPT00000000000<gef_number>_IMBRO.GEF. In this name a lot of characters just produce noise and a name like CPT<gef_number> would make it more clear.

The only workaround is to add an API call that renames the entities but this call would need to be connected to a button since it cannot be added in the function to which the @ParamsFromFile decorater is used. I currently do not see a workaround that achieves what I want to achieve.

Found out that the actual entity is created before the @ParamsFromFile method is called. One of the kwargs is the entity_id. Turns out you can already make modification to the entity using the API.

# Sample code

@ParamsFromFile(file_types=[".txt"])
def process_file(self, file: File, entity_id: int, **kwargs):
    # Rename the newly created entity
    api = API()
    current_entity = api.get_entity(entity_id)
    current_entity.rename("This is my new name")