Traceback errors with 2019 Revit

Revit 2018 runs the below selection no issues but I am getting the included error for 2019…

I’m able to replicate the error in both Revit 2018 and 2019. It seems to be stemming from the next() function, but I’m having difficulty understanding the logic so I can’t provide a solution.

@cgartland So I can at least explain logic. Read in 3 separate list.

List 1 is a value held in the pipe family.
List 2 is list of pipe diameters.
List 3 is a list of values to compare to List 1.

The condition it is looking for is L1[a]<L3[y]. If the condition is not met move to the next index of L3 till satisfied. Once satisfied take the L2[y] and put it into list L4. Push L4 into the pipe diameter property.

What’s happening is that one of your values in L1 is greater than all of the values in L2. So, the next() function keeps iterating until it reaches the end and then raises the exception. Using a subset of your data I get the same error:

Changing the first value from 177.4 to 1.4 does not raise an exception because none of the values in L1 exceed the max value of L2.

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

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import DSCore nodes in Dynamo
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *

# Import python library
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import os
import shutil
import math
# Import math library
from math import *

#Import Data and Time
from datetime import datetime
now = datetime.now()

#Import System Library
import System
from System.Collections.Generic import *
from System.IO import Directory, Path

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

def buildlist(L1,L2,L3):
	solution = []
	for l_first in L1:
		item_l2 = [i for v,i in zip(L2,L3) if l_first<=v]
		if item_l2:
			solution.append(item_l2)
	return solution

#Preparing input from dynamo to revit
first = IN[0]
second = IN[1]
third = IN[2]
fourth= []

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

fourth = buildlist(first,second,third)

solution = []
for l_first in first:
	templist = []
	for i,v in enumerate(second):
		if l_first <= v:
			templist.append(third[i])
			continue
		else: continue
	if templist:
		solution.append(templist)
TransactionManager.Instance.TransactionTaskDone()

#Final output
OUT = fourth,solution

can achieve what you need with or without enumerate. Two ways to achieve that as shown above.

@stillgotme getting similar errors as before. Where is the deliniation between methods?

@cgartland IN[2] goes up to 7000 in the image though so not sure that is it…

do you mind showing me the errors?


@stillgotme
Out should be a single list with [22,22,4,10,6,22,20,20,20,2,2,2,2]

Take IN[1] and compare it to values in IN[0] for <= condition. Once satisfied, take the index of item in IN[0] and get the value from IN[2] at that index and append it to a list…

What is odd is that the code I had posted initially worked literally the day before…

Looks like inputs IN[0] and IN[1] got switched by accident. Here’s a modified version of what you’ve posted (it may have to do with the variable naming which was a bit confusing–L1 = IN[0], L2 = IN[2], L3 = IN[0]).

image

L1 = IN[0]
L2 = IN[1]
L3 = IN[2]

def buildlist(L1, L2, L3):
	solution = []
	for l_first in L1:
		for l_sec, l_third in zip(L2, L3):
			if l_first <= l_sec:
				solution.append(l_third)
				break
	
	return solution
	
OUT = buildlist(L1, L2, L3)

I should note that this also assumes that the if statement will evaluate as True at least once per outer loop. If it doesn’t, the solution list will be shorter than the input lists.