How to create new NetClass using python

How to create new NetClass using python and how to add track width and via properties into it. I know some of the steps:

ds = pcb.GetDesignSettings()
netclass = ds.GetNetClasses()

after this how to add new netclass and its properties.
Your Response will be appreciated.
Thanks and Regards
Pooja Sharma

I’m assuming you use kicad v6 since you didn’t specify version.

Use Netclasses.Add() method to add a NETCLASSPTR object

Hello Sir,

Is there a way to assign netclass to a particular net using python ?


But this is getting into the weeds of pcbnew internals. When you change things like this from python sometimes saving the board in pcbnew wipes out your changes. This is fine if you never intend the board to be edited in pcbnew.

What is your end goal?

Actually what i am doing is auto-routing, so it takes rules from dsn file of the board.
Before creating dsn file I have to assign new nets (which should have different trace widths) and i have to assign some netclass to them so that the rules will get freeze while creating dsn.

What auto-router is doing, new nets gets the netclass “DEFAULT”, and autorouter create thin traces according to Default setting. I want to use thick trace for that assigned nets inturn assign netclass to particular net.

Makes sense, I’m assuming the board is generated by script too, otherwise you would have assigned net classes in schematic editor.

In this case using the method I linked above should be fine.

Ok , I got it.
lets say “3.3V” is a net which I have added in board using python. And there is net class name “Power” in board.

ds = pcb.GetDesignSettings()
nc = ds.GetNetClasses()
np = nc.NetClasses()
p = np.items()[0][1] # Power Net class
o = p.NetNames()

Now, 3.3V will have net class name “Power”

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