Inkspace1.0 插件(1) HelloWorld python例子

本文介绍Inkscape1.0插件开发的变化及Helloworld示例。插件由*.inx和*.py组成,需放置于特定目录。通过示例draw_path_example.inx和HelloWorld.py展示配置与调用过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Inkspace1.0 发布后, 插件写法有了变化, 以前网上很多东西不能用了. 这里整理出一个Hello world例子.

Inkspace1.0的python插件有两个文件, *.inx和*.py, 写好后需要拷贝到插件目录, 比如我安装路径在 D:\Inkscape, 则插件路径为: D:\Inkscape\share\inkscape\extensions , 文档里说在Preferences里有个User extensions设置也可以用, 我没试过, 觉得没必要放在那里尝试, 因为写代码需要用的几个py库都在 share\inkscape\extensions里面, 便于查阅方法属性.

一个简单的插件配置文件draw_path_example.inx 如下:

<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
    <name>Hello World Example</name>
    <id>org.inkscape.filter.Hello_World_example</id>

    <effect>
        <object-type>path</object-type>
            <effects-menu>
                <submenu name="AAA Tools"/>
            </effects-menu>
    </effect>
    <script>
        <command location="inx" interpreter="python">HelloWorld.py</command>
    </script>
</inkscape-extension>

重点在<name> <id>,  <submenu> <command>, submenu会在Inkspace的Extension菜单下显示"AAA Tools" ,  name会在"AAA Tools"菜单上显示二级菜单"Hello World Example", 点击会调用 HelloWorld.py.  id不能跟别的插件相同, 否则可能调用不正常. 

所调用HelloWorld.py代码

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

import inkex

class HelloWorldExtension(inkex.EffectExtension):
    def effect(self):
        self.msg("Hello World")
        self.debug("debug world")

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

运行结果:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值