Scripting, how to use GetProperties() and SetProperties()

In order to save a few custom settings on the layout file, I am trying to use the Python call to GetProperties() and SetProperties().

props = board.GetProperties()
dummy = props['dummy']
props['dummy'] = 'Another value'
board.SetProperties(props)
board.Save(board.GetFileName())

As excepted, this writes the property to the .kicad_pcb file, which is great. However if the users decides to later save the file using the UI, it reverts any changes made using the script.
Does anyone has a clue how to “apply” the changes made by the script to the UI?

Cheers,
Patrick

You can’t, saving from the UI drops all custom properties. It’s probably a bug but I don’t know if these properties are intended to be used like this.

Let me briefly elaborate on the actual problem I am trying to solve. Maybe there is another solution. Our Push for KiCad plugin (https://github.com/AislerHQ/PushForKiCad) should keep the Project ID of our service on the drawing itself. This is later used to add new revisions to the project instead of creating a new project.
As @qu1ck already explained, GetProperties() and SetProperties() is reset on save. Because of this I decided to use the comment section on the drawing frame to keep the Project ID. The beauty of this solution is, that it is directly visible on the drawing and thus everyone knows about the corresponding project.


Of course the plugin first checks if the comment line is already used.

This functionality is provided by

board = pcbnew.GetBoard()
title_block = board.GetTitleBlock()
# and 
title_block.SetComment('This is a comment')
board.SetTitleBlock(title_block)

This works fine on macOS and Windows however on Linux (Ubuntu on my test system) it completely resets the title block including the title itself.
Does anyone know about this limitation? Or is it rather a bug? Or is there another solution I could try?

Looking forward,
Patrick

There shouldn’t be platform differences in scripting like you describe. It’s more likely that you used different versions of kicad in your tests or maybe if you were doing manual testing there was human error.

Your code looks fine and definitely should not reset the title block. If you can reproduce this, report it on gitlab.

1 Like

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