Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to work with effects in GIMP Python?
#5
In practice  for a similar call I use a wrapper:
Code:
def callProcedure(procId: str, run_mode=Gimp.RunMode.NONINTERACTIVE, **kwargs):
   procedure=Gimp.get_pdb().lookup_procedure(procId)
   if procedure is None:
       raise Exception(f'Procedure "{procId}" no found')
   config: Gimp.ProcedureConfig = procedure.create_config()
   #config.set_property('run-mode',run_mode)
   for name,value in kwargs.items():
       if isinstance(value,list):
           config.set_core_object_array(name.replace('_','-'),value)
       else:
           config.set_property(name.replace('_','-'),value)
   result=procedure.run(config)
   results = [result.index(i) for i in range(result.length())]
   if results[0] is not Gimp.PDBStatusType.SUCCESS:
       raise Exception(f'Error returned from procedure "{procId}": {results[0].value_name}')
   return results[1:]

So you can call the procedure with Python keyword arguments:

Code:
   res = callProcedure('plug-in-sel2path', image=image,
                       drawables=[selectableLayers[0]],
                       align_threshold=.05,
                       corner_surround=1,
                       error_threshold=.05,
                       filter_epsilon=1,
                       filter_iteration_count=1,
                       filter_percent=0.
                       )
And the callProcedure code converts python-friendly argument names such as filter_epsilon into Gimp friendly names such as filter-epsilon.
Reply


Messages In This Thread
RE: How to work with effects in GIMP Python? - by Ofnuts - 04-06-2025, 05:31 PM

Forum Jump: