第二个插件实现画路路径, 添加图层
配置文件 D:\Inkscape\share\inkscape\extensions\mj_draw_path_example.inx
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Draw Path Example</name>
<id>org.inkscape.filter.mj_draw_path_example</id>
<effect>
<object-type>path</object-type>
<effects-menu>
<submenu name="AAA Tools"/>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">mj_draw_path_example.py</command>
</script>
</inkscape-extension>
程序文件 D:\Inkscape\share\inkscape\extensions\mj_draw_path_example.py
#!/usr/bin/env python
# coding=utf-8
import inkex
from inkex.elements import Group, PathElement
class MyExtension(inkex.EffectExtension):
# ...
def effect(self):
# Create a new layer. 增加一个叫MyNewlayer的图层, 注意1.0用插件可以产生同名图层,可能是bug
layer = self.svg.add(inkex.Layer.new(u'MyNewlayer'))
layer.set('style', 'display:true') # initially visible
layer.append(self.make_a_shape()) # 添加一个路径
return layer
def make_a_shape(self):
my_shape = PathElement()
# Lists of numbers, pythonic objects, Cubic curves etc.
my_shape.style = {'stroke': 'red', 'stroke-width': '2', 'fill': 'none'}
my_shape.path = "M 10 10 L 15 250 C 150 70 10 10 10 20" #svg 代码
# Transform can be modified in many ways too
my_shape.transform.add_translate(self.svg.namedview.center) #移动到中间
my_shape.transform.add_scale(2.0,2.0) #放大2倍
return my_shape
if __name__ == '__main__':
MyExtension().run()
实现结果为红线部分