In Dynamo 0.7.3 this worked out fine. In 0.7.4 the Element.Document is not accepted anymore and when using the Current Document node, the Doc.Phases statement in my Python isn’t accepted anymore. Any suggestions?
The content of the Python node:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
Import RevitAPI
clr.AddReference(“RevitAPI”)
import Autodesk
from Autodesk.Revit.DB import *
doc= IN[0]
elements =
for i in IN[1]:
elements.append(UnwrapElement(i))
for i in elements:
for phase in doc.Phases:
#perform actions here
You need to reference RevitServices. Here’s the code used in custom node Document.Phases in package Clockwork:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
elementlist = list()
for phase in doc.Phases:
elementlist.append(phase)
OUT = elementlist
If you want to write a Python script in Dynamo, I strongly suggest you read the following article on the Dynamo wiki:
Python 0.6.3 to 0.7.x Migration · DynamoDS/Dynamo Wiki · GitHub
Thanks. This helped me out and simplified my code even.
Meanwhile I got the script up and running.
You can see the whole story and dataset on this link: http://revitbeyondbim.wordpress.com/2014/12/16/dynamo-for-revit-review-design-with-room-access-requirements/
Working for 0.7.4 now.
Organon
December 2, 2015, 11:20pm
6
import clr
clr.AddReference ("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference ("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
rooms = UnwrapElement (IN[0])
groups = list ()
for phase in doc.Phases:
phaseName = phase.Name
roomPhase = list ()
for room in rooms:
roomPhaseName = room.get_Parameter (BuiltInParameter.ROOM_PHASE).AsValueString ()
if roomPhaseName == phaseName:
roomPhase.append (room)
groups.append (roomPhase)
OUT = groups