Inkscape扩展脚本入门

Inkscape官网

https://inkscape.org/

建议下载1.3版本

官方插件脚本文档

https://inkscape-extensions-guide.readthedocs.io/en/latest/index.html

但这个文档似乎和当前版本不符合,直接按照其内的方法写脚本会有问题

Inkscape插件加载目录

默认情况下,插件加载目录为

C:\User\用户名\AppData\Roaming\inkscape\extensions

也可以通过菜单、编辑、首选项、系统,设置这个目录

Inkscape扩展脚本入门_第1张图片

 插件脚本

一个完整的Inkscape插件需要两个文件:*.inx、*.py,并且将这两个文件放到上面的目录,若格式正确,就能被加载出来,显示到扩展菜单下

以下为最基本的Hello World插件示例

hello_world.inx





<_name>Hello World


yourname.yourorganization.title


hello_world.py



    all
    

    
    

    


hello_world.py

#!/usr/bin/env python
# coding=utf-8

import inkex

from inkex.elements import TextElement

class Greet(inkex.GenerateExtension):

    def generate(self):
		# return inkex.errormsg(_("Hello"))
        textElement = TextElement()
        textElement.text = 'Hello World'
        return textElement

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

若格式正确,加载之后就能在看到菜单、扩展、Hello World

Inkscape扩展脚本入门_第2张图片

执行后能看到文档内被新建一个文本

Inkscape扩展脚本入门_第3张图片

参考文档

https://pdfroom.com/books/inkscape-guide-to-a-vector-drawing-program-4th-edition/eKRd6xyo2Zp/download

https://inkscape-extensions-guide.readthedocs.io/en/latest/index.html

https://inkscape.org/forums/beyond/cannot-import-inkex/

你可能感兴趣的:(inkscape,python)