Set Work Plane

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
I’m not so good with Python… could anyone help me to solve it?

Thanks!

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?

actually, I’m asking to do something I cannot do :sweat_smile:

So please read this first:

I cannot go further than this

1 Like

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:

2 Likes

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…

<img

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

probably this image is a little bit more clear

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.

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

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

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
1 Like

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
1 Like

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!