Double click on path stop working after running

Hi there!

I found that I can’t double-click to select an outline after running my script. Here is what it does:

In the current editing glyph:

  • copy outlines + components to a new layer
  • in the new layer, deletes all paths with direction==1

After running, I can’t select paths by double-clicking in that particular glyph.
Any guess on what could the problem be?
Thanks!

Can you show the actual script? It is probably a problem with the .parent property of the paths.

Thanks for the quick response!
Here is the whole thing:

font = Glyphs.font
allGlyphs = font.glyphs
selectedLayer = font.selectedLayers[0] # get active layer

def findBracketLayer(targetLayerName):
	#print "-- targetLayerName",targetLayerName
	global targetLayer
	targetLayer=None
	for layer in selectedGlyph.layers:
		if layer.name == targetLayerName:
			targetLayer = layer
			
def clearLayer(myLayer):
	print "- clearing:",myLayer
	for p in myLayer.paths:
		myLayer.paths = []
	for c in myLayer.components:
		myLayer.removeComponent_(c)
	for a in myLayer.anchors:
		del myLayer.anchors[a.name]
					
def copy2bracket(sourceLayer,targetLayer):
	targetLayer.paths = sourceLayer.paths
	targetLayer.width = sourceLayer.width
	targetLayer.anchors = sourceLayer.anchors
	targetLayer.components = sourceLayer.components
	
def removeReversed(myLayer):
	pathIndex=0
	for path in myLayer.paths:
		isCounter=False
		if path.direction == 1:
			isCounter=True
		if isCounter==True:
			del(myLayer.paths[pathIndex])
		if isCounter==False:
			pathIndex+=1 # only when leaving the contour

def meltCounters(selectedGlyph):
	for m in font.masters:
		print selectedGlyph.layers[m.name]
		sourceLayer = selectedGlyph.layers[m.name]
		targetLayerName = sourceLayer.name+" [750]"
		findBracketLayer(targetLayerName) # Find the bracketLayer that matches your master
		print "- targetLayer:",targetLayer
		
		if targetLayer==None: 
			print "No target layer!!"
		else:
			if len(sourceLayer.paths) > 0: # Only continues if your master is NOT empty
				clearLayer(targetLayer) # Remove all paths in bracketLayer
				copy2bracket(sourceLayer,targetLayer) # Copy from master to bracketLayer
				if len(targetLayer.paths) > 0:
					removeReversed(targetLayer)

for selectedGlyph in font.selection:
	print "------", selectedGlyph
	meltCounters(selectedGlyph)

Thanks!

You can’t just assign the paths to another layer.

You need to copy them first:

import copy

targetLayer.paths = copy.copy(sourceLayer.paths)
1 Like

That fixed it. Thanks for the help! :slight_smile:

Good idea, I didn’t know about the copy library. My enhancement:

from copy import copy
targetLayer.paths = copy(sourceLayer.paths)

Avoids the copy.copy() structure.

What is the advantage of using the copy library instead of the built in method copy() for things like paths?

Calling copy() on a path should not copy the paths. You need a deepCopy() for that.

Using the copy module is more pythonic. The copy() method comes from the objectiveC side.

Good to know, thanks!