In a custom plugin I'm calling some custom QgsProcessingAlgorithm
that are loaded with the plugin itself.
If I create an instance of these algorithms I need to prefill the parameters with some custom values and I think this can easily be done by passing a custom dictionary to the initAlgorithm
method [0].
I'm setting some side variables needed by be plugin (that have not to be outputs), but again this can be done by setting some class variables (i.e. self.my_custom_id = 'zzz'
) and getting them when needed.
my_algorithm = MyCustomAlgorithm()
my_algorithm.initAlgorithm(
'INPUT': 'custom_path'
)
# how to open and exec the algorithm dialog?
What I'm not able to do is to simply open/exec the algorithm dialog.
If I use processing.createAlgorithmDialog
then I can exec the algorithm dialog but I cannot retrieve the side variables needed.
my_dialog = processing.createAlgorithmDialog(
'my_custom_provider:my_custom_algorithm`,
{
'INPUT': 'custom_path'
}
)
my_dialog.exec_()
I'm stuck in this loop. Somebody has already faced the same issue?
1 Answer 1
In your second approach you could use the algorithm()
method to retrieve the instance of your custom QgsProcessingAlgorithm
and then access its class variables.
my_dialog = processing.createAlgorithmDialog(
'my_custom_provider:my_custom_algorithm',
{
'INPUT': 'custom_path'
}
)
# access your custom class variables
print(my_dialog.algorithm().my_custom_id) # prints 'zzz'
my_dialog.exec()
createAlgorithmDialog
can also receive an instance of QgsProcessingAlgorithm
as first argument to create a dialog. Therefore the following will also be a valid option:
my_algorithm = MyCustomAlgorithm()
my_dialog = processing.createAlgorithmDialog(
my_algorithm,
{
'INPUT': 'custom_path'
}
)
# access your custom class variables
print(my_algorithm.my_custom_id) # prints 'zzz'
# execute dialog
my_dialog.exec()
-
thanks! No idea why but my QGIS (doesn't matter which version 3.22, 3.26, 3.27) is crashing if I make an instance of my algorithm and pass it to the
createAlgorithmDialog
method. Anyway, I can use the unique identifier. I also discovered that you have access to the resuls withmy_dialog.results()
after the execution.matteo– matteo2022年08月02日 15:42:06 +00:00Commented Aug 2, 2022 at 15:42