Data structure with ids

pm.tr.setNodeType(...).apply() should do it. Make sure you only call that when necessary, of course, so that you don’t end up in an infinite recursive event cycle.