Skip to content

Commit

Permalink
First prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
elschilling committed Feb 2, 2024
0 parents commit 95567d3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions class2layer.inx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>IfcClasses to Layers</name>
<id>effect.class2layer</id>

<label>New layers will be created from IfcClasses.</label>

<effect needs-live-preview="false">
<object-type>all</object-type>
<effects-menu>
<submenu name="IFC"/>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">class2layer.py</command>
</script>
</inkscape-extension>
29 changes: 29 additions & 0 deletions class2layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python

import inkex
from inkex import Group

global layer_list
global layer
layer_list = []

class CreateLayersFromClasses(inkex.EffectExtension):
def effect(self):
svg = self.svg
for g in svg.xpath('//svg:g'):
g_class = g.get('class')
check_str = 'Ifc'
if g_class:
for class_name in g_class.split():
if check_str in class_name:
if class_name not in layer_list:
layer = svg.add(Group(id=class_name))
layer.set('inkscape:groupmode', 'layer')
layer.set('inkscape:label', class_name)
layer_list.append(class_name)
else:
layer = svg.getElementById(class_name)
layer.add(g)

if __name__ == '__main__':
CreateLayersFromClasses().run()

0 comments on commit 95567d3

Please sign in to comment.