Get Analytical Space from Energy Analysis Surface by using Python

Hi everyone,

I’m trying to get the “primary analytical space” that a “energy analysis surface” is associated with in the energy model from revit. In the image below is shown more specific my approach:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

My first attempt was by writing the code below. However I got the following error: <<File “<string>”, line 36, in <module> AttributeError: attribute ‘GetAnalyticalSpace’ of ‘namespace#’ object is read-only>>

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
import clr

Import DocumentManager and TransactionManager

clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

Import RevitAPI

clr.AddReference(‘RevitAPI’)
import Autodesk

Import Revit Nodes

clr.AddReference(“RevitNodes”)
import Revit

Import from Revit DB and all its parts

from Autodesk.Revit.DB import *

Import from Revit Creation where the Create.NewDuct class is.

from Autodesk.Revit.Creation import *

Import ToProtoType, ToRevitType geometry conversion extension methods

clr.ImportExtensions(Revit.GeometryConversion)

#Defining Current document
con = Autodesk.Revit.DB.Analysis

doc = DocumentManager.Instance.CurrentDBDocument

#Imput of energy analysis surface
Surf = IN[0]

Start Transaction

TransactionManager.Instance.EnsureInTransaction(doc)
#Get analytical Space info

con.GetAnalyticalSpace(Surf);

Stop Transaction

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable
if errorReport == None:
OUT = output
else:
OUT = errorReport

Afterwards I tried to rewrite my code in the following way and this time I didn’t get any error. However I got an empty list as an output. I don’t really know what the mistake could be.

import clr

clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
import clr

Import DocumentManager and TransactionManager

clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

Import RevitAPI

clr.AddReference(‘RevitAPI’)
import Autodesk

Import Revit Nodes

clr.AddReference(“RevitNodes”)
import Revit

Import from Revit DB and all its parts

from Autodesk.Revit.DB import *

Import from Revit Creation where the Create.NewDuct class is.

from Autodesk.Revit.Creation import *

Import ToProtoType, ToRevitType geometry conversion extension methods

clr.ImportExtensions(Revit.GeometryConversion)

#Defining Current document
con = Autodesk.Revit.DB.Analysis

doc = DocumentManager.Instance.CurrentDBDocument

#Imput of energy analysis surface and list definition
Surf = UnwrapElement(IN[0])
elementlist = list()

Start Transaction

TransactionManager.Instance.EnsureInTransaction(doc)
#Get analytical Space info

for con in Surf:
try:
ref = con.GetAnalyticalSpace(Surf)
elementlist.append(ref)
except:
elementlist.append(list())

Stop Transaction

TransactionManager.Instance.TransactionTaskDone()

OUT = elementlist

 

Thanks in advanced. I would really appreciate some help.

Kind regards,

Alejandro Mata

Hi again,

I think that I’m making some progress in my python script in order to get the analytical space from an energy analysis surface. (http://revitapisearch.com/html/c9373502-fff8-00f8-0d29-10f2cce6d2ea.htm)

However, I still haven’t made it to work. So far is looking like that:

 

An this is the error that I’m getting now:

<<Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. Traceback (most recent call last): File “<string>”, line 35, in <module> TypeError: expected EnergyAnalysisSurface, got UnknownElement>>

Do you have any recommendations about what could be the reason for this error?

Thanks in advanced.

Kind regards,

Alejandro Mata

Interesting… Also found this in the built in parameters;


Might be another way to get the space

Fixed your code (Needed to unwrap IN[0) but I get the following error;
2019-03-06%2023_07_27-Window

Ok This is working with a list of surfaces;
Analysis Surfaces.dyn (64.2 KB)

(2.0.2)