Element.Document and Python script for phases in Dynamo 0.7.4


#1

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?

2014-12-12_21-58-10

 

 

 

 

 

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

 


#2

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: https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration

#3

Thanks. This helped me out and simplified my code even.


#4

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.


#5

New to Dynamo=/Python

Is there a way to extract the room phases? I have 3 phases with rooms. I cannot filter out the rooms of a particular phase (or is there a way?)

I have excerpts of the script:

##Gather sums of wall / room boundaries based on lengths and directions
import clr
clr.AddReference(“RevitNodes”)
clr.AddReference(‘ProtoGeometry’)
import math
clr.AddReference(‘RevitAPI’)
clr.AddReference(‘RevitAPIUI’)
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager

import RevitServices
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
import Autodesk

from Autodesk.Revit.DB import *

items = UnwrapElement(IN[0])

###snip###

PhaseList = list() ##Gather Phases - works…

for phase in doc.Phases:
PhaseList.append(phase.Name)

for item in items:
doc = item.Document
clist = list()

###########################################################################################
#Room Phase
Phase=’’ ##initialize to nothing
ii=-1
for xphase in doc.Phases:
ii=ii+1
if item.CreatedPhaseId == xphase.Id: ##Needs work… needs to red Phase ID to phase name correctly, and doesn’t work…
break
Phase = PhaseList[ii]
clist.append(Phase)


#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