I'm trying to create an extension in inkscape that adds a gradient mesh to the select shape. (then it would do something else but I'm blocked at this step).
import inkex
from inkex.elements._filters import MeshGradient
class CreateMeshGradient(inkex.EffectExtension):
def add_arguments(self, pars):
pars.add_argument("--rows", type=int)
pars.add_argument("--cols", type=int)
def effect(self):
# Retrieve user inputs
myRows = self.options.rows
myCols = self.options.cols
# Create a new mesh gradient with a default position
mesh_gradient = inkex.elements._filters.MeshGradient.new_mesh((0, 0), myRows, myCols)
gradient_id = self.svg.get_unique_id("mesh_gradient")
mesh_gradient.set('id', gradient_id)
self.svg.defs.add(mesh_gradient)
rect = inkex.Rectangle()
rect.set('x', '10')
rect.set('y', '10')
rect.set('width', '100')
rect.set('height', '100')
rect.set('fill', 'url(#' + mesh_gradient.get('id') + ')')
#rect.set('style', 'fill:red')
self.svg.append(rect)
if __name__ == "__main__":
CreateMeshGradient().run()
The code runs without errors but It does not attach anything to the selected object. So to test it I also make the script create a rectangle and add it to the document. If I fill the rectangle in red it works. If I fill the rectangle with the mesh gradient the rectangle appears "trasparent" and it says that a mesh_gradient is attached it but I cannot edit it in no way with mesh tools, see attached image.
Hi,
I'm trying to create an extension in inkscape that adds a gradient mesh to the select shape. (then it would do something else but I'm blocked at this step).
I created a simple .inx and .py files
my_test.inx
and this is my python script.
The code runs without errors but It does not attach anything to the selected object. So to test it I also make the script create a rectangle and add it to the document. If I fill the rectangle in red it works. If I fill the rectangle with the mesh gradient the rectangle appears "trasparent" and it says that a mesh_gradient is attached it but I cannot edit it in no way with mesh tools, see attached image.
Any idea what I'm making wrong?
You do not set any stops for your mesh gradient. They are the key to make it work.