Reporter plugin: Transform BezierPath

I’m trying to write a reporter plugin that displays a glyph in another glyph with both right sidebearings aligned. Like this:


I have gotten as far as showing the reference glyph but it’s always aligned with the left sidebearing I and I can’t figure out how to shift it over the right amount (currentGlyph.width - referenceGlyph.width) for each glyph it’s displayed in. I tried messing around with the NSAffineTransform methods but I don’t know how to implement it correctly. Here is my plugin.py code:
from GlyphsApp.plugins import *
from Foundation import NSPoint

class ____PluginClassName____(ReporterPlugin):
		
	def settings(self):
		self.menuName = 'RSB Aligned Glyph'
		
	def background(self, layer):
		Glyph = layer.parent
		Font = Glyph.parent
		rsbGlyph = Font.glyphs['_rsbGlyph'].layers[0]
		thisGlyphWidth = layer.width
		rsbGlyphWidth = rsbGlyph.width
		shift = thisGlyphWidth - rsbGlyphWidth
		NSColor.colorWithCalibratedRed_green_blue_alpha_(0.0, 0.6, 1.0, 0.4).set()
		rsbGlyph.drawBezierPath.fill()

This is my first attempt at writing a plugin. I’ve tried to read as much documentaion as possible but I’m just not getting it. I’dI really appreciate any help on this.
Thanks!

You forgot the image?

You need to build an NSAffineTransform and transform the paths with it.

sorry posted by accident. Edited now

There is a transform snippet that helps you write that code:

thanks for that. However, I still don’t understand how to apply the transformation. The “t” in Layer.transform_checkForSelection_doComponents_(t,False,True) is not defined or I don’t know what it is supposed to be referring to. I’ve tried to deconstruct other plugins that use NSAffineTransform but it isn’t clear to me how it all goes together. Does the transformation get applied before or after the outlines are drawn? Does the transformation need to act on a layer, paths or nodes? I feel like I just need a simple example but I haven’t been able to find one.
Sorry, I’ve been trying my best to figure it out. Thanks for any help you can give me.

It is an NSAffineTransform object, which is explained in the 2nd line of the comment:

Returns an NSAffineTransform object for transforming layers.
Apply an NSAffineTransform t object like this:
	Layer.transform_checkForSelection_doComponents_(t,False,True)
Access its transformation matrix like this:
	tMatrix = t.transformStruct() # returns the 6-float tuple
Apply the matrix tuple like this:
	Layer.applyTransform(tMatrix)
	Component.applyTransform(tMatrix)
	Path.applyTransform(tMatrix)
Chain multiple NSAffineTransform objects t1, t2 like this:
	t1.appendTransform_(t2)