-
Hi, i have another question. How do we assign a layer per page? The code below will create two layers. The first layer is called 'red shape' & the second layer is called 'yellow shape". But it creates both the layers on the first page, and the second page is empty. The result I would like to achieve is having the layer "red shape" on "red page" & the layer "yellow shape" on "yellow page" (...just to clarify, now both shapes are on the red page). Is there a way to make each layer on separate pages ? Or perhaps just to save the shapes directly into a page, instead to a layer? canvas.resize_by_name('A7') canvas.resize_by_name('A7') |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, but first let me explain the concept underlying layers and pages. That should make the coding step more understandable. Both layers and pages are Inkscape-specific concepts; they don't exist in plain SVG. A layer is implemented as an SVG group. Just like an ordinary group, its size is determined by its contents. The only difference between a layer and a group is that a layer contains a couple Inkscape-specific attributes: One corollary of the above is that a layer doesn't fundamentally exist on a particular page. It's merely a grouping of objects that may all lie on a single page or that may lie on different pages. A second corollary of the above is that placing an object on a particular page primarily is a matter of placing the object somewhere on the global canvas within the page's rectangular boundaries. That said, here's a small piece of code that centers a red circle on the "red" page and a yellow circle on the "yellow" page: canvas.resize_by_name('A7')
red_page = page('Red page')
rlft, rtop, rwd, rht = red_page.viewbox
red_circle = circle((rlft + rwd/2, rtop + rht/2), 50, fill='red', stroke_width=4)
yellow_page = page('Yellow page')
ylft, ytop, ywd, yht = yellow_page.viewbox
yellow_circle = circle((ylft + ywd/2, ytop + yht/2), 50, fill='yellow', stroke_width=4) Notice how I use the page's It's easy enough to put each shape in its own layer, but remember that there's no formal association between layers and pages: canvas.resize_by_name('A7')
red_page = page('Red page')
rlft, rtop, rwd, rht = red_page.viewbox
red_circle = circle((rlft + rwd/2, rtop + rht/2), 50, fill='red', stroke_width=4)
red_layer = layer('Red layer')
red_layer.append(red_circle)
yellow_page = page('Yellow page')
ylft, ytop, ywd, yht = yellow_page.viewbox
yellow_circle = circle((ylft + ywd/2, ytop + yht/2), 50, fill='yellow', stroke_width=4)
yellow_layer = layer('Yellow layer')
yellow_layer.append(yellow_circle) I hope that helps you achieve what you want with your actual code. |
Beta Was this translation helpful? Give feedback.
Yes, but first let me explain the concept underlying layers and pages. That should make the coding step more understandable.
Both layers and pages are Inkscape-specific concepts; they don't exist in plain SVG. A layer is implemented as an SVG group. Just like an ordinary group, its size is determined by its contents. The only difference between a layer and a group is that a layer contains a couple Inkscape-specific attributes:
inkscape:groupmode
to indicate that the group should be interpreted as a layer andinkscape:label
to specify the layer's name. A page…