Help with quick python script!

Hi everyone,

I'm in need of  help, I'm using Flab 6-7 and need to automatically set the starting point in several glyphs and their masters.
There is an option in "contours"–"set starting point" but if i have to do it one by one I'll take forever.

Does anyone have a script for this?
Do scripts actually work in Flab 6-7? I had several crashes
Thank you!
Tagged:

Comments

  • Found a way to do it without a script!!!

    Either way, if anyone can tell me if there is a python for typography course I would be thankful.
  • Don't know how to call FL SetStartPoint function from script, but you can try this:
    import fontlab as fl
    import math
    
    
    for glyph in fl.CurrentFont().glyphs:
        for layer in fl.flGlyph(glyph).layers:
            for contour in layer.getContours():
                bbox = contour.boundingBox()
                dist = lambda pt: math.sqrt(
                    (bbox.x() - pt.x) ** 2 + (bbox.y() - pt.y) ** 2
                )
                nodes = [
                    (index, node)
                    for index, node in enumerate(contour.nodes())
                    if node.type == "on"
                ]
                start_index = sorted(
                    [(index, dist(node)) for index, node in nodes],
                    key=lambda _: _[1],
                )[0][0]
                if start_index != 0:
                    contour.setStartPoint(start_index)
    fl.CurrentFont().update()

  • @Fernando Díaz there is one, by Roberto Arista, which is (I think) the course version of this.
  • @Fernando Díaz What you are looking for is among the many functions of TypeRig, the script/add-on that is sufficiently powerful that the FontLab folks made it an optional install in the app, in FontLab 7.

    I have become highly dependent on TypeRig for a number of things.

    From the FL7 release notes:

    The Scripts menu has a Update / Install Scripts command. Click it to install some useful Python packages as well as TypeRig, a monumental Python extension for FontLab 7 developed independently by Vassil Kateliev. TypeRig brings some example Python scripts as well as TypeRig GUI, a large panel that lets you perform various batch operations. When you run Update / Install Scripts for the first time, you will need to restart FontLab 7 two or three times. Run the command once every few weeks to update TypeRig. Note: This functionality is experimental.