I would like to create a plugin that can operate on the currently selected item in the PCBNew window. For this purpose, I’d like to understand how a plugin would get the selected item(s) from the API.
For example, I would like to implement something that can quickly set the justification of a footprint text. Like one might with a button or hotkey in Excel or Word.
So the user would select the item, say the footprint’s Value field on the Fab layer, and run this plugin to apply FP_TEXT.SetHorizJustify() accordingly. (One would need three plugins, for left, right and center.)
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.
Is there some more direct way for the plugin to find the selected text?
I realize that implementing features like I described also runs into the problem of how the user activates the plugin conveniently, given that currently there’s no way to tie a hotkey to a plugin. However, Streamdeck. And I guess if desperate I could have Streamdeck open the item’s edit dialog, and tab its way to the Justification combo box etc.
But in general I’d like to know the plugin way to operate on the selected footprint(s), texts and so on. And maybe at some point Kicad will offer hotkeys for plugins to complete the picture.
@albin A couple of those tools are indeed plugins that operate on the selection. And they find the selection by iterating all the relevant items on the board.
@qu1ck I too looked through the API and didn’t find anything obvious. The example plugins I saw indeed iterated over items, but generally were looking for footprints, whereas in my case my plugin would be visiting all the footprints and inspecting the subsidiary Reference(), Value() and GraphicalItems(), so possibly 10 or more times as many items. But perhaps that goes fast enough to be tractable.
@Jarrett Thanks for the example. Indeed yes I could enable a toolbar button for each plugin. Sadly there doesn’t appear to be a way to connect a hotkey to that button.
On a tangential note:
I discovered that PCBNew allows you to multi-select individual texts of several footprints, using Shift-Click. So for example just the F.Fab Value field of R1 and R2 and R3.
This does not allow you to open the edit dialog and adjust the justification, height etc of all at once. However I guess it’s useful for positioning, and Align and Distribute functions (not to be confused with justification). And will also work for a justification plugin.
Given that we are close to V7 release, you should check whether any of new functionalities about to be introduced solves your issue (2022 End-of-year Recap! - YouTube)
I used to have a plugin for V5 that calculated and showed track lengths for specific nets (in order to do length tuning for a bus) and then V6 introduced Net inspector making my plugin redundant. Kicad is developing quite rapidly with and discoverability of new features takes time especially since most web references (videos, …) lag behind.
Thanks for pointing out the Edit Text and Graphic Properties dialog.
I’m all in favor of being able to bulk-edit properties, including justification. However in this instance, I need to be able to set justification for individual footprint texts, or possibly a few that are nearby to each other.
I’m experimenting with adding additional information fields (on different layers) to footprints, and to avoid positioning them all by hand, I am using the position, direction, layer (F.Fab, B.Fab), height and justification of the Fab layer item FOOTPRINT.Value() as a guide. So once the Fab Values are positioned by hand, a script can position, size and orient my additional fields accordingly.
Justification is significant here because at many locations on the board, one end of the Value string abuts a component, while there’s open space on the other end. My added strings may be a bit longer than the Value string and can extend into that open space.
I’m also curious. Why the necessity for justification?
My normal practice is to drop the grid down to 1 mil. when the board is mostly finished, then push the text for the footprints to nearby, suitable, vacant real estate. Everything done with left finger mouse and zooming.
Edit: justification at this level is also available in 6.x.x.
@jmk FWIW, I described my current use case a few messages ago.
And yes, there are several ways to adjust footprint text justification etc, and more in K7. But all require opening a dialog, or at least moving the mouse, (eg: K7 to the properties panel) finding the desired item, clicking something or manipulating a combo box. The improving GUI is great for discoverability, but slow for a lot of changes.
By contrast, I’m hoping to get to the point of just selecting the item, and then a single button press on the keyboard or Stream Deck to make the change, here being left/center/right justify.
Related faster-UI improvements, I think still awaited, are:
IMO it would still be useful to have chained shortcuts/hotkeys, for example if A runs a plugin, it could be followed by B which would do action X while A followed by C would do action Y. This way it would be possible to write and install one plugin with several small functions, instead of writing and installing, say, 10 or 20 plugins for small tasks.
Simple Plugin is adequate for what you want to do. Complex plugin is primarily for plugins needing resources/files that are called by the plugin but, it’s mostly to keep things unconfused as all that can be done by Simple plugin.
Regarding ‘finding the selected item’ well, pretty simple, just point to where to look, so to speak and what to look for.
You can have Pop-Up GUI panels for ‘Input’ and for displaying output…
Below shows my Simple Plugin that has Pop-up panel with Buttons that call Def’s in the plugin and call external App’s (this one shows a button for calling an SQL Database for Proj Mgmt…