I want to write a Gimp-Python plugin in order to export all SVG paths from the current image. This seems quite simple but I am stuck with pdb calls, I may not be calling procedures correctly so I need your help.
Here is my code :
#!/usr/bin/env python
from gimpfu import *
def exportToSvg(img, layer) :
gimp.pdb.vectors_export_to_file(img,"C:/Users/Public/Documents/output.svg",0)
register(
"ExportToSvg",
"Export all SVG paths",
"Export all SVG paths from current image",
"My Name",
"My company",
"2015",
"<Image>/MyScripts/Export to svg",
"*",
[],
[],
exportToSvg)
main()
After opening Gimp and loading an image, when I click on my plugin i receive this error:
Error when calling « gimp-procedural-db-proc-info » : Procedure« vectors-export-to-file » not found
When I search in Gimp PDB, I can find"gimp-vectors-export-to-file" so what is the problem ? How should I call this procedure ?
You are almost there - the "pdb" module is just exposed at module level with the from gimpfu import *
so, no need to do gimp.pdb.<procname>
- just pdb.<procname>
(it would work, though).
But what is really causing your error is the procedure is actually called
gimp_vectors_export_to_file
- and not vectors_export_to_file
-
You should be calling it as:
pdb.gimp_vectors_export_to_file(img,"C:/Users/Public/Documents/output.svg",None)
Also note that for most PDB calls requiring integer identifiers of image items, you should pass an apropriate Python object representing that item instead. The "Vectors" object for saving individual Vectors is obtained by calling other PDB functions. For saving all vectors , instead of the "0" listed in the function description, pass None
.
NB: there is a Python interactive console you can access using filters->python->console
- it is much easier to code for these plug-ins and scripts if you test your pdb calls and image manipulations interactively first.
To get a reference to your image in the interactive console, type:
img = gimp.image_list()[0]