Set Work Plane

I tried to do this, but it gives me some problems… do you have any suggestion for me?

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

#unwrap all elements to use with API
bubbleEnd = UnwrapElement(IN[0]).ToRevitType()
freeEnd = UnwrapElement(IN[1]).ToRevitType()
cutVector = UnwrapElement(IN[2]).ToRevitType()
pView = UnwrapElement(doc.ActiveView.ToDSType(True))

TransactionManager.Instance.EnsureInTransaction(doc)
#apply lineweight override to elements in an input list
typelist = list()

rPlane = doc.Create.NewReferencePlane(bubbleEnd,freeEnd,cutVector,pView)
# "End" the transaction
TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable

def SetWorkPlane():
		
		newRefPlane = UnwrapElement(rPlane)

		TransactionManager.Instance.EnsureInTransaction(doc)
		sp = SketchPlane.Create(doc,newRefPlane)
		doc.ActiveView.SketchPlane = sp
		TransactionManager.Instance.TransactionTaskDone()

		return "Work plane changed"
		
		
newWorkPlane = 	SetWorkPlane()
		

OUT = newWorkPlane