Kicad Python bindings: Proper way to create or copy FP_TEXT to add to FOOTPRINT?

Thanks again for your suggestions @qu1ck and @MitjaN. Still no success, but more clues:

Recap: In all cases the goal is to get a FOOTPRINT’s added FP_TEXT and FP_SHAPE items to display visually in PCBNew’s layout view, following running the External Plugin. In general:

  • The various modifications I tried do appear immediately in each component’s Properties dialog.
  • I tried many combinations of enabling/disabling layers and the Refresh function, with no impact.
  • Saving the board, and reloading it into PCBNew causes the changes to display as expected.

New observations:

  1. In the layout window, when one or more components are selected, PCBNew displays more layers and changes some texts to white (as a way of highlighting them). For a modified part, that causes the added FP_TEXTs to display (in white). They disappear again on deselecting the component.

  2. I tried removing and re-adding the modified footprint, as you guys suggested, but that did not prompt PCBNew to show the modifications.

  3. Same, but with a time.sleep(5) between Remove and Add (thinking that maybe there was some event that needed to happen). No improvement.

  4. I previously noted that changing the layer of one of the required FP_TEXTs (Value) does get updated in the layout view. So maybe the problem concerns the “non-required” items accessible only via footprint.GraphicalItems()? But…

  5. Library footprints come with a “non-required” FP_TEXT “$(REFERENCE)” for the RefId in the F.Fab layer. That’s accessible via GraphicalItems(). Using the plugin to change the layer of that item becomes visible immediately. So it’s not the GraphicalItems() membership per se that’s the issue.

  6. Thinking that maybe Duplicate was the key factor, I tried creating a FP_TEXT from scratch (not fully knowing how many attributes I would need to set for a working new FP_TEXT):

            newitem = pcbnew.FP_TEXT(fp)
            newitem.SetText("TestTest")
            newitem.SetPosition(fp_refid_posn)
            newitem.SetLayer(layer_for_annot)
            newitem.SetVisible(True)
            fp.Add(newitem)

Once again, this new FP_TEXT does not become visible in the layout window, but as with the previous cases, the text does appear when the component is selected (and disappears on deselect) and also appears in the component’s Properties dialog, and if the board is saved and reloaded, the new FP_TEXT is now visible.

Tentative conclusion

In fp.Add-ing new or duplicated FP_xxx’s, there seems to be some per-FP_xxx flag that’s not getting set, or some list that the new FP_xxx’s are not getting added to. Apparently saving and reloading works around that problem. But it sure would be nice to get this to work live!

1 Like