I’m trying to replicate this graph, but there’s something odd with the python programming. I’m getting this error message:
Aviso: IronPythonEvaluator. Falha na operação EvaluateIronPythonScript.
Traceback (most recent call last):
File “”, line 37, in
AttributeError: ‘list’ object has no attribute ‘ToRevitType’
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import *
import System.Collections.Generic
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('RevitServices')
from RevitServices.Transactions import TransactionManager
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
# Get input variables
subregions = IN[0]
host = UnwrapElement(IN[1])
# Init variables
curveLoops = []
createdSubRegions = []
error = []
TransactionManager.Instance.EnsureInTransaction(doc)
# Get groups of curves (exploded polycurves!) and creates per group a SubRegion
for i in subregions:
# Init CurveLoop for every curve group
x = CurveLoop()
# Iterate the seperate curves -> convert type to Revit Type -> add to CurveLoop
for j in i:
x.Append(j.ToRevitType())
curveLoops.append(x)
# Add layer to list
y = [x]
yI = List[CurveLoop](y)
if SiteSubRegion.IsValidBoundary(yI):
# Create SubRegion out of the CurveLoop group and add its to 'createdSubregions'
newSubRegion = SiteSubRegion.Create(doc, yI, host.Id)
createdSubRegions.append(newSubRegion)
TransactionManager.Instance.TransactionTaskDone()
# Output
OUT = createdSubRegions
The error occurs when I input a list of lists. Make sense. However, when I input a flattened list, I get:
Aviso: IronPythonEvaluator. Falha na operação EvaluateIronPythonScript.
Traceback (most recent call last):
File “”, line 36, in
TypeError: iteration over non-sequence of type Line
Is it because the code is not recognizing the sketch as a closed loop? In this case, how to workaround?
The Python script is built to work with a list of lists of curves, so you’ll need to make your flattened list one level deeper. Definitely take some time to sit back and learn Python if you want to use Python nodes, it is essential for copying/pasting Python blocks to also understand what they are doing and the structure of inputs they expect to receive. I have a series on YouTube that covers Python fundamentals if it helps, here is part one:
Alternatively the code could be wrapped in a custom node. This would allow list lacing and levels to be applied as needed, ensuring that you can input any list structure as long as the list levels are adjusted correctly.
The list is workable in nodes that support level behavior, but Python takes levels explicitly if in a script node. In this case the Python script uses a nested for loop, so it essentially says ’ for each object in a list… then for each curve in that list’.