I was wondering how I can give the paths with labels or tags. Is it possible to set multiple labels/tags to one path? I'd need to give the paths multiple labels or tags for future data processing. I tried the code below but it doesn't work.
I want to work with a specific layer (called 'Polygon') of multiple paths, including two types of paths: 1, closed polygon paths and 2, paths that are line. I'd like to select all type 2 paths and give them a label called 'boundary'. Since the d string of the closed polygon paths ends up with 'Z', the d string of the line paths ends up with numbers. I used this method to select the line paths and use item.set() to give the label to the path.
class Prepare(inkex.EffectExtension):
def find_boundary(self,layer,boundary):
item = self.svg.get('inkscape:label')
if item == layer:
for child in item.getchidren():
dstr = child.get('d')
if dstr[-1] != 'Z':
child.set('label',boundary)
def effect(self):
self.find_boundary('Polygon','boundary')
if __name__ == '__main__':
Prepare().run()
Labels are really there for the user experience not for coding as such. They existing the Inkscape namespace, I would not try to manipulate them for assisting coding as such.
A very simple way is to use svg custom data attributes.
for item in selection_list:
item.set('data-czkpanda', 'Hello this is a custom data attribute :)')
item.set('data-inklinea', 'Another custom data attribute !')
they can be retrieved with item.get and removed using set None
for item in selection_list:
if item.get('data-czkpanda'): # if None, is bool False
item.set('data-czkpanda', None)
Hi, I wonder how I can find ALL the paths with the given attribute within a layer. If I use return, it only return one path and end the loop.
def paths_of_dAttr(self,layer,data_attr):
"""Select the paths labeled with the given attribute.
"""
for item in self.svg:
if item.get('inkscape:label') == layer:
paths = item.getchildren()
for path in paths:
if path.get(data_attr):
return path
Hi, I wonder how I can find ALL the paths with the given attribute within a layer. If I use return, it only return one path and end the loop.
def paths_of_dAttr(self,layer,data_attr):
"""Select the paths labeled with the given attribute.
"""
for item in self.svg:
if item.get('inkscape:label') == layer:
paths = item.getchildren()
for path in paths:
if path.get(data_attr):
return path
I was wondering how I can give the paths with labels or tags. Is it possible to set multiple labels/tags to one path? I'd need to give the paths multiple labels or tags for future data processing. I tried the code below but it doesn't work.
I want to work with a specific layer (called 'Polygon') of multiple paths, including two types of paths: 1, closed polygon paths and 2, paths that are line. I'd like to select all type 2 paths and give them a label called 'boundary'. Since the d string of the closed polygon paths ends up with 'Z', the d string of the line paths ends up with numbers. I used this method to select the line paths and use
item.set()
to give the label to the path.Labels are really there for the user experience not for coding as such. They existing the Inkscape namespace, I would not try to manipulate them for assisting coding as such.
A very simple way is to use svg custom data attributes.
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/data-*#:~:text=The%20data%2D*%20SVG%20attributes,belong%20to%2C%20with%20the%20SVGElement.
As the page points out:
xml
.;
,U+003A
).A
toZ
letters.I've used them before, very simple and easy.
Hi inklinea,
Thank you for your info. Would you mind providing a simple example?
I read the webpage about
data-*
and wrote my code, but I couldn't get it to work.Thanks!
they can be retrieved with item.get and removed using set None
Thanks!
Hi, I wonder how I can find ALL the paths with the given attribute within a layer. If I use return, it only return one path and end the loop.
Hi, I wonder how I can find ALL the paths with the given attribute within a layer. If I use return, it only return one path and end the loop.
I solved the problem using xpath method.