Ultra-simple plugin creation for layout

Hi, I would like to create a plugin or script that toggle the visibility of the reference of the currently selected module when a specific hotkey is hit.

At first glance, it should be around 10 lines long.

Although the plugin creation process seems to be very complicated.
I may have missed some trivial documentation.
is there an “hello world” example plugin somewhere ?
can someone give me a link for this kind of simple example ?

Unfortunately it’s not possible to bind a hotkey to a plugin.

There is some basic documentation in the pcb editor manual, but it’s only in the “nightly” (future v8) version of the docs. It should all be valid for 7.0 as well, but some of the examples might have to change slightly because the API is not very stable. I only tested the examples in the nightlies.

Maybe this will help…

#1
You can Toggle the Visibility by a ‘Click’ once setting up the Visibility. It will Toggle All items having been similarly set. (see video)

#2
There is No Hot-Key ability for Plugins. However, a Plugin can be run from a Single-Click of it’s Icon. If the plugin only does some action without needing to select something, it will happen. That part is all about your plugin-design-code.

#3
Plenty of documentation on making plugins (there are two types: Simple and Complex). Do some Searching on this Forum, YouTube, Internet (and read Kicad’s plugin documentation)

That said, you can see how to create a Simple Plugin from this (my YouTube video) and the only difference (between that plugin and what you want to do) will be the actions defined in the “def Run(self):”

Your homework is:
• Watch the video and read it’s info and click & read the “…more” content
• Create the Plugin (from video) with these Edits:

  • Leave the “board = GetBoard()” [line 19)
  • Delete Lines 20 thru 28
  • Delete “str(total),”

• you could leave ‘total’ and set a dumb value eg, 1234. And, not delete the “str(total),”

Success will result in:
• an Icon showing up in PCB top MenuBar
• Clicking the Icon will pop-up a Messge-Panel diaplaying 'total’s value…)

I can’t say exactly where to place the .py because platforms are different as are Kicad versions… thus, some homework on you part…

[ADDED: this will Not contain a Meta file and will Not be an Official Plugin - thus, will need to be placed in the proper location for your System and kicad-version, thus, the homework (generally, in the Scripting/Plugins folder]

1 Like

There are “hello world” examples here PCB Python Bindings | Developer Documentation | KiCad

But like said above, you can’t bind action plugins to hotkeys.

Hi guys, thanks for your answers.
As it seems that custom action cannot be bound to a hotkey, I decided to use external tools and especially xdotool to emulate key press.

Although inelegant, it’s really efficient.

I used my window manager to trigger this script when F7 is pressed

#!/bin/bash

#small start delay
sleep 0.1

#edit current module
xdotool key "e"
sleep 0.1

#switch focus to the "visible" checkbox of Reference
xdotool key "Tab"
sleep 0.1

#turn visibility off
xdotool key "KP_Subtract"
sleep 0.1

#validate button
xdotool key "Alt_R+v"

select component, hit F7, and it does what i want in less than a second.

but it would be nice if this kind of macro could be integrated into the editor.

2 Likes

I prefer your solution. It’s more flexible and customizable. Once something like this gets integrated, it gets “stuck” with a particular behavior that may or may not be “improved” at a yearly cadence.