Using connectAllOpenPaths()


#1

Hi, I’m trying to use the layer.connectAllOpenPaths() and nothing is actually happening, nor is there an error message in the Macro Panel.
Selecting by hand my paths and right clicking Close Open Paths in the context menu does work.

What am I missing?
Thanks!

code snippet: (just last line doesn’t do anything)

addToLayer = NSMutableArray.array()

for path in thisLayer.paths:
	newPath = GSPath()
	newPath = path.copy()
	addToLayer.append(newPath)
	for node in newPath.nodes:
		node.x += shiftX
		node.y += shiftY

for path in addToLayer:
	thisLayer.addPath_(path)

for path in thisLayer.paths:
	path.selected = True

thisLayer.connectAllOpenPaths()

#2

Maybe you could use this:

for path in thisLayer.paths:
    path.setClosed_(True)

But for me connectAllOpenPaths is also not doing anything.


#3

That function is for connecting open path ends that are already on top of each other, like in this case:
47


#4

Thanks!

Are both functions the same? -
Close Open Paths and layer.connectAllOpenPaths()?


#5

No. One closes open paths, the other reconnects open path ends with identical coordinates.


#6

Oh, in that case I have 2 questions:

  1. Is there a way to access via script the ‘Close Open Paths’?
  2. thisLayer.connectAllOpenPaths() still does nothing in my code, for instance on these nodes:
    Is there another import I should include or am I calling it wrong?


#7

The open pieces seem to be double and overlap the normal outline. Can you double click next the the curve and Cmd+Arrow right move the selection? I suspect that it is a full outline and some unneeded pieces will be left.


#8

Sadly- none found :frowning:
Also- is seems to work as one unit, shifting all together nicely.
just not actually closing. (nor is thisLayer.correctPathDirection() doing anything- thought that might help…)

Is there somewhere (couldn’t find) I can see how it’s done in OffsetCurve filter? Although the filter itself doesn’t answer what I need exactly, maybe it’s close?


#9

I think this might be due to adding a path manually and maybe doing it wrong?

connectingPaths = NSMutableArray.array()

for path in thisLayer.paths:

	# create a two-point path with the first nodes:
	connectingPath1 = GSPath()
	n1 = newPath.nodes[0]
	n2 = path.nodes[0]
	connectingPath1.addNode_(n1)
	connectingPath1.addNode_(n2)
	# add the path to the layer
	connectingPaths.append(connectingPath1)

	for path in connectingPaths:
		thisLayer.addPath_(path)

#10

Why are you doing this? Who does the path look before you do this?


#11

The main objective is to create a version of BoradNibber for Hebrew glyphs.
In Hebrew the contrast is in an opposite direction to the one found in Latin glyphs, and BroadNibber can’t seem to handle that (tried originally to tweak the open code for that).
After some rounds of coding, I decided to try and code it myself (mainly- not using the OffsetCurve Filter, which seems to be the main problem for the flipped contrast).

Attached are two screenshots:

  1. prior to creating the path, connecting the first and last nodes (just duplicated and shifted the original)
  2. after creating the path from the 2 nodes, prior to trying to draw the path (as in the snippet above). This has an effect on the lower nodes some how, they look a bit off.

#12

It seems that the copying or the reversing of the paths was not done correctly. You see the strange direction of the end node indicators (the blue line and the arrow)?

Can you show the full code? Do you have it on GitHub already?


#13

You can change the angle in Broadnibber.


#14

Yes, tried that as a starting point, and it still didn’t work properly- the output looked off in a Hebrew context.
Also tried to change the rotation matrix (worked better, not enough though)

Not on git yet, but I can DM it to you shortly.

Thanks!


#15

Can you post a screenshot of the layer before you run the script?


#16

This is the original path:

This is the outcome of running the script of copying the path, without creating the connecting paths the first and last nodes (just duplicated and shifted the original)

The funny arrows you noted only appear after creating the connecting paths (even without adding them to the layer paths yet, just declaring and initializing them)

Thanks!


#17

I send you a “fixed” version of your script via DM. It is much simpler then you think :wink:


#18

Oh my… that was simple…

I’m pasting here two notes that I think were helpful, for future searches on how to add nodes to a path

so instead of :
connectingPath1.addNode(n2) and then connectingPaths.append(connectingPath1)

here the solution Georg suggested was using python’s list.extened() :
path.nodes.extend(newPath.nodes)

also - if a path is copied and you with to connect it to the original - it should be reversed - newPath.reverse()

Thank you so so much.