Clearing Glyph

RoboFont Forums Help / General Clearing Glyph

This topic contains 5 replies, has 3 voices, and was last updated by  frederik 6 years, 7 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #5810

    Jeremie
    Member

    Hello,

    I am trying to clear all contour data from a glyph’s layer (‘mask’).
    Because I could not find a removeGlyph() method, I am using removeSegment().
    I parse the glyph’s contours and the contours’s segments and delete the first segment.

    g = CurrentGlyph()
    	
    print g
    g.prepareUndo()
    mask = g.getLayer("mask")
    mask.prepareUndo()
    
    for c_index in range(len(mask)):
    	print 'contour:', c_index
    	for s_index in range(len(mask[c_index])):
    		print '--segment:', s_index
    		print mask[c_index][0].type
    		print len(mask[c_index])
    		mask[0].removeSegment(0)
    		mask.update()
    
    g.update()	
    

    But all I manage to do is to remove the first contour (contour 0), then I got an error:
    “list index out of range”

    Any help would be greatly appreciated :)

    #5811

    Jeremie
    Member

    Ok I’m sorry for this post, I found the way with clearContour()

    g = CurrentGlyph()
    
    mask = g.getLayer("mask")
    mask.prepareUndo()
    g.prepareUndo()
    
    mask.clearContours()
    mask.update()
    
    #5812

    frederik
    Keymaster

    also see the robofab docs

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

    and the super handy object map

    http://www.robofab.org/objects/model.html

    good luck

    #5817

    Jens K.
    Participant
    g = CurrentGlyph()
    m = g.getLayer("mask")
    m.clear()
    

    also works, but I don’t think it’s documented anywhere!? clear() also removes anchors and components.

    #5818

    Jeremie
    Member

    cool, thanks for that :)
    As I said to Frederik earlier, there is a lack of documentation at one place for all that…

    #5822

    frederik
    Keymaster

    an alternative option to get docs:

    f = CurrentFont()
    
    help(f)
    

    (this works for any object)

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

You must be logged in to reply to this topic.