SOLVED RComponent.position not working



  • Looking for a way to get the “absolute” coordinates of a component, I stumbled on RComponent.position in the documentation.

    But when I run this I get a trackback in both current beta and last release:

    Traceback (most recent call last):
      File "<untitled>", line 4, in <module>
      File "/Applications/RoboFont.app/Contents/Resources/lib/python3.7/fontParts/base/base.py", line 90, in __get__
      File "/Applications/RoboFont.app/Contents/Resources/lib/python3.7/fontParts/base/base.py", line 746, in _get_base_position
      File "/Applications/RoboFont.app/Contents/Resources/lib/python3.7/fontParts/base/base.py", line 758, in _get_position
    AttributeError: 'RComponent' object has no attribute 'x'
    

    I’m not sure if this is something that is not implemented (yet/anymore) or if I am using it wrongly.

    What would be the best way to figure out the position of a given component?

    Thanks for your help.


  • admin

    component.position will be removed in future version, as it was a bug :)



  • Ah, good to know. I haven’t seen that issue.

    Thanks for the snippet, that helps a lot!



  • hello @benedikt,

    this is a known bug in FontParts, see this issue.

    this seems to work:

    glyph = CurrentGlyph()
    component = glyph.components[1]
    bounds = component.layer[component.baseGlyph].bounds
    if bounds:
        x = bounds[0] + component.offset[0]
        y = bounds[1] + component.offset[1]
        print(x, y)
    

    thanks!