Is it possible to set the ratio from a selection via script?

this is a follow up to my previous thread Exporting to png based on selection? - #3
(got a rough script working where it exports the selection as png, scales to thumbnail size and then updates the .kra file, thank you Grum999)

my question here is can I change the ratio of the rectangle selection tool via script? basically find the ratio of the whole document and then lock the selection to that ratio, as the .kra preview.png thumbnail can only accept the documents ratio

Sure, you can manipulate the PyQt5 elements directly:

from krita import *

qdock1 = next((w for w in Krita.instance().dockers() if w.objectName() == 'ToolBox'), None)
wobj1 = qdock1.findChild(QToolButton,'KisToolSelectRectangular')

if wobj1.isChecked():
    qdock2 = next((w for w in Krita.instance().dockers() if w.objectName() == 'sharedtooldocker'), None)
    wobj2 = qdock2.findChild(QDoubleSpinBox,'doubleRatio')
    wobj3 = qdock2.findChild(QPushButton,'lockRatioButton')

    wobj2.setValue(1.8)
    wobj3.setChecked(True)

Do note that sharedtooldocker changes depending on what tool you are on

2 Likes

Perfect
thank you!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.