# Set Work Plane

**URL:** <https://forum.dynamobim.com/t/set-work-plane/8775>\
**Category:** Developers\
**Tags:** python\
**Created:** [January 11, 2017, 9:02am UTC](https://forum.dynamobim.com/t/set-work-plane/8775 "2017-01-11T09:02:19Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![ste\_camp](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@ste\_camp](https://forum.dynamobim.com/u/ste_camp)\
**Post date:** [January 11, 2017, 9:02am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/1 "2017-01-11T09:02:19Z")

</div>

Hi everyone,  
I’m trying to set automatically the work plane from dynamo. I found this method in Revit API [http://www.revitapidocs.com/2017/44adcf08-cbba-6338-5c4f-d70cc78b447a.htm](http://www.revitapidocs.com/2017/44adcf08-cbba-6338-5c4f-d70cc78b447a.htm)  
I’m not so good with Python… could anyone help me to solve it?

Thanks!

---

<div class="post-metadata">

**Author:** ![Yna\_Db](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/yna_db/32/30641_2.png) [@Yna\_Db](https://forum.dynamobim.com/u/Yna_Db)\
**Post date:** [January 11, 2017, 9:13am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/2 "2017-01-11T09:13:51Z")

</div>

Hello, are you asking someone to do something you cannot do yourself, or do you rather have any document that you need to improve with some help?

---

<div class="post-metadata">

**Author:** ![ste\_camp](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@ste\_camp](https://forum.dynamobim.com/u/ste_camp)\
**Post date:** [January 11, 2017, 9:15am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/3 "2017-01-11T09:15:37Z")

</div>

actually, I’m asking to do something I cannot do 😅

---

<div class="post-metadata">

**Author:** ![Yna\_Db](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/yna_db/32/30641_2.png) [@Yna\_Db](https://forum.dynamobim.com/u/Yna_Db)\
**Post date:** [January 11, 2017, 9:17am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/4 "2017-01-11T09:17:00Z")

</div>

So please read this first:

> [@How to get help on the Dynamo forums](https://forum.dynamobim.com/t/how-to-get-help-on-the-dynamo-forums/4677):
>
> One of the main goals of the Dynamo community is to help others. One way to do that is by answering your questions. But to get the right answer, you’ll first have to ask your question in the right way. Although people are generally very helpful, there are things you can do to improve your chances of getting good and quick answers. Below you will find some suggestions on how to achieve that. Do not think of these suggestions as rules and especially do not take them as a guarantee of getting an an…

---

<div class="post-metadata">

**Author:** ![ste\_camp](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@ste\_camp](https://forum.dynamobim.com/u/ste_camp)\
**Post date:** [January 11, 2017, 9:28am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/5 "2017-01-11T09:28:59Z")

</div>

I cannot go further than this

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/a/aa2b6da67869c9f1c801779e99c59256884753c9.PNG)

---

<div class="post-metadata">

**Author:** ![Einar\_Raknes](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/einar_raknes/32/8566_2.png) [@Einar\_Raknes](https://forum.dynamobim.com/u/Einar_Raknes)\
**Post date:** [January 11, 2017, 9:56am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/6 "2017-01-11T09:56:14Z")

</div>

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:

> [@How to get help on the Dynamo forums](https://forum.dynamobim.com/t/how-to-get-help-on-the-dynamo-forums/4677/10):
>
> Whenever you need help with a python script, be sure to paste the code into your post, mark it and press the \</\> button: [image]

---

<div class="post-metadata">

**Author:** ![ste\_camp](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@ste\_camp](https://forum.dynamobim.com/u/ste_camp)\
**Post date:** [January 11, 2017, 10:11am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/7 "2017-01-11T10:11:26Z")

</div>

> [@Einar\_Raknes](#):
>
> ```
> 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"
> 
> ```

Hi Einar, thanks so much for your reply. I try to explain better what I’m trying to do: I created a new reference plane in Revit with Dynamo using some points and planes… now I’m tying to set automatically from dynamo the plane that I created without entering in Revit and using the “Set Work Plane” tool.

I tried to use the set plane method that I found in revit API but I cannot solve it.  
Now I tried to use your solution but I’m doing something wrong because it’s not working…

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/c/5cd53ed29de19a9ac8ece4f1a85181004a482b41.PNG)\<img

---

<div class="post-metadata">

**Author:** ![ste\_camp](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@ste\_camp](https://forum.dynamobim.com/u/ste_camp)\
**Post date:** [January 11, 2017, 10:12am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/8 "2017-01-11T10:12:00Z")

</div>

src="//cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex022/uploads/dynamobim/original/3X/4/c/4c2a01e192804f74c5f1b8119bde3c0f84ed254c.PNG" width=“690” height=“186”\>

---

<div class="post-metadata">

**Author:** ![ste\_camp](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@ste\_camp](https://forum.dynamobim.com/u/ste_camp)\
**Post date:** [January 11, 2017, 10:12am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/9 "2017-01-11T10:12:40Z")

</div>

![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/8/c84c97c30f8e610e0e141159180c1f9b23728679.PNG)

---

<div class="post-metadata">

**Author:** ![ste\_camp](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@ste\_camp](https://forum.dynamobim.com/u/ste_camp)\
**Post date:** [January 11, 2017, 10:13am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/10 "2017-01-11T10:13:22Z")

</div>

![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/8/68cf549e875ab8c74c95a26ba1bb375338f0b2ad.PNG)

---

<div class="post-metadata">

**Author:** ![ste\_camp](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@ste\_camp](https://forum.dynamobim.com/u/ste_camp)\
**Post date:** [January 11, 2017, 10:30am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/11 "2017-01-11T10:30:26Z")

</div>

probably this image is a little bit more clear

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/e/4eb7c782319bcd46e65aa9f62110e82ffc121102.PNG)

---

<div class="post-metadata">

**Author:** ![Einar\_Raknes](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/einar_raknes/32/8566_2.png) [@Einar\_Raknes](https://forum.dynamobim.com/u/Einar_Raknes)\
**Post date:** [January 11, 2017, 11:42am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/12 "2017-01-11T11:42:12Z")

</div>

A couple of things:

- In python `def` means that a function is defined. Nothing will happen before you call the function.
- I think you need to convert the reference plane to a sketch plane before it can be used to set the workplane.

---

<div class="post-metadata">

**Author:** ![ste\_camp](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@ste\_camp](https://forum.dynamobim.com/u/ste_camp)\
**Post date:** [January 11, 2017, 5:33pm UTC](https://forum.dynamobim.com/t/set-work-plane/8775/13 "2017-01-11T17:33:03Z")

</div>

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

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/c/2c097b164e1e23982324a01a3631106a8791f75d.PNG)

```
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
```

---

<div class="post-metadata">

**Author:** ![Einar\_Raknes](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/einar_raknes/32/8566_2.png) [@Einar\_Raknes](https://forum.dynamobim.com/u/Einar_Raknes)\
**Post date:** [January 11, 2017, 7:18pm UTC](https://forum.dynamobim.com/t/set-work-plane/8775/14 "2017-01-11T19:18:32Z")

</div>

You are getting closer. Take a look at this link to get a better understanding of element wrapping and geometry conversion: [https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration#revitapi](https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration#revitapi)

Here is an updated script that might work, if I have guessed the correct input types of your graph.

```
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 elements and convert geometry from Dynamo to Revit:
# Read more here: https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration#revitapi
bubbleEnd = IN[0].ToPoint()
freeEnd = IN[1].ToPoint()
cutVector = IN[2].ToVector()
pView = doc.ActiveView

# Create the reference plane in a transaction
TransactionManager.Instance.EnsureInTransaction(doc)
rPlane = doc.Create.NewReferencePlane(bubbleEnd,freeEnd,cutVector,pView)
TransactionManager.Instance.TransactionTaskDone()

# Set the reference plane as the sketchplane in the active view in another transaction
TransactionManager.Instance.EnsureInTransaction(doc)
sp = SketchPlane.Create(doc,rPlane.Id)
doc.ActiveView.SketchPlane = sp
TransactionManager.Instance.TransactionTaskDone()

OUT = rPlane
```

---

<div class="post-metadata">

**Author:** ![ste\_camp](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@ste\_camp](https://forum.dynamobim.com/u/ste_camp)\
**Post date:** [January 12, 2017, 8:35am UTC](https://forum.dynamobim.com/t/set-work-plane/8775/15 "2017-01-12T08:35:32Z")

</div>

Thanks Einar, I watched the link, I made some changes to your code and now work perfecly! Thank you so much!!  
here is the final code that I created

```
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 elements and convert geometry from Dynamo to Revit:

bubbleEnd = UnwrapElement(IN[0]).ToRevitType()
freeEnd = UnwrapElement(IN[1]).ToRevitType()
cutVector = UnwrapElement(IN[2]).ToRevitType()
pView = UnwrapElement(doc.ActiveView.ToDSType(True))

# Create the reference plane in a transaction
TransactionManager.Instance.EnsureInTransaction(doc)
rPlane = doc.Create.NewReferencePlane(bubbleEnd,freeEnd,cutVector,pView)
TransactionManager.Instance.TransactionTaskDone()

# Set the reference plane as the sketchplane in the active view in another transaction
TransactionManager.Instance.EnsureInTransaction(doc)
sp = SketchPlane.Create(doc,rPlane.Id)
doc.ActiveView.SketchPlane = sp
TransactionManager.Instance.TransactionTaskDone()

OUT = rPlane
```

---

<div class="post-metadata">

**Author:** ![kbruno1989](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kbruno1989/32/88072_2.png) [@kbruno1989](https://forum.dynamobim.com/u/kbruno1989)\
**Post date:** [November 24, 2020, 9:19pm UTC](https://forum.dynamobim.com/t/set-work-plane/8775/16 "2020-11-24T21:19:59Z")

</div>

Hey bud, do you happen to have the solution and/or the chart in a higher resolution?

I am working on the same issue and would love to utilize portions of your code if possible for a solution I am working on!
