AttributeError: 'list' object has no attribute 'ToRevitType'

Hi,

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

Is there any workaround?

And chance you are passing a list of lists of loops instead of a list of loops into IN0 of the Python node from the Dynamo environment?

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?


selecionaPisoAdaptaTopo.dyn (11.2 KB)
TestePisoTopo_r1.rvt (1.9 MB)

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:

1 Like

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.

1 Like

I always thought the product of Flatten node was working list. Now I know that not always.

I’m a fan of your YouTube channel and I’ll surely watch this Python series. Thank you so much!

@jacob.small, that’s something I’ll consider, as soon as I’m able to understand a little bit more of coding. Thanks!

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’.

1 Like