Python bindings - how to find item selected in the PCBNew layout window

Chained shortcuts

I suspect if Kicad had a mechanism for hotkeys to run plugins, then the first keystroke could invoke a plugin that pops up a small UI, which, having the focus, would then capture the second keystroke. That effect might be good enough.

Though we don’t have hotkeys for plugins, I might give this scheme a try in conjunction with Stream Deck, to create the effect of the initial “hotkey to run plugin”, then followed by another key. The user could key this second key on the keyboard, or it could be a subsequent step in the Stream Deck macro.

Well a single plugin python file can register multiple plugins. So from the point of view of managing the code, that avoids a proliferation of files. However, it still creates a proliferation of items on the Tools > External Plugins menu.

I am on the lookout for how to create subsidiary menu folders on the Tools > External Plugins menu, but haven’t seen how to do that. I thought that “complex plugin” might do that, but haven’t yet tried it. “complex” might just be for organizing a multi-python-file plugin as a python module (ie: subsidiary directory with __init__.py file). I’ll get to this at some point soon, but comments welcome on The Way to create Tools > External Plugins > MyManyFunctions folder.

If you’re a programmer (from Noob to Expert) you’ll glean the answers from image below. It contains Three “where to look’s” and “actions to perform”. That’s what I mean in terms of code…

Your best approach IMO is to look at several of the Plugins that come with Kicad and look at some that are posted online - there are common threads running through them…

The actual Action they take isn’t too important, what is important is that they refer to something (‘point to it’ so to speak) and then they ‘do something’ to or with something…

You indicated you want to

That is not supported by kicad at the moment.

@BlackCoffee your code snippets are missing some items (value and reference texts of footprint are not included in GraphicalItems() result). I’ve added an API to get selected items to kicad, merge request link above (not merged yet).

I’m not clear on what you’re saying but, doesn’t matter. All of my Plugins work verrrry well. Never a problem. I did Not intend to post full code details…

What I mean is that if a footprint’s reference is selected your code snippet will not work, i.e. will think nothing is selected. Same with value text. Maybe it’s fine for your use case but gwideman was asking how to get all selected items and your code doesn’t do that.

You’re correct, it doesn’t do that - and, I did Not intend to show how to do that. My intent was to show how to get selected items from something code is pointing to (drawing, mod, pcb…). Whether or not the API/whatever contains specific abilities/features is up to a User to discover.

I figure that if I tell someone what I’m holding is a Dollar-Bill, they should know it contains 100 pennies, two 50cents, 4 quaters… so to speak. And, if curious, they can discover how to combine other coins to make it a Dollar’s worth…

ADDED: And, in the image I posted several posts above, I show a Resulting Panel of items that are listed for a File I point to… that item being pointed to can be the PCB, any file…
Exampe below reads contents of PCB file…

That’s my approach…

@BlackCoffee You would have saved yourself a lot of typing if you had just read the original post:

I see that EDA_ITEMs (like FP_TEXT) have a IsSelected field. But I am hoping that iterating every single text of every footprint is not the way to discover which item is selected.

You just elaborated for us exactly the method that most conspicuously appears in the API, that I already described, and the avoiding of which was the point of my post.

And having said that, the recursive iteration solution doesn’t in any sense start with “point to where to look”. It starts with no idea where to look. So as a substitute, it looks exhaustively “everywhere”, and eventually finds all the items upon which to act.

My post acknowledges that we have a dollar consisting of 100 pennies, and the discussion is how to trade it in for single dollar bill.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.