Export control in Krita

A Krita 6+ script that lets you export directly into the source directory instead of what it last remembers. Advanced export by default. If you ignore the resizing tab, it’s no different than normal export.

Written in pyqt6, this should work from the Workflow Buttons docker, but does not work from the toolbar.

import os
from krita import Krita

app = Krita.instance()
doc = app.activeDocument()

if doc is not None:
    file_path = doc.fileName()
    
    if not file_path:
        app.action('file_save_as').trigger()
    else:
        dir_path = os.path.dirname(file_path)
        old_loc = app.readSetting('File Dialogs', 'SaveAs', '')
        app.writeSetting('File Dialogs', 'SaveAs', dir_path)              
        app.action('file_export_advanced').trigger()
        
        if old_loc:
            app.writeSetting('File Dialogs', 'SaveAs', old_loc)

A note about the toolbar:

To get a script on the toolbar, you have to set it as a shortcut in Krita’s Ten Scripts first. The fact that it’s limited to ten is already a problem, if you have a lot of scripts. After it’s a shortcut, you can add it to the toolbar.

Which is fine if it works. But often it doesn’t. I queried AI (in this case, Gemini) and it told me that Krita wraps the toolbar items in a “global action wrapper” which causes the script to struggle. So it’s just as well to focus on making the scripts functional for the Workflow Buttons docker, which can include an unlimited number of scripts with custom icons.

Leave a comment