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.
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.
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.
now,
ds = pcb.GetDesignSettings()
nc = ds.GetNetClasses()
np = nc.NetClasses()
p = np.items()[0][1] # Power Net class
o = p.NetNames()
o.append(“3.3V”)
pcbnew.Refresh()