当前位置: 首页 > article >正文

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插件需要两个文件:*.inx、*.py,并且将这两个文件放到上面的目录,若格式正确,就能被加载出来,显示到扩展菜单下

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

hello_world.inx

<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">

<!-- 1. Replace this with the title of your extension. This will Show in the extensions menu-->
<_name>Hello World</_name>

<!-- 2. Fill this in. It ensures that your extension has a unique ID -->
<id>yourname.yourorganization.title</id>

<!-- 3. Show the relative path to your extension. For example, `~/.config/inkscape/extensions/template.py` would be `template.py`-->
<dependency type="file" location="inx">hello_world.py</dependency>
<!-- <dependency type="executable" location="extensions">inkex.py</dependency> -->

<effect>
    <object-type>all</object-type>
    <effects-menu>

    <!-- 4. Where is your extension located? (You can nest menus) -->
    <submenu _name="submenu"/>

    </effects-menu>
</effect>
<script>

    <!-- 5. Same as #4 -->
    <command location="inx" interpreter="python">hello_world.py</command>

</script>
</inkscape-extension>

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

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

参考文档

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/


http://www.kler.cn/a/37703.html

相关文章:

  • STL源码刨析_vector
  • Pytorch基本使用—参数初始化
  • Spring Boot使用DataFreezer操作Aerospike
  • 确定Linux虚拟机需要安装哪个架构的应用
  • mongdb安全认证详解
  • Jenkins Pipline使用SonarScanner 检查 VUE、js 项目 中遇到的Bug
  • 渲染流程(上):HTML、CSS和JavaScript,是如何变成页面的?
  • Flutter:EasyLoading(loading加载、消息提示)
  • MySQL-分库分表详解(三)
  • 三菱PLC上位机测试
  • 100种思维模型之安全边际思维模型-92
  • 第五十八章 开发Productions - ObjectScript Productions - 测试和调试Production
  • 《计算机网络--自顶向下方法》第四章--网络层:数据平面
  • c# GDI+绘图的应用-多边形
  • 【C++刷题集】-- day4
  • 分布式锁与同步锁
  • MySQL---表数据高效率查询(简述)
  • C++中随机数的使用总结
  • C国演义 [第九章]
  • 拖动排序功能的实现 - 使用HTML、CSS和JavaScript