Subtract paths in G3

It seems that the path subtract code no longer works in G2. I had something like this before:

PathOperator = GSPathOperator.alloc().init()
PathOperator.subtractPaths_from_error_(Erasers, Paths, None)

I was looking around for a replacement like GSPathOperations and GSSubtract but couldn’t make sense of either of them. How do you do it in G3?

That subtract method is a class method now. So you don’t need to allocate the pathOperator but call the method on the class. (I’m not at the Mac right now, but it should be something like this:

GSPathOperator.subtractPaths_from_error_(Erasers, Paths, None)

Thanks. It looks like the way to initiate Paths and Erasers have also changed?

    Erasers = NSMutableArray.alloc().init()
	Erasers.append( eraserPath )
	Paths = layer.pyobjc_instanceMethods.paths()

At least the Paths line seems to give me an error. When I try layer.shapes for a path, or [s for s in layer.shapes if type(s) == GSPath], the path operator doesn’t subtract.

Nudging the topic. Could anyone help me with this?

You need to use layer.shapes or build a new NSMutableArray as an argument for the GSPathOperator methods.
Layer.paths and Layer.components are proxies that can only be used to iterate only those objects.

Thanks, do you mean like this? It didn’t do anything.

Erasers = NSMutableArray.alloc().init()
Erasers.append(layer.shapes[0])
Paths = NSMutableArray.alloc().init()
Paths.append(layer.shapes[1])
GSPathOperator.subtractPaths_from_error_(Erasers, Paths, None)

Yes.

Hmm, like I said, the result is exactly the same as before I run the code.

The subtracted path is in the Paths. You might need to put that back into the layer. What are you trying to do?

Ah that’s where it was! I’ve finally got the resulting shape. Thanks!

My goal here is to update my scripts to G3, and this subtract paths is one of the obscure changes. I didn’t have to extract the resulting paths before, so it’s a new change, right?

While I am on the topic of boolean operations, from some version G3’s remove overlap behaviour has changed; if the original outline had an outside loop, Remove Overlap doesn’t remove them.

In Glyphs 2, you might have used the layer.paths directly.