Find In Layer Names Script

I’m trying to create a script derived from Find and Replace in Layer Name, where the function will just find glyphs with the string inserted, and create a new tab with the glyphs at the correct bracket layer.

I’m stuck at line 35… I’m not sure how to create a string with glyphs at the correct layer?

[Edit]: New version creates a new tab with the base master glyphs. Not the bracketed glyphs, it’s good enough anyway.

Here is some python code that should help. You probably have the editViewController already somewhere and Layer is the bracketed Layer that should show up.

Attributes = {“GSLayerIdAttrib” : Layer.layerId()}
textStorage = editViewController.graphicView().textStorage()
selectedRange = textStorage.selectedRange()
if selectedRange.length == 0:
selectedRange.length = 1
textStorage.willChangeValueForKey_(“text”)
textStorage.text.addAttributes_range_(Attributes, selectedRange)
textStorage.didChangeValueForKey_(“text”)

Thanks, but I don’t have a editViewController but am using

Since I'm trying to create a new tab instead of add to current tab?

Also, in this version, I am getting an error, any ideas?

that means that you need to remove the parenthesis at the end of a method call in line 19.

You get the editViewController like this:

editViewController = Doc.windowController().activeEditViewController()