Can I align all nodes to their nearest grid intersections?

Post questions on how to use or achieve an effect in Inkscape.
anon13
Posts: 32
Joined: Thu Dec 05, 2013 6:59 am

Can I align all nodes to their nearest grid intersections?

Postby anon13 » Thu Feb 26, 2015 7:59 am

I've drawn a pattern using only the grid lines but I seem to have accidentally dragged a few of the shapes so their nodes no longer rest on the gridlines. Of course I can manually check every shape and the nodes but there are a lot of them, so what I was wondering is: is there any way to make all selected shapes snap their nodes to the closest grid intersections?

In the attachment, all the blue filled boxes are aligned to the grid, but the orange filled boxes have been nudged so their nodes are no longer on the grid intersections. At the moment I would have to manually check and drag each node of every corner back which takes a while and sometimes the misalignment is so small that it's easily missed.
Attachments
nodes not on grid example for forum.svg
(6.52 KiB) Downloaded 213 times

tylerdurden
Posts: 2337
Joined: Sun Apr 14, 2013 12:04 pm
Location: Michigan, USA

Re: Can I align all nodes to their nearest grid intersection

Postby tylerdurden » Thu Feb 26, 2015 8:31 am

I don't know about of any automation to correct position, but to easily see the alignment, I'd use Menu: View>Display Mode>Outline.
Have a nice day.

I'm using Inkscape 0.92.2 (5c3e80d, 2017-08-06), 64 bit win8.1

The Inkscape manual has lots of helpful info! http://tavmjong.free.fr/INKSCAPE/MANUAL/html/

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

Re: Can I align all nodes to their nearest grid intersection

Postby brynn » Thu Feb 26, 2015 10:53 am

I feel your pain!. I've recently been locking layers much more than I ever used to, because of having this problem so often!

That must only be part of the image, because it would just take 5 minutes or less, to fix that whole file. Have you learned about Snapping? If you set up your snapping control bar in the right way, it will be just several quick mouse movements to fix those.

On the snap tool control bar, in addition to the buttons you already have engaged, press: Snap cusp nodes. Now grab each square with the Selection tool, and drag it towards the node where you want it to be aligned. You'll notice when the "snap" happens, because the square will sort of jump when it gets close, and you'll see a little text to confirm that the snap happened, and which parts were snapped.

As you gain more experience with snapping, there are some other controls that will make it even better, and easier to control. Note the manual info: http://tavmjong.free.fr/INKSCAPE/MANUAL ... pping.html

anon13
Posts: 32
Joined: Thu Dec 05, 2013 6:59 am

Re: Can I align all nodes to their nearest grid intersection

Postby anon13 » Thu Feb 26, 2015 11:35 am

tylerdurden: thank you for replying. That outline mode is cool and useful, thank you (:
brynn: I should have explained the attachment better, I'm sorry: that was just a simple example I created to help explain the situation. The actual patterns tend to be much much bigger and the current one even has overlapping semi-transparent shapes which makes things harder, especially if edges overlap so errors can easily be hidden and missed.
I never really thought about all those extra snapping buttons so that's really helpful, thank you and for the link too (:
I always use grids and snapping when drawing my patterns but the problem arises if I'm not careful enough in the copying and pasting (rather than drawing everything 6 or 8 times) or just careless mouse clicking without the grid on etc. So, is the answer to just be more careful then?!

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

Re: Can I align all nodes to their nearest grid intersection

Postby brynn » Thu Feb 26, 2015 12:10 pm

Well yes, I guess that would be what we're left with. But there are tools like layers, locking, hiding, which cleverly used, can help prevent this problem. Also grouping, or sometimes combining, depending on the circumstances. And if this is a repeating pattern, you might be able to work out tiled clones -- that would allow you to make the entire pattern, in one click.

Unfortunately, in my experience, by the time I figure out the Symmetry and Shift tabs, I could have manually created the pattern 5 or 6 times. I wish they would make those Shift units in anything but percent! That's what takes so much time for me, is calculating the percent shift.

For using Layers, typically I will have the original pattern in a separate layer. Duplicate a unit, whatever that is. That whole set you provided in the attachment could be a unit, for example. Anyway, try this routine:

-- have the original unit on one layer, and create a 2nd layer, where the pattern will be stored -- keep that layer hidden, you might not necessarily need to see it -- but if you do need to see it, be sure to lock it, so you can't accidentally mess it up
-- Duplicate the unit, and move it directly to the other layer (Shift + PgUp or Pg Dn) (assuming it's correctly placed already)
-- Duplicate again, and move that unit into place, in the same layer with the original -- when it's in place, move it to the pattern layer -- be sure that it's properly in place before you move to the other layer
-- repeat until finished -- now you will have a perfect pattern on the hidden or locked layer, as long as your original placement is correct
-- the first thing you should do, when you unlock that layer, is Group everything (Ctrl A to select all)

Good luck :D

anon13
Posts: 32
Joined: Thu Dec 05, 2013 6:59 am

Re: Can I align all nodes to their nearest grid intersection

Postby anon13 » Thu Feb 26, 2015 1:55 pm

I really wanted there to be some clever code or trick or extension but ah well!!
I've tried cloning a little before but the procces felt long and tricky; maybe I'll have to put in a bit of practice and see if it can make drawing any quicker, though I agree about the percentage annoyance. And I'm not sure how it would work with my patterns (see attachment if you're interested, or ignore it if you're not; I don't mind either way).
Thank you for the effort you put in to typing up that routine. I think I understand it but I'm not sure how pratical it would be for me since I go back and edit things alot, change my mind, change it back etc.
Attachments
quick pattern example for forum.svg
(34.42 KiB) Downloaded 214 times
Inkscape 0.91 / Windows 7 / 64bit

Lazur
Posts: 4713
Joined: Tue Jun 14, 2016 10:38 am

Re: Can I align all nodes to their nearest grid intersection

Postby Lazur » Thu Feb 26, 2015 10:16 pm

Pixelsnap extension is just about to solve that problem -fitting nodes to the pixel grid.
A bit of scaling may be necessary, but it should work.

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

Re: Can I align all nodes to their nearest grid intersection

Postby brynn » Fri Feb 27, 2015 9:56 am

That might work, if his grid is a pixel grid. If his grid some other custom arrangement, pixelsnap might not align the nodes to his grid.

anon13
Posts: 32
Joined: Thu Dec 05, 2013 6:59 am

Re: Can I align all nodes to their nearest grid intersection

Postby anon13 » Mon May 18, 2015 1:39 am

Lazur: Pixelsnap looks handy, but unfortunately, like Brynn said, I don't draw on a pixel grid. Usually I set the grid like graph paper, so 1mm squares. What do you mean by a bit of scaling though?

Sorry for not replying sooner.
Inkscape 0.91 / Windows 7 / 64bit

Lazur
Posts: 4713
Joined: Tue Jun 14, 2016 10:38 am

Re: Can I align all nodes to their nearest grid intersection

Postby Lazur » Mon May 18, 2015 2:50 am

You draw with 1 mm scale, which is 3,543307087 px at the 90 dpi inkscape uses.
By scaling your drawing 25,4/90, your grid will be fit in size for pixel snapping.


Besides that maybe the extension can be edited to work with mm grid.

anon13
Posts: 32
Joined: Thu Dec 05, 2013 6:59 am

Re: Can I align all nodes to their nearest grid intersection

Postby anon13 » Mon May 18, 2015 3:01 am

That's a lot of pixels!
I don't understand the 225,4/90", sorry.
So what happens if I then want to enlarge it again to keep drawing?

That would be amazing if it could.....
Inkscape 0.91 / Windows 7 / 64bit

Lazur
Posts: 4713
Joined: Tue Jun 14, 2016 10:38 am

Re: Can I align all nodes to their nearest grid intersection

Postby Lazur » Mon May 18, 2015 3:20 am

1 inch = 25,4 mm = 90 pixels @ 90 dpi.

Like, if you draw a rectangle 1 mm in width, then switch the unit to px, it will be 3,543 pixels, exactly 90/25,4 times "larger".

Actually you don't even need to count the right size, just switch between the units and type in the right value, displayed with the previous unit.
In practice, you can draw a large rectangle covering your work, move it to bottom (End), group all objects together and resize the rectangle only would keep high accuracy.
For example, if you draw a 1000 mm / 1000 mm square, by switching to px, it will be 3543,307 px / 3543,307 px. If you then type in 1000 px / 1000 px, the scale will be right for pixelsnap.

anon13
Posts: 32
Joined: Thu Dec 05, 2013 6:59 am

Re: Can I align all nodes to their nearest grid intersection

Postby anon13 » Mon May 18, 2015 3:54 am

Ohhh, I saw the comma in "3,543307087" and forgot that it's used in place of a fullstop so interpreted it as "3,543,307,087"; what a numpty mistake!!
I tried that on a small scale and it's not a good suggestion and method, thank you. But either I'm doing something wrong or being too picky because after resizing back up again, I forced a node (which I had nudged to not be on the grid which then, after running pixelsnap, appeared to be back on the grid) to snap and the co-ordinates had changed slightly. So it appears to work but but not as accurately as I would like.....
Inkscape 0.91 / Windows 7 / 64bit

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

Re: Can I align all nodes to their nearest grid intersection

Postby brynn » Mon May 18, 2015 9:54 am

If I understand, you originally worked with a 1 x 1 mm grid? Except those nodes that somehow missed the grid, was everything else snapped to the mm grid? I had the impression that you weren't using snapping originally, and just using the mm grid....I guess you could say "informally"....or just as a visual guide, rather than the precision that snapping provides.

Anyway, if the nodes were not precisely aligned to the mm grid intersections, then even if you scale it, use pixelsnap extension, and then scale back, it will not put the nodes in their original places.

Lazur's technique should work beautifully, if you were using snapping on the mm grid.

That's an nice idea, btw, to expand the pixelsnap extension to a "grid snap" extension, that will snap to a grid of any size units! I think pixelsnap was orignally created, at least partly to help with images destined for the internet (although it has other uses as well). But auto snapping to any grid could also be useful!

anon13
Posts: 32
Joined: Thu Dec 05, 2013 6:59 am

Re: Can I align all nodes to their nearest grid intersection

Postby anon13 » Mon May 18, 2015 11:28 am

That is correct. The nodes don't miss the grid, unless I've purposely turned off snapping, which is usually when I manage to accidentally nudge objects and so then they aren't accurately placed on the grid intersections anymore. For the purpose of trying Lazur's technique, I drew two shapes (with snapping on); I left one accurately drawn and then nudged the other slightly for comparison. When zoomed out they both looked to be snapped but upon zooming in and forcing the nudged nodes to snap, the co-ordinates (at least, bizarrely, for the y-axis) changed, meaning that they hadn't quite made it back to the grid intersections. I hope that makes sense.
I always thought that it would be too hard to do so never made a suggestion but since seeing pixelsnap, I've got my hopes up again! How would someone go about making it a reality?
Inkscape 0.91 / Windows 7 / 64bit

Lazur
Posts: 4713
Joined: Tue Jun 14, 2016 10:38 am

Re: Can I align all nodes to their nearest grid intersection

Postby Lazur » Mon May 18, 2015 8:32 pm

Tried the pixelsnap way and I do see it's not working exactly as it supposed. Not sure why, it doesn't snap all the nodes to grid intersections.
Maybe there is/should be a bug report at launchpad?
https://bugs.launchpad.net/inkscape/

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

Re: Can I align all nodes to their nearest grid intersection

Postby brynn » Mon May 18, 2015 9:24 pm

No, I've never found it to snap ALL nodes to grid interesections. And I'm not sure it's supposed to....because that would alter or distort the object.

It would be interesting to find out about that, but I don't have time to investigate, myself (not right now, anyway).

anon13
Posts: 32
Joined: Thu Dec 05, 2013 6:59 am

Re: Can I align all nodes to their nearest grid intersection

Postby anon13 » Tue May 19, 2015 12:46 am

Lazur: Did it do the same for you in snapping the nodes on the x-axis but not the y-axis?
The search for 'pixelsnap' only returned one result, which wasn't relevant. But I've never searched for or reported a bug before so I'm probably not be the best person to do so.
brynn: so if it doesn't snap all nodes, how does it decide which ones to snap and which to leave?
That's a shame, but I hope everything that is keeping you busy is going well (:
Inkscape 0.91 / Windows 7 / 64bit

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

Re: Can I align all nodes to their nearest grid intersection

Postby brynn » Tue May 19, 2015 1:16 am

I always thought the main purpose of pixelsnap was to make objects or images clearer on the internet. If you draw a bunch of perfectly vertical or horizontal lines, all the same width, and look closely, you will see that they don't all appear to be the same width. But if you have them aligned to whole pixel values, the appear to be correct. The best I could tell by experimenting with Pixelsnap is that it tries to align left- or right-most, or top- or bottom-mode node to a whole pixel value.

Let me make up a sample file.....

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

Re: Can I align all nodes to their nearest grid intersection

Postby brynn » Tue May 19, 2015 2:00 am

Ok, so attached are 2 files. 1 SVG file, so you can download and look at, if you like, and a PNG, to see the effect that I'm seeing on my screen.

pixelsnap.png
pixelsnap.png (3.36 KiB) Viewed 5224 times


pixelsnap.svg
(7.58 KiB) Downloaded 169 times


On the left are 6 vertical 1 px wide stroked paths. On the right is just a duplicate! But you can see the one set looks wider than the other. For some reason, having the paths aligned to whole pixel values fixes the display.

Now here's the confusing part. At first you might think that the set on the left is not aligned to a whole pixel, while the one on the right is. But it's just the opposite. I think the reason is because when the nodes are aligned to the whole pixel, and the stroke is 1 px wide, then the left and right edges of the stroke actually lie at n.500 pixel values. If the set of lines is shifted by 0.5 px, then while the nodes lie on n.5 px value, the left/right edges lie on the whole pixel value.

Also, I tested the Pixelsnap extension on the set of lines. In this case, it doesn't make any difference from the set on the right. It's just the same. However, I noticed that the extension has some new info in the dialog for 0.91, that I had not seen before. I guess it explains a little bit about how it works. It does seem to imply that all nodes should be affected. ("....snaps borders to half-points and fill to whole points") But I guess it doesn't specifically say that.

I can't explain what causes this effect, or why having the nodes and/or paths aligned in this certain way, fixes it. I don't think I've ever heard or read an explanation. But it's probably something to do with the nature of pixels and the raster display (that most computer screens use).

Having different stroke widths, or viewing those 6 lines at different zoom levels, or shifting some lines by odd (not whole) pixel values will have different effects on this phenomenon. Lately, I have not experimented with the extension, to figure out how it handles different stroke widths, different shaped objects, etc. I'm sure I could learn more by doing so. But for now, unfortunately, I have other priorities. However, I don't think the extension is malfunctioning. Anyone could search the bug tracker https://bugs.launchpad.net/inkscape .....although I guess extension issues are not handled in the bug tracker. Probably better to contact the person who wrote the extension....or maybe can learn something from it's webpage (https://code.google.com/p/pixelsnap/).

anon13
Posts: 32
Joined: Thu Dec 05, 2013 6:59 am

Re: Can I align all nodes to their nearest grid intersection

Postby anon13 » Tue May 19, 2015 2:48 am

Very confusing indeed! Though the picture and your clear explanation definitely helped, thank you. So which version would you say is more correct/accurate then; having the nodes aligned to the whole or half pixel?
So the extension did make a difference to the left one by moving the lines on to the half pixel (like the right set already was)?
You're probably right, and I bet the effect is highly annoying to some; I'm just glad that it doesn't seem to matter with the sorts of projects I do!
Sounds like a lot of variables. I agree; I probably just need to learn about how it functions rather than expecting it to do one thing and thinking there's an error when it doesn't. I'm not that bothered about snapping to pixels, to be honest, but maybe I'll get in contact and see if it's a possibility to scale the extension to snap to mm grid.
So, I guess I'll just have to try and be super careful when snapping is off to prevent any nudges that I'd have to manually fix.
Inkscape 0.91 / Windows 7 / 64bit

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

Re: Can I align all nodes to their nearest grid intersection

Postby brynn » Tue May 19, 2015 4:48 am

So which version would you say is more correct/accurate then;...

The set of lines on the right is the one that's displayed more correctly. But that could all go out the window, if you start changing things -- like the width of the strokes, or the spacing of the lines, or the DPI if you decided to export, or really, just about anything. I haven't found pixelsnap can solve a lot of different problems. But in certain cases, it can be very helpful.

I wouldn't have thought of it at all for your problem, since I already had an idea that pixelsnap doesn't snap every node. But it still was a clever idea.

Yes, as long as you use snapping to the mm grid, you should be fine. Duplicate shapes and just drag to snap to the proper corner nodes. And especially if you have 1 shape with a node that doesn't align to the grid, as long as you duplicate an existing one, and there's at least 1 node at a grid intersection, you won't have to ever disable snapping, unless you have to draw a brand new piece with a non-snapping node.

Those look like interesting designs, btw. What will they be used for?

anon13
Posts: 32
Joined: Thu Dec 05, 2013 6:59 am

Re: Can I align all nodes to their nearest grid intersection

Postby anon13 » Tue May 19, 2015 6:32 am

Correction: sounds like an large, vast lot of variables!
It really doesn't make sense why pixelsnap doesn't snap every node, but I suppose there must be some reason or logic it in.
I wouldn't draw without snapping, at least not for the sort of things I 'draw' usually. As long as the shape I'm duplicating doesn't have an unsnapped node! I guess I need a better workflow and to check the shape before I duplicate to make sure that doesn't happen, or else the problem easily becomes much bigger.

The first attachment was just a quick example to make a point but I think the project that caused this post looked like:
screenshot922.png
screenshot922.png (154.42 KiB) Viewed 5191 times
and the problem was that the shapes were transparent enough that when they weren't in the correct place, the overlapping stroke paths appeared thicker than they should. Oh and it was used for a tshirt.

As for the second attachment, that's just an example doodled 'maze' thing and for no particular purpose really. It started with the squares in maths books and then evolved onto smaller graph paper (though this one was done on the computer):
screenshot923.png
screenshot923.png (5.9 KiB) Viewed 5191 times
Inkscape 0.91 / Windows 7 / 64bit

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

Re: Can I align all nodes to their nearest grid intersection

Postby brynn » Wed May 20, 2015 4:07 pm

I love geometric designs like that. For the 2nd one, I would be tempted to start coloring in the little shapes. Actually I might be inspired to do something like that myself! Especially after learning about XIA (viewtopic.php?f=11&t=18416), I was thinking of making a maze type of game.

anon13
Posts: 32
Joined: Thu Dec 05, 2013 6:59 am

Re: Can I align all nodes to their nearest grid intersection

Postby anon13 » Sat May 23, 2015 3:48 am

I have attempted to colour them in in the past but I didn't spend enough time learning what colours go best because they often ended up looking quite childish when I tried so I gave up! I'd be interested to see how you coloured them in though. You should; it's fun! I had a look at that post, but I was mostly very confused, sorry.
Sidenote; I tried to post a topic on the pixelsnap google group the other day but either it didn't go through, or it needs to be verified first etc, so no progress on scaling it up to snap to mm grid at the moment.
Inkscape 0.91 / Windows 7 / 64bit


Return to “Help with using Inkscape”

Who is online

Users browsing this forum: No registered users and 6 guests