Hey all. I’m trying to give three input lists of IN[0], IN[1], and IN[2] to a Python Node (which its code is shown below) and receive an output which is a calculated number based on information received from those lists. The code has been compiled and it ran just fine outside of dynamo with test lists and no error was received. But, I am getting an "unexpected token ‘:’ " error when I run the code. Could you please help me with this?
These inputs are also shown in the pictures below:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# FUNCTIONS =====================
def mat_dict(mat):
mat_d = {}
for item in mat:
mat_d[item[0]]=item[1]
return (mat_d)
def match_mat(surf,mat_d):
prdct_lst =[]
for item in surf:
a = []
for i in range(len(item[0])):
b = []
area = item[1][i]
coef = mat_d[item[0][i]]
for coef_item in coef:
b.append(area*coef_item)
a.append(b)
prdct_lst.append(a)
return(prdct_lst)
#=====================================
dataEnteringNode = IN
mat_in = IN[0]
flr_in = IN[1]
wll_in = IN[2]
material_dictionary = mat_dict(mat_in)
wall_list = match_mat(wll_in,material_dictionary)
floor_list = match_mat(flr_in,material_dictionary)
room_denom = []
for i in range (len(wall_list)):
room = [0,0,0,0,0,0,0]
a = [0,0,0,0,0,0,0]
b = [0,0,0,0,0,0,0]
for m in range (7):
for j in range (len(wall_list[i])):
a[m] += wall_list[i][j][m]
for k in range (len(floor_list[i])):
b[m] += floor_list[i][k][m]
for m in range (7):
room[m] = a[m]+b[m]
room_denom.append(room)
OUT = room_denom
I would double check everywhere there is an : and make sure everything around it is properly formatted. Since the error didn’t give a line, you could try commenting out chunks of code at a time to figure out where the error is. You can comment out a section with """ """:
Try making a copy of your python node, and remove parts of the code bit by bit until you have located the “:” causing the issue.
Sometimes for me, I have had to just retype that part of the code, and somehow it has resolved my issue.
It looks like some of your range commands have a space between “range” and the parentheses. This may be causing the issue. The colons appear to be in the correct places at first glance.
Is there any chance that there is a : inside one of your inputs? Reaching a bit here, but if you are inputting things that aren’t strings that may have a : inside of them, they could cause an error when being used as a dictionary key.
Kenny, this worked. I pinned down the problem and I found out that I have been leaving out a ‘)’ while typing the code in dynamo. It turns out that this code is fine and it was a typo that was causing the error.