-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclass2layer.py
30 lines (26 loc) · 973 Bytes
/
class2layer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
import inkex
from inkex import Group
def class2layer(svg):
layer_list = []
xpath_expr = "//*[contains(concat(' ', normalize-space(@class), ' '), ' Ifc')]"
elements = svg.xpath(xpath_expr)
for element in elements:
classes = element.get('class').split()
IfcClass = [string for string in classes if string.startswith('Ifc')][0]
# inkex.utils.debug(IfcClass)
if IfcClass not in layer_list:
layer = svg.add(Group(id=IfcClass))
layer.set('inkscape:groupmode', 'layer')
layer.set('inkscape:label', IfcClass)
layer_list.append(IfcClass)
else:
layer = svg.getElementById(IfcClass)
layer.add(element)
# inkex.utils.debug(IfcClass)
return svg
class CreateLayersFromClasses(inkex.EffectExtension):
def effect(self):
self.svg = class2layer(self.svg)
if __name__ == '__main__':
CreateLayersFromClasses().run()