[Inkscape Extension] Import SVG / Edit XML-Tree

Discussion about writing code for Inkscape.
BigSmoker
Posts: 4
Joined: Mon Apr 25, 2016 5:48 pm

[Inkscape Extension] Import SVG / Edit XML-Tree

Postby BigSmoker » Fri May 13, 2016 9:59 pm

Hello InkscapeForum i have question for a program i wrote in python.

I want to Import a "template.svg" with different Groups (with ID) and need to Seperate them in my Program.


1. How do i load the "template.svg" into my program?
2. What are the tools to manipulate the XML-Tree which Inkscape offers?

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: [Inkscape Extension] Import SVG / Edit XML-Tree

Postby Moini » Fri May 13, 2016 10:05 pm

I think you might want to look at Jabier's pattern extension. That one will show you how to import a new template, and it also manipulates objects in the template before loading it into Inkscape: https://inkscape.org/en/~jabiertxof/%E2 ... xtension+0
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

BigSmoker
Posts: 4
Joined: Mon Apr 25, 2016 5:48 pm

Re: [Inkscape Extension] Import SVG / Edit XML-Tree

Postby BigSmoker » Fri May 13, 2016 10:14 pm

Thanks i will take a look on that!

BigSmoker
Posts: 4
Joined: Mon Apr 25, 2016 5:48 pm

Re: [Inkscape Extension] Import SVG / Edit XML-Tree

Postby BigSmoker » Tue May 17, 2016 4:50 pm

How can i turn a XPATH into a .ELEMENT?

I got my Object as XPATH but cant Access its Attributes because its XPATH and no direct ElementTree object :lol:

BigSmoker
Posts: 4
Joined: Mon Apr 25, 2016 5:48 pm

Re: [Inkscape Extension] Import SVG / Edit XML-Tree

Postby BigSmoker » Wed May 18, 2016 12:01 am

I have different Objects, i seperate them via xpath

searchStr = '//svg:g[@attribute-creator="popup1"]'
selectStr = template.xpath(searchStr, namespaces=inkex.NSS)

Works fine, my Object is saved in

selectStr[0]



...now i got

Main Group (popup1)
-Child Group Button1
--Rectangle Rect1
--Text
-Child Group Button2
--Rectangle Rect2
--Text

its everything in selectStr[0] , which seems to be "xpath" !

...i dont want to change the Original File because its the Template to copy from
I use the XML-Name "attribute-creator" for selecting the Groups/Objects like to edit it with .set method

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: [Inkscape Extension] Import SVG / Edit XML-Tree

Postby brynn » Wed May 18, 2016 8:18 am

I can't help with this. But I wanted to point you to this page, with lots of resources. I'm not even sure if what you need is covered here. But it's worth having a look, probably (if you haven't already seen it).

Also for the best help with writing extensions, I would suggest one of the mailing lists. For whatever reason, mailing lists is how the more advanced users and developers prefer to interact. Either the development list or user list will get you the help you need (if you don't get answers here). https://inkscape.org/en/community/mailing-lists/

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: [Inkscape Extension] Import SVG / Edit XML-Tree

Postby Moini » Wed May 18, 2016 8:50 am

I think Brynn meant to link to https://inkscape.org/en/develop/extensions/ .
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: [Inkscape Extension] Import SVG / Edit XML-Tree

Postby brynn » Wed May 18, 2016 12:59 pm

Oh yeah. Sorry, I forgot to paste in the url. Thanks Moini!


Return to “Programming”