Sharing custom filters using FilterParams import/export

This 2020 thread has been migrated from Ideas because @kku implemented a feature for sharing a custom filter in the FilterParams (an Isotammi collection addon tool) in July 2025.
Recreating a Custom Filters from a multi-stage filter description is a painful and error-prone process.

I’ve found that I can move Custom Filters by appending the XML chunk in the custom_filters.xml in the gramps51 subdirectory of the User Directory.

Actually, you can just trim the closing line from the original XML file and then paste entire custom_filters.xml file with the 1st two lines removed (not included in the copy&paste buffer). Unfortunately, that duplicates any identically named Custom Filters … yet it only shows the first one in the GUI.

Perhaps the Custom Filters parser could be tweaked to keep reading past the </filters> and extra XML header? It should probably also overwrite identically named Filters withiin each filter object type.

The intervening lines that have to be deleted when the entire XML custom filter files have been concatenated are:

</filters>
<?xml version="1.0" encoding="utf-8"?>
<filters>

Example: the 5-stage filter in the Wiki example is:

<?xml version="1.0" encoding="utf-8"?>
<filters>
  <object type="Place">
    <filter name="5-Stage filter A" function="and" comment="Place filter A from the 5-stage FILTERS wiki example">
      <rule class="HasData" use_regex="False">
        <arg value="il"/>
        <arg value="State"/>
        <arg value=""/>
      </rule>
    </filter>
  </object>
  <object type="Event">
    <filter name="5-Stage filter B" function="and" comment="Event filter B from the 5-stage FILTERS wiki example">
      <rule class="MatchesPlaceFilter" use_regex="False">
        <arg value="5-Stage filter A"/>
      </rule>
    </filter>
  </object>
  <object type="Person">
    <filter name="5-Stage filter C" function="and" comment="Person filter C from the 5-stage FILTERS wiki example">
      <rule class="MatchesEventFilter" use_regex="False">
        <arg value="5-Stage filter B"/>
      </rule>
      <rule class="HasEvent" use_regex="False">
        <arg value="Residence"/>
        <arg value=""/>
        <arg value=""/>
        <arg value=""/>
        <arg value=""/>
        <arg value="0"/>
      </rule>
    </filter>
    <filter name="5-Stage filter D" function="and" comment="Person 5-Stage filter D from the 5-stage FILTERS wiki example">
      <rule class="MatchesEventFilter" use_regex="False">
        <arg value="5-Stage filter B"/>
      </rule>
      <rule class="HasEvent" use_regex="False">
        <arg value="Death"/>
        <arg value=""/>
        <arg value=""/>
        <arg value=""/>
        <arg value=""/>
        <arg value="0"/>
      </rule>
    </filter>
    <filter name="5-Stage filter E" function="or" comment="Person 5-Stage filter E from the 5-stage FILTERS wiki example">
      <rule class="MatchesFilter" use_regex="False">
        <arg value="5-Stage filter C"/>
      </rule>
      <rule class="MatchesFilter" use_regex="False">
        <arg value="5-Stage filter D"/>
      </rule>
    </filter>
  </object>
</filters>

Incidentally, the example 5-stage custom filter in the wiki is completely ineffective for its stated purpose. That purpose is to find People who were born or died in a variably selected State.

All the sample Events are logged at the city or county level. The filter only finds State level divisions. So the second stage Event filter does not find a single Event. And, of course, that means that none of the deeper stages can find anything either.

And it turns out that it isn’t even possible to accomplish the goal with the existing filters. The idiosyncratic Place hierarchy of the example.gramps tree defeats all the existing rules. There are 3 additional Place entities at the state level that straddle state lines. Since there might be more than 1 place, you cannot use the Places enclosed by another place rule.

It would be possible if there was a filter that would find returned from another Place filter … such as from Tagged places.

Maybe it would be good to have a tool to facilitate with upgrades. For example, after installing a new version, you could use it to migrate .ini settings and custom filters.

I added the possibility export and import custom filters to my FilterParams addon:

I hope that this would make sharing filters easier. This works nicely with multi-stage filters.

I finally broke out the test box again, re-set to a factory Win10 and installed the new Gramps 6.0.4 AIO so I could test some recent add-on updates. (A barebones system offers a different set of edge-case stresses.)

One of the things I was curious about was: how the new 1.2.5 FilterParams version implemented the Import and Export of custom filters. What was the format and how was the filter definition saved or loaded?

The FilterParams 1.2.5 update is available through the curated collection of plug-ins Isotammi Project in the 6.0, 5.2, 5.1 and 5.0 Addon Managers.

https://raw.githubusercontent.com/Taapeli/isotammi-addons/master/addons/gramps60
https://raw.githubusercontent.com/Taapeli/isotammi-addons/master/addons/gramps52
https://raw.githubusercontent.com/Taapeli/isotammi-addons/master/addons/gramps51
https://raw.githubusercontent.com/Taapeli/isotammi-addons/master/addons/gramps50

The Import and Export is a very straightforward interface. It uses the clipboard as the transfer medium, not the Gtk File Chooser.

After installing, restart Gramps to verify the updated plug-in version is registered. Open the FilterParameters tool from the Tools → Isotammi tools → FilterParams… menu option. To export, Select the desired filter and click the Export button. The XML representation of the filter will be copied to the clipboard and displayed in a Text Editor box. (You can tweak the definition in the text editor and re-clip the tweaked XML.) If it is a multi-stage filter, all the composite filters will be included in the clipped text.

Share the clipboarded data via eMail or an online forum. Or save it in your favorite text editor or as a Note in your Gramps tree.

Clicking the Import button in the FilterParams dialog will paste the current clipboard data into the text editor. You can tweak the filter definition before clicking the editor’s Import button. (You might want to make the filter name unique.) If there is an existing filter with any of the the filter names, the duplicates will be listed with an Overwrite confirmation or Cancel bailout option.

The Text Editor is a modal dialog. No other part of Gramps will be available until the dialog is dismissed. So if you store the XML as a Note, you will need to clipboard the code from a Note Editor before selecting the Import button.

A section on custom filter Import and Export has been added to the FilterParams README.md

The FilterParams screen capture has been updated in the wiki too.

@kku has just posted FilterParams 1.2.7 to the Isotammi Add-ons curated collection.

He has refined the Import/Export. It has been tested with XML with <filters> chunks. Designed to exchange the current Custom Filter with any referenced multistage Filters. It works both with and without an XML header. So it can also import an entire custom_filters.xml file.

The example custom filter in the wiki docs for FilterParams has a 3-stage custom filter. It finds People who have Events enclosed by a particular Place.

<filters>

  <object type="Person">
    <filter name="Some Event in place X" function="and" comment="People filter : who have the events">
      <rule class="MatchesEventFilter" use_regex="False" use_case="False">
        <arg value="Event in place x"/>
      </rule>
    </filter>
  </object>

  <object type="Event">
    <filter name="Event in place x" function="and" comment="Event filter : occurred in a place">
      <rule class="MatchesPlaceFilter" use_regex="False" use_case="False">
        <arg value="In place x"/>
      </rule>
    </filter>
  </object>

  <object type="Place">
    <filter name="In place x" function="and" comment="Place filter : enclosed by a place">
      <rule class="IsEnclosedBy" use_regex="False" use_case="False">
        <arg value="P0450"/>
        <arg value="0"/>
      </rule>
    </filter>
  </object>

</filters>

Try using the copy icon at the top-right of the listing (above) to clipboard those 3 Custom Filters. Then, with the People view active, open FilterParams 1.2.7 and click the Import button. The clipboarded XML will be in the text box. Click the new Import button in that dialog.

A dialog will appear that confirms 3 filters were imported and the dialog will switch to the new filter added in the current category.


If custom filters with the target names exist, an overwrite confirmation dialog will appear. If you want duplicates, you can go back to the clipboard text and edit the <filter name=""> to something unique.

Before doing a Test run of the new filter, select a Place. The default Place ID is P0450 and you may not have such an ID in your Place list.