Batch editing elements

Say I want to make all my “reserarch” notes private.

Is there any way I can do it other than editing them one by one?

Set up a Custom Filter that finds all the “Research” notes.

If it was a Person, Event, or Media; then you could have used the Set Privacy addon tool (Tools → Family Tree Processing → Set Privacy… ) with that filter.


Instead, you will probably need to build a script for the SuperTool addon tool from Isotammi. There is another thread describing a similar SuperTool privacy setting script for People from before the Set Privacy addon was available. You just have to adapt it for Notes.

2 Likes

You might ask @Mattkmmr if he would expand his Set Privacy tool to handle Notes too. When someone had a similar inquiry about setting Event privacy en masse, he knocked out a very quick and powerful enhancement to his Set Privacy tool.

1 Like

Thanks for the info and the links. I’m not a technical user, so unfortunately writing a script is not an option for me.

I have a small DB, It doesn’t take much time to change manually all my notes, so is not really a problem in my case. I simply assumed that this kind of batch editing was possible with the core program but I was unable to find a way to do it.

Having said that, it would be nice if the Set Privacy Tool would support notes too.

1 Like

The script was REALLY easy to adapt.

Here, I’ve gone into the Notes category and created a Custom Filter for “Source Note” type Notes.

(Using the Example.gramps tree, this filtered to 2 of that tree’s 19 Notes. Always learn a new technique using a fresh import of the Example.gramps file into a new blank tree.)

Then with the Notes category active, open Isotammi’s SuperTool addon tool and use FileOpen to load the script transcribed below. Test the script with the Execute… but make certain to set the “Filtered objects” radio button and have “Commit changes” deselected until after successful testings. After confirming the list shows the correct records would update, enable the “Commit changes” and Execute a final time.


The Filter gramplet actually needs to be in the sidebar, not the bottombar. This Notes view mode has the Privacy column displayed using the ViewConfigure options


Save the following as text file named : SuperTool-Notes Privacy.script

[Gramps SuperTool script file]
version=1

[title]
SuperTool-Notes Privacy

[category]
Notes

[initial_statements]
# A simple script to change the Gramps Privacy "padlock" Oct2022 # of filtered Notes to locked
# completely UNSAFE. Make a backup before running
# source:    https://gramps.discourse.group/t/how-to-set-private-record-for-multiple-people/2885/3

[statements]
myinitprivacy = note.get_privacy()
note.set_privacy(True)
myendprivacy = note.get_privacy()

[filter]

[expressions]
 note, myinitprivacy, myendprivacy

[scope]
filtered

[unwind_lists]
False

[commit_changes]
True

[summary_only]
False
1 Like

The only line that’s vital in the script above is:

[statements]
note.set_privacy(True)

All the rest is about feedback & double-checking myself.

I think if you change note by obj that script will be available in any category

1 Like

Thanks again, I’ve done the job manually already, but I’ll keep on eye on this thread if I need to do this in the future.

[Gramps SuperTool script file]
version=1

[title]
SuperTool-Set Privacy

[category]

[initial_statements]
# SuperTool-Set Privacy.script : A simple script to change the Gramps Privacy "padlock" of View objects to locked
# Completely without error handling. Make a backup before running
# discussion:    https://gramps.discourse.group/t/batch-editing-elements/3552 
# 23 Apr 2023 B.McCullough

[statements]
myinitprivacy = obj.get_privacy()
obj.set_privacy(True)
myendprivacy = obj.get_privacy()

[filter]

[expressions]
 obj, myinitprivacy, myendprivacy

[scope]
selected

[unwind_lists]
False

[commit_changes]
False

[summary_only]
False
1 Like

Since this thread was written, a SuperTool extension (getargs.py or GetArguments) has been added to allow User selectable input to offer a pop-up list or checkbox in addition to a type-in textbox.

So now there is a Checkbox that lets you Set Privacy if selected, and Clear Privacy if deselected:


Right now, this means that the extension must be identified with a @include statement to make those option available. For now, that script reads:

[Gramps SuperTool_beta script file]
version=1

[title]
SuperTool-Object Privacy

[category]
People

[initial_statements]
# A simple script to change the Gramps Privacy "padlock" Oct2022 # of selected Category object to locked
# completely UNSAFE. Make a backup before running
# based on:    https://gramps.discourse.group/t/how-to-set-private-record-for-multiple-people/2885/3
@include getargs.py
args = getargs2(myTestLevel=("Set Privacy: ", bool, True))
counter = 0

[statements]
myInitPrivacy = obj.get_privacy() 
if obj.get_privacy() != args.myTestLevel:
    obj.set_privacy(args.myTestLevel)
    counter +=1
else: 
    None

[filter]

[expressions]
name, myInitPrivacy, obj.get_privacy(), counter

[scope]
selected

[unwind_lists]
False

[commit_changes]
False

[summary_only]
False

@kku

Can such a script be made to work in ANY category? Every time that I save a Script as a Note, it sets the blank universal [category] back to the current category.

We’ve spoken before about documenting an example of wrapping a SuperTool script in an Addon Tool.

This seems like a good opportunity. Setting Privacy is a common need. And the thread here shows a Privacy script evolving from a narrow scope (in the Notes category only). And then showing how to validating the outcome before using the “commit-changes”

It then evolved to be usable in any category and then added a GetArguments example.

(Another expansion to this thread might be to demonstrate how to add a Filter selector. But that is a luxury.)

Can you describe what changes are needed to make the script work as an add-on Tool? Consider the process of making a plugin and publishing it to a GitHub repository as already covered.

The big questions are:

  • what modules need to be included in an addon that the SuperTool shell normally provides.
  • how to support the various “[scope]” selections of “All objects” vs. “Filtered objects” vs. “Selected Objects”.

Every time that I save a Script as a Note, it sets the blank universal [category] back to the current category.

Yes, Supertool always sets the category as the current category when saving a script. This is a design mistake - Supertool should support multiple categories better. Note however, that a script can still work in any category even if there is a warning when the script is loaded.

1 Like

One possible scenario:

Supertool provides the function ‘supertool_execute’. This function can be invoked in any addon and it can execute any Supertool code. The code to set the privacy attribute would be something like

from supertool_utils import supertool_execute

rsp = supertool_execute(category='Notes', db=db,
      handles=handles, statements='obj.set_privacy(True)')

The answers to the two questions are

  • only supertool_utils need to be imported as shown above
  • the ‘scope’ is supported by the ‘handles’ parameter: the addon needs to supply the handles of the objects to be processed (passing None as the handles parameter will process all objects in the given category)
1 Like

That’s wonderful!!! Thanks

OK. That example is executing a single SuperTool Script statement.

How about if I want to use an entire script? Can I pass an entire Script through the supertool_utils with supertool_execute ? Or is it necessary to use the script as an outline for a plugin?

This is not yet documented in the README but there is also the function ‘supertool_execute_script’ that can execute a complete script file. Its usage is like

rsp = supertool_execute_script(script, dbstate=None, db=None, 
         trans=None, handles=None, args="")

However, the [scope] in the script file is ignored and the ‘handles’ parameter is used instead.

1 Like