Generate node overlap with python?


I'm not very good with robofab, but I wanted to select a node and create another node on top.
Just in case I'm using fontlab 5 and have all the basic python plugins installed.

Thank you for your help!


  • (Actually, It would be duplicate nodes putting it in simple words).
  • Hi @Fernando Díaz,
    not completely sure why you would want to do this ;) but anyway maybe this helps -
    quick and dirty made out of an older RoboFab script for FL - It worked when I used the square selection (not directly selecting a node) see image - the other image for indentation - still not sure if this is what you need - good luck!!

    from import CurrentGlyph, CurrentFont

    g = CurrentGlyph()
    sel = []

    for contour in g.contours:
    for Point in contour.points:
    if Point.selected:

    if len(sel) != 0:
    xL = []
    yL = []
    #store up all coordinates for use later
    for Point in sel:
    x, y = Point.x, Point.y

    print sel, xL[0], yL[0]
    p = g.getPen()
    p.moveTo((xL[0], yL[0]))
    p.lineTo((xL[0], yL[0]))

  • Hey @Lukas Schneider thank you!

    But what I need is the node to be part of the contour, right now I get a separate node on the same place, it's close though. 

    I know it's very weird haha :)
  • Dyana WeissmanDyana Weissman Posts: 112
    edited January 2016
    Under Tools/Customize... you can enter your own key command for Duplicate Node. Alternatively, control-click on the node you want and Duplicate Node comes up in the pop-up menu. Still part of the contour. No need for a script. …Unless I am misunderstanding the context.
  • Hey Dyana,

    On my version of fontlab 5.0.4, there is no Duplicate Node in the customize menu. And you can do only 1 at a time. 

    Which version are you using?
  • Nina StössingerNina Stössinger Posts: 124
    edited January 2016
    Based on what Lukas wrote above, this seems a bit brutalist but something in this direction (probably with some refinements) might do the trick. Not tested more than ten minutes. Things get a bit weird with curve points.
    from import CurrentGlyph, CurrentFont

    g = CurrentGlyph()

    for contour in g.contours:
    for i in range(0, len(contour.bPoints)):
    point = contour.bPoints[i]
    if point.selected:
    # print i
    contour.insertBPoint(i+1, point.type, point.anchor, point.bcpIn, point.bcpOut)

  • It works Nina!

    Thank you for helping me in my madness
    PS: I love you work :)

  • I'd like the opposite of this script where sometimes a nice single node curve becomes two overlapping nodes that cannot be merged
  • Ahh, I have FL 5.1.2, but I haven't used it in years, in case you were thinking of upgrading. Glad that Nina solved the problem. 
  • I just bought the new version, but haven't installed it yet :) 
  • Vassil KatelievVassil Kateliev Posts: 41
    edited January 2016
    Why don't you use the Fontlab's native insert functionality as specified in Fontlab Unnoficial Guide:
    "... Insert (Node | Glyph | [Node]) | (Node | Glyph |  [Node], nodeindex) - inserts Node, Glyph or sequence of Nodes at the begining of glyph's nodes or at specified node index..."

    ...i think it is far simpler or you need to code to be RoboFab-ed? The following siple code will duplicate the node and insert a straight/line segment between the two nodes:

    from FL import *

    glyph = fl.glyph
    nodeIndex = 0

    while nodeIndex < len(glyph.nodes):
        if glyph[nodeIndex].selected:
            glyph.Insert(Node(nLINE, Point(glyph[nodeIndex].x, glyph[nodeIndex].y)), nodeIndex + 1)
        nodeIndex += 1

Sign In or Register to comment.