Is there a way to automatically select only extreme points?

Hello everyone,

I’m wondering if there’s a way to automatically select only extreme points?

There’s a built-in “add extremes” function so it seems the software can already determine if a point is an extreme or not.

The workflow I’m currently doing:

  1. Add extremes to an auto-traced letter
  2. Select all extreme points
  3. Reverse selection of nodes (via shift, in effect selecting non-extreme nodes)
  4. Use “Remove nodes and try to keep shape”

I’m finding that offset curve creates a lot of unnecessary points and weird artifacts to the original shape at times (which, this is probably because the original shape is auto-traced and has nodes all over the place) and am using this to clean up afterwards.

It would be great if there were a way to automate step #2 (if not the entire workflow).

Edit: Also, I’m not sure but I think that there still needs to be manual inspection after this step… what I’m really looking for is to select all “necessary” points to a shape and/or delete all “unnecessary” points to a shape.

Run this in the Macro panel:

for p in Layer.paths:
	delete_nodes = []
	for n in p.nodes:
		if n.type == "offcurve":
			continue
		current_pos = n.position
		prev_pos = n.prevNode.position
		next_pos = n.nextNode.position
		if current_pos.x == prev_pos.x == n.nextNode.x or current_pos.y == prev_pos.y == n.nextNode.y:
			n.selected = True
			# use the code up to here just for selecting extremes
			continue
		delete_nodes.append(n)
	# delete nodes that are not extremes:
	for n in delete_nodes:
		p.removeNodeCheckKeepShape_normalizeHandles_(n, True)

You can also, to some extent, use the Tidy Up Paths function. Fontlab’s was better, but it still works for strictly unnecessary points :wink:

1 Like

Thank you so much, SCarewe! I really appreciate your help and time!

To report back on results (for anyone else’s reference as well):

  1. I initially got some indent errors running macros because there is a space/tab discrepancy in the whitespace

  2. The node selection so far does seem to require some manual intervention (e.g. some necessary points such as angled corners aren’t selected, may not select necessary points within counters)

  3. Weirdly I am hitting a bug when running the macro as a selection (I have some frequently used code I like to keep in the window) and when I zoom, the glyph disappears, and then has issues after (becomes a ? in tab, may show other glyphs that have the same problem)

  4. But running the selection part of the code as the only snippet in the Macro window works very well with automating most of the work of selecting only “necessary points”!

A note: I’ve never found Tidy Up Paths very helpful in my workflow - it usually only gets rid of nearly-overlapping or overlapping nodes, adds some extra points, or sometimes does nothing.

But Glyphs is awesome and so is this community, so no shade!

Ha, sorry about that. That’s what happens if you try and write code inside the forum web inerface instead of a proper environment :sweat_smile: I fixed the indentation errors.

What do you mean with angled corners? I admit I haven’t tested my code, it is just supposed to catch extremes of curves. Do you want it to catch corners, too? That shouldn’t be a problem, if all other points are smooth curve nodes. Just add or if n.type is "line" before the colon at the end of the long line with all the ==.

About 3: You realise you can use multiple tabs in the Macro panel? You can simply open a new tab with the + button (bottom left).

1 Like

Mind = Blown
That’s what I get for never reading any instruction manuals…
I’m sure there’s other stuff I can do too, like add it to the scripts folder and or create short cuts, but one thing at a time!

image

To illustrate what I’m looking to achieve (which may be a fairly complex thing), I’m looking to select the minimal number of points necessary to convey the shape (i.e. how glyphs are supposed to be made, but… vector tracing is my friend) and get rid of all the unnecessary ones. So the script might catch 80% of what I need, but also sometimes also selects points that are superfluous.

From what I understand, it’s selecting only points that have a completely straight vertical or horizontal handles, right? Not quite what I’m trying to automate, but still helpful!

Ah, I see, that’s what you mean by extremes. In type design, extremes usually refer to vertical and horizontal extremes, as this is how paths are usually drawn.

Finding the nodes that are necessary to describe (within a certain accuracy) a curve is a lot more complex than what I wrote above. I don’t know black magic, that’s a question for a pro.

1 Like

Have a look at the Delete Short Segments and Clean Up Lines plugins by @mekkablue which may handle some of the cases you are dealing with.

The Magic Remover plugin allows you to select a bunch of nodes (the Lasso selection tool may be of assistance) and get rid of them all at once.

Personally, I find it easiest to select and single node and just Tab–Tab–Tab my way through the path and press Delete whenever I don’t need a node. That takes more time, but also offers more control over clean up result.

1 Like

Ah, yes, sorry about that, I’m not super sure of the terminology. I see, curves are tricky. You’ve been a great help though, so thank you!

Thank you for the tips! I have played around with some plugins, and I’ll take a look at those!

I do want to save some time/tedium but I didn’t know the Tab-Tab-Tab feature, that will come in handy as well!

Because cleaning up a traced path is so cumbersome, it is sometimes quicker to place the image in the glyph and draw the paths manually. There are some tutorials/videos about that on the website.

1 Like

Thanks, Georg! I have tried it both ways and they’re sometimes equally time consuming… perhaps I need to get better at plotting points. I’ll check out the tutorials!