Where in the pcbnew object model do we get access to the position, size, visibility, orientation etc of the various texts associated with a footprint (aka “module”)? That includes the Reference, Value, and Properties (user-added to a symbol instance in EESchema).
I have a basic Action Plugin working which can iterate board.footprints(), use GetReference(), GetFPIDAsString, GetValue() and GetProperties() and write these to a text file.
However, these are all basically strings, and don’t include attributes for the text’s position, size etc. I can’t find where those attributes are stored, and how they are associated with the footprints.
With footprint.GraphicalItems() you can get all footprint drawing items (inckuding text). You can get only text items by filtering them with if type(item) is pcbnew.FP_TEXT:. Then you can get position and orientation of the text with GetPosition() and GetTextAngle(). But IIRC the position is relative to the center of the footprint so you have to account for this if you want to get absolute position. And I forgot how is with the orientation. And finally you have to be careful if the footprint is flipped.
Thanks MitjaN and @qu1ck, that got me going on the right track.
However one oddity – I noticed that the FP_TEXT items returned by footprint.Reference() and Value() do not appear in the GraphicalItems collection. Though there is a ${REFERENCE} FP_TEXT in GraphicalItems, but this is the one on the Fab layer, as opposed to Reference, which is the one on the Silkscreen layer.
Yeah, that’s by design. Value and Reference are madatory properties of footprint. Everything extra is added to GraphicalItems. Reference on fab layer is also extra.
Yeah, your’re right. I got tripped (again) by the “Keep upright” text option. If checked and footprint only slightly tilted in the right way, the text looks upside down. So that is why I thought my plugins failed to position text.
With Keep upright
Without Keep upright
Anyhow, this is how I acctually get footprint ext items (including Reference and Value):
def get_footprint_text_items(footprint):
list_of_items = [footprint.Reference(), footprint.Value()]
footprint_items = footprint.GraphicalItems()
for item in footprint_items:
if type(item) is pcbnew.FP_TEXT:
list_of_items.append(item)
return list_of_items