Add an anchor

RoboFont Forums Help / General Add an anchor

This topic contains 13 replies, has 3 voices, and was last updated by  qkeave 6 years, 9 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #5732

    qkeave
    Participant

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

    #5733

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

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

    good luck

    #5736

    qkeave
    Participant

    thank you!

    #5737

    qkeave
    Participant

    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.'
    
    #5738

    Thom
    Participant

    try this:

    g.removeGuide(a)
    #5740

    qkeave
    Participant

    thanks Thom that works,

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

    #5752

    frederik
    Keymaster

    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!

    #5753

    frederik
    Keymaster

    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
    
    #5754

    qkeave
    Participant

    Sorry –> double post

    Attachments:
    You must be logged in to view attached files.
    #5756

    qkeave
    Participant

    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().

    Attachments:
    You must be logged in to view attached files.
    #5758

    frederik
    Keymaster

    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
    
    #5763

    qkeave
    Participant

    Well this is what I used (https://github.com/qkeave/Robofab-tools/blob/master/Radial%20Guides.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.'
    
    #5767

    frederik
    Keymaster

    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!

    #5770

    qkeave
    Participant

    Thanks!

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.