Create Multiple Reference Planes

Reference plane creation in different direction doesn’t work any more
I used to always use this old python script from Rhythm, and it worked wonderfully to create reference planes in different directions until now.

it works for just one
How can i make it work for multiple reference planes?

You will need to include the error messages that you get as well as the DYN and Python code. I don’t see how anyone can help you with what you posted.

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


#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)
typelist = list()

# End the transaction
TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable
OUT = rPlane

To convert Proto Points to Revit API XYZs (points) you need to call ToXyz() not ToRevitType(). You also don’t need to unwrap Proto elements. This method is only used/required for interop with wrapped Revit Elements.

You also don’t need to unwrap the doc.ActiveView, nor do you need to call ToDSType() as this wraps an Element which is redundant considering you call it inside a UnrwapElement() plus you need it unwrapped to make the RevitAPI call to construct the plane. See if that gets you any closer.

3 Likes

@Nico_Stegeman, I would give @Thomas_Mahon’s comments a try.

One of the bigger issues is that node will not work with lists as it is very old and one of my early pieces of work in Rhythm. I actually removed that node from Rhythm a while back and it is no longer supported in my package.

I went ahead and edited your post for formatting and removed my name as that script is no longer in Rhythm.

That all being said, if this is a node you still wanted to see in Rhythm, I can definitely add it back as a zerotouch variant. Let me know what you think.

2 Likes

Changed it a bit.

I would certainly love it if the Node will be part of your package again. And when it is a zero touch node i can also use it in code blocks

I gave @Thomas_Mahon a try.
Getting a little closer i think. But stil not creating multiple reference planes

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
Start = IN[0]
End = IN[1]
cutVector = IN[2]
pView = UnwrapElement(doc.ActiveView.ToDSType(True))
#pView = UnwrapElement(doc.ActiveView.ToDSType(True))

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

i = 0;
for S,E in zip(Start,End):
try:
S.ToXyz()
E.ToXyz()
rPlane = doc.Create.NewReferencePlane(S,E,cutVector,pView)
x.append(rPlane)
# x.append(S)
except:
x.append("None")
i+=1
# x.append(rPlane)
# "End" the transaction
TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable
OUT = x

Just to quote Thomas…

You also don’t need to unwrap the doc.ActiveView, nor do you need to call ToDSType()

So maybe like this?

uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
pView = uidoc.ActiveView

In general I try to output variables such as pView, S and E to help see where the problem is :slight_smile:

Hope that’s useful,

Mark

I am getting the points and view. but i am still not able to create the reference planes

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
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
pView = uidoc.ActiveView

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

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

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

i = 0;
for S,E in zip(Start,End):
try:
S.ToXyz()
E.ToXyz()
cutVector.ToXyz()
rPlane = doc.Create.NewReferencePlane(S,E,cutVector,pView)
x.append(rPlane)
# x.append(S)
except:
x.append("None")
i+=1
# x.append(rPlane)
# "End" the transaction
TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable
OUT = x,S,E,cutVector,pView

It’s a difficulty with the ‘try’ it just skips the bit you’re interested in…

If you just put it in a ‘for’ you’ll likely get an error message saying that something didn’t work?

Better still you would adjust the ‘try’ to output an error message, you see it in Konrad’s old code, I just had a look in ‘Get Built In Parameter’ but I’m not sure if he’d object to me just copying it all in!

Hope that helps,

Mark

1 Like

I stil get an empty list and a warning:
line 63
expected XYZ got point.
What is the reason of this warning?

Well… I guess it means the .ToXYZ() isn’t working? :slight_smile:

If you posted a couple of test files it would be easier to work out why?

I wonder whether that part should be taken out of the transaction… It’s a Dynamo method?

Hope that helps,

Mark

1 Like

Hy Mark

This is my test file

DY PL Reference Plane test.dyn (53.2 KB)

Nico

ToXyz() has a return type of XYZ and therefore instantiates an XYZ instance, it does not cast the original Point to XYZ. So, you need to assign your Points (S and E) to new variables when you call ToXyz() i.e. store the result of the conversion, then pass these new XYZs into your ReferencePlane() constructor. Currently, you a doing what you did at the start - passing Proto Points into the ReferencePlane() constructor (as S and E are unmodified by the ToXyz() call), which as you know, are the wrong instance type, and that’s why the same exception is occurring.

Also, on line 62 you have a typo; you are are calling ToXyz() like a property. Its a method, and therefore requires the empty parenthesis… and you need to store the result of the conversion to XYZ in a new variable, which then needs to be passed into your ReferencePlane() constructor (same issue as above).

2 Likes

Thanks Mark, Thomas, and John

Probably not a very good script I made but it works. And i learned a few things to better understand Python. Thank you guys.

Greetings Nico

2 Likes

Mark

according to your advice
Now without the try and i start transaction only when it is needed and stop it :slight_smile:

Great perseverance… Nothing like the joy of it running :slight_smile: Good job!

1 Like