Skip to content

Commit 95567d3

Browse files
committed
First prototype
0 parents  commit 95567d3

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

class2layer.inx

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
3+
<name>IfcClasses to Layers</name>
4+
<id>effect.class2layer</id>
5+
6+
<label>New layers will be created from IfcClasses.</label>
7+
8+
<effect needs-live-preview="false">
9+
<object-type>all</object-type>
10+
<effects-menu>
11+
<submenu name="IFC"/>
12+
</effects-menu>
13+
</effect>
14+
<script>
15+
<command location="inx" interpreter="python">class2layer.py</command>
16+
</script>
17+
</inkscape-extension>

class2layer.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
3+
import inkex
4+
from inkex import Group
5+
6+
global layer_list
7+
global layer
8+
layer_list = []
9+
10+
class CreateLayersFromClasses(inkex.EffectExtension):
11+
def effect(self):
12+
svg = self.svg
13+
for g in svg.xpath('//svg:g'):
14+
g_class = g.get('class')
15+
check_str = 'Ifc'
16+
if g_class:
17+
for class_name in g_class.split():
18+
if check_str in class_name:
19+
if class_name not in layer_list:
20+
layer = svg.add(Group(id=class_name))
21+
layer.set('inkscape:groupmode', 'layer')
22+
layer.set('inkscape:label', class_name)
23+
layer_list.append(class_name)
24+
else:
25+
layer = svg.getElementById(class_name)
26+
layer.add(g)
27+
28+
if __name__ == '__main__':
29+
CreateLayersFromClasses().run()

0 commit comments

Comments
 (0)