[Solved] How to move each group to a new created layer

Discussion about writing code for Inkscape.
amjahed
Posts: 5
Joined: Sat Apr 02, 2011 4:02 am

[Solved] How to move each group to a new created layer

Postby amjahed » Wed May 25, 2011 11:38 am

Salam for all,
For example :
Input SVG : One layer (root) with n groups
Output SVG : n layer (each layer contains one group

There is a simple way to do it with python ? python/xml ?

Thanks and best regards
Last edited by amjahed on Wed Jun 08, 2011 10:01 am, edited 1 time in total.

User avatar
RobA
Posts: 335
Joined: Fri Aug 10, 2007 1:22 am

Re: How to move each group to a new created layer

Postby RobA » Thu May 26, 2011 6:52 am

Layers are (technically) groups in Inkscape.

You just need to add inkscape:groupmode="layer" attribute to each group <g> node.

Any language that can open an xml file and process it should be able to handle the task (outside of inkscape).

-Rob A>
Last edited by RobA on Wed Jun 01, 2011 2:10 am, edited 1 time in total.

User avatar
shawnhcorey
Posts: 149
Joined: Mon Jan 07, 2008 12:17 pm

Re: How to move each group to a new created layer

Postby shawnhcorey » Thu May 26, 2011 9:27 pm

RobA wrote:Layers are (technically) groups in Inkscape.

You just need to add <i>inkscape:groupmode="layer"</i> attribute to each group <g> node.


Beware of nested groups. You should only add the above to the outer-most groups. I don't know what Inkscape would do if it thought an inner group was a layer.

User avatar
RobA
Posts: 335
Joined: Fri Aug 10, 2007 1:22 am

Re: How to move each group to a new created layer

Postby RobA » Thu May 26, 2011 11:00 pm

shawnhcorey wrote:
RobA wrote:Layers are (technically) groups in Inkscape.

You just need to add <i>inkscape:groupmode="layer"</i> attribute to each group <g> node.


Beware of nested groups. You should only add the above to the outer-most groups. I don't know what Inkscape would do if it thought an inner group was a layer.


No problem. Inkscape supports sublayers (right from the layer dialog, insert a new layer before, after or as a sub-layer)

-Rob A>

User avatar
shawnhcorey
Posts: 149
Joined: Mon Jan 07, 2008 12:17 pm

Re: How to move each group to a new created layer

Postby shawnhcorey » Fri May 27, 2011 7:26 am

RobA wrote:No problem. Inkscape supports sublayers (right from the layer dialog, insert a new layer before, after or as a sub-layer)


Gee, you learn something new every day. Thanks.

amjahed
Posts: 5
Joined: Sat Apr 02, 2011 4:02 am

Re: How to move each group to a new created layer

Postby amjahed » Tue May 31, 2011 8:57 pm

RobA wrote:Layers are (technically) groups in Inkscape.

You just need to add <i>inkscape:groupmode="layer"</i> attribute to each group <g> node.

Any language that can open an xml file and process it should be able to handle the task (outside of inkscape).

-Rob A>

Thanks ! Happy to find a solution easier than I expected.
From your answer, I modify (with text editor) :

Code: Select all

    <g
      id="g3771">

To :

Code: Select all

    <g
       inkscape:label="Layer-1"
       inkscape:groupmode="layer"
       id="g3771">

How to use the <i> attribute ?

User avatar
RobA
Posts: 335
Joined: Fri Aug 10, 2007 1:22 am

Re: How to move each group to a new created layer

Postby RobA » Wed Jun 01, 2011 2:12 am

Sorry - the <i> and </i> came because I posted from elsewhere and it didn't get converted to bbcode.

What you show is exactly what you need - you don;t even need the label line.

Here is one I did with search/replace in a text editor, each group in the original layer ended up as a sublayer of the original "Layer 1":
Image

-Rob A>

amjahed
Posts: 5
Joined: Sat Apr 02, 2011 4:02 am

Re: How to move each group to a new created layer

Postby amjahed » Wed Jun 01, 2011 9:03 am

Great :) , It's so easy to do.
I summarize (case of an SVG file that has one layer) :
1- Create groups
2- In a text editor, remove :

Code: Select all

  <g
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1"
     ... >

and the last

Code: Select all

  </g>

3- replace all :

Code: Select all

<g

with :

Code: Select all

<g inkscape:groupmode="layer"


See the two attached captures.
Thanks !


Return to “Programming”