2014-09-03 29 views
3

我目前正在使用Python编写Inkscape插件。在此插件中,我想从插件文件夹加载模板(现有的svg),并通过名称或密钥访问此模板中的某些对象。然后我想更改对象的边框和/或填充颜色,并向其中添加一些文本。我如何使用inkscape的python脚本接口来做到这一点?我发现了几个关于如何为inkscape编写插件的示例(请参见下文),但它们都适用于现有的已打开文档。在Inkscape插件中加载和修改svg

  1. http://www.hoboes.com/Mimsy/hacks/write-inkscape-extension-create-multiple-duplicates/
  2. http://wiki.inkscape.org/wiki/index.php/Script_extensions
  3. http://ospublish.constantvzw.org/blog/tools/inkscape-plugins-in-python
  4. http://wiki.inkscape.org/wiki/index.php/Generating_objects_from_extensions
  5. http://wiki.inkscape.org/wiki/index.php/PythonEffectTutorial

回答

0

你可以使用lxml

t = etree.parse("path/test.xml") 

然后,您可以任意

  1. 操纵t直接的性能 - 这可以从Python的完成而无需实际打开Inkscape中。你的树可以用t.write("filename")
  2. 保存添加t使用self.document.getroot().append(t)

此外,这是不是你问什么当前打开的文档,但可以派上用场:一个Inkscape的插件,允许你写短来自Inkscape的python片段:http://www.smanohar.com/inkscape.php