Best way to get a bPoint given an identifier?

  • Is this the best way to get a bPoint object given an identifier? Or is there a built-in method that's more succinct? I can find getIdentifierForPoint but essentially I need the opposite.

    bpt = [b for c in g.contours for b in c.bPoints if b.getIdentifier() == "12345678AB"][0]

  • admin

    hi @colinmford,

    as far as I know there’s no built-in method for this…

    I see some issues with your approach:

    1. if there’s no bPoint with the given identifier, you’ll get an IndexError (list is empty)
    2. identifiers are unique, but the loop will continue even after the bPoint is found (not necessary)
    3. using getIdentifier() will generate an identifier for bPoints which don’t have any (not necessary)

    so, I think something like this would be better:

    g = CurrentGlyph()
    ID = 'yDLmPFci12'
    bptForID = None
    for c in g:
        for b in c.bPoints:
            if b.identifier == ID:
                bptForID = b

    hope this makes sense! cc @frederik @benkiel

  • Really substantive answer, @gferreira! Thanks!