Add an anchor



  • Simple question, how the heck do I add an anchor? (in python)



  • Thanks!


  • admin

    see http://docs.python.org/library/pprint.html

    import pprint
    
    data = [["nested Item1", "nested Item2", "nested Item3", "nested Item4"], "item1", "item2"]
    pprint.pprint(data)
    

    good luck!



  • Well this is what I used (https://github.com/qkeave/Robofab-tools/blob/master/Radial Guides.py)

    PS. How do I enable PrettyPrint on my code?

    # Add Radial Guides - Quinn Keaveney
    
    g = CurrentGlyph()
    ancs = []
    gd = []
    
    for angle in range(0, 180, 15):
        gd.append("Radial {0}deg".format(angle))
    
    for a in g.anchors:
        b = a.name
        ancs.append(b)
        
    if 'Radial Guide' not in ancs:
        g.appendAnchor("Radial Guide", (500, 500))
    
    for a in g.guides:
        if a.name in gd:
            g.removeGuide(a)
    
    for a in g.anchors:
        if a.name == 'Radial Guide':
            x = a.x
            y = a.y
            for angle in range(0, 180, 15):
                g.addGuide((x, y), angle, name=("Radial {0}deg".format(angle)))
                guide = g.addGuide((x, y), angle, name=("Radial {0}deg".format(angle)))
                guide.naked().showMeasurements = True
    
    CurrentFont().update() 
    
    print ''
    print 'Digested by Python.'
    

  • admin

    mm, I cannot reproduce this bug

    sample script:

    glyph = CurrentGlyph()
    glyph.clearGuides()
    
    for a in glyph.anchors:
        for angle in range(0, 180, 15):
            guide = glyph.addGuide((a.x, a.y), angle)
            guide.naked().showMeasurements = True
    


  • Frederik, you are the man! I really appreciate the programming point.

    That being said I want to report a bug. >_<
    When you set the measurements via the scripting window it isn't reflected in the WYSIWYG editor, even after CurrentFont().update().



  • Sorry --> double post


  • admin

    and from a programming point of view it is maybe better to use range(start, end, steps)

    # print out an angle between 0° and 360° in steps of 15
    for angle in range(0, 360, 15):
        print angle
    

  • admin

    As measurements are a UI related attribute, it is not added to the robofab-like guide object.

    However you can change the display of measurements of a guide with:

    glyph = CurrentGlyph()
    
    guide = glyph.addGuide((100, 100), 90, "my guide")
    guide.naked().showMeasurements = True
    

    to remove all guides you can also use glyph.clearGuides()

    good luck!



  • thanks Thom that works,

    now I just need to figure how to turn on measurements with python



  • try this:

    g.removeGuide(a)
    


  • Thanks and sorry! I'm probably not as good at searching as I thought I was.
    BUT, this of course leads to more questions.

    • How do I set guides to measure
    • How do I ACTUALLY remove guides (because I can't get removeGuide() to work)

    I've attached the little tool I'm making below for context.

    g = CurrentGlyph()
    ancs = []
    gd = ['Radial 0deg','Radial 20deg','Radial 40deg','Radial 60deg','Radial 80deg','Radial 100deg','Radial 120deg','Radial 150deg','Radial 160deg']
    
    for a in g.anchors:
        b = a.name
        ancs.append(b)
        
    if 'Radial Guide' not in ancs:
        g.appendAnchor("Radial Guide", (500, 500))
    
    for a in g.guides:
        if a.name in gd:
            #THIS IS WHERE I WANT TO REMOVE THE GUIDE
            #removeGuide(a)
        
    print g.guides
    
    for a in g.anchors:
        if a.name == 'Radial Guide':
            x = a.x
            y = a.y
            g.addGuide((x, y), 90, name="Radial 0deg")
            g.addGuide((x, y), 110, name="Radial 20deg")
            g.addGuide((x, y), 130, name="Radial 40deg")
            g.addGuide((x, y), 150, name="Radial 60deg")
            g.addGuide((x, y), 170, name="Radial 80deg")
            g.addGuide((x, y), 190, name="Radial 100deg")
            g.addGuide((x, y), 210, name="Radial 120deg")
            g.addGuide((x, y), 230, name="Radial 150deg")
            g.addGuide((x, y), 250, name="Radial 160deg")
            #I JUST NEED TO SET THESE TO MEASURE
    
    print ''
    print 'Digested by Python.'
    


  • thank you!


  • admin

    g = CurrentGlyph()
    g.appendAnchor("name", (100, 100))
    

    see also http://www.robofab.org/objects/glyph.html

    good luck