Hello Stefano,
Here is an example that might help:
def setWorkPlane():
plane1 = Plane.CreateByNormalAndOrigin(view.ViewDirection, view.Origin)
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
sp = SketchPlane.Create(doc,plane1)
doc.ActiveView.SketchPlane = sp
TransactionManager.Instance.TransactionTaskDone()
return "Work plane changed"
By the way, here is how you can paste and format the code in this forum: