How to create a new netclasse by python? [scripting]

if you add this line:

std::shared_ptr<NETCLASS>(std::string name)  { return new std::shared_ptr<NETCLASS>(new NETCLASS(name)); }

to pcbnew/swig/netclass.i and recompile/install you can do this:

import pcbnew
board = pcbnew.GetBoard()
ds = board.GetDesignSettings()
# ugly. exposes a public member not via an accessor method
nc = ds.m_NetClasses  
foo = pcbnew.NETCLASSPTR("foo")
nc.Add(foo)

and you’ll have a new netclass named foo in the design rules.

I’ll submit this change to the kicad folks. I haven’t decided yet whether to try to add an access function for m_NetClasses, so it may take some time. Probably not though. the real way to improve things is probably to develop a set of wrapper classes to make the python interface make more logical.

2 Likes