First Python Script

python
dynamo

#1

Hello I having trouble getting my script to run correctly. I am trying to compare entries in a list. If there is a match between the two I return a match (true or false). I get the error name ‘List’ is not defined. Still fairly new to python so any help is appreciated.

import clr


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


clr.AddReference("RevitNodes")
import Revit

from Revit.Elements import *



#The inputs to this node will be stored as a list in the IN variables.


#Assign your output to the OUT variable.
OUT = []





numberOfentries = IN[0]
RevitLst = IN[1]
ExcelLst = IN[2]

count = 0




#while (List.GetItemAtIndex(RevitLst,count) != NULL):

RevitArray = List.GetItemAtIndex(RevitLst,count)
RevitRevDescription = List.FirstItem(RevitArray)
RevitRevDate = List.GetItemAtIndex(RevitArray,1)
RevitIssuedStatus = List.GetItemAtIndex(RevitArray,2)
RevitRevSequence = List.GetItemAtIndex(RevitArray,3)

ExcelArray = List.GetItemAtIndex(ExcelLst,count)
ExcelRevDescription = List.FirstItem(ExcelArray)
ExcelRevDate = List.GetItemAtIndex(ExcelArray,1)
ExcelIssuedStatus = List.GetItemAtIndex(ExcelArray,2)
ExcelRevSequence = List.GetItemAtIndex(ExcelArray,3)

if(RevitArray == ExcelArray and RevitRevSequenc == ExcelRevSequence and RevitRevDate == ExcelRevDate):
	match = True
else:
	match = False



	

	#count = count + 1





OUT = match


#2

When pasting code use the Preformatted Text option so others can follow along and copy your code if needed.
image


#3

Fixed!


#4

I don’t understand this: you first compare RevitArray with ExcelArray and then you compare items of those lists… If they are the same so their items should be the same… Are you trying to analyse if the whole array is the same or any of it’s items?


#5

`
import clr
clr.AddReference(‘DSCoreNodes’)
from DSCore import *

#The inputs to this node will be stored as a list in the IN variables.

numberOfentries = IN[0]
RevitLst = IN[1]
ExcelLst = IN[2]

count = 0

#while (List.GetItemAtIndex(RevitLst,count) != None):

RevitArray = List.GetItemAtIndex(RevitLst,count)
RevitRevDescription = List.FirstItem(RevitArray)
RevitRevDate = List.GetItemAtIndex(RevitArray,1)
RevitIssuedStatus = List.GetItemAtIndex(RevitArray,2)
RevitRevSequence = List.GetItemAtIndex(RevitArray,3)

ExcelArray = List.GetItemAtIndex(ExcelLst,count)
ExcelRevDescription = List.FirstItem(ExcelArray)
ExcelRevDate = List.GetItemAtIndex(ExcelArray,1)
ExcelIssuedStatus = List.GetItemAtIndex(ExcelArray,2)
ExcelRevSequence = List.GetItemAtIndex(ExcelArray,3)

if(RevitArray == ExcelArray and RevitRevSequence == ExcelRevSequence and RevitRevDate == ExcelRevDate):
match =True
else:
match = False

#Assign your output to the OUT variable.
OUT = match
`


#6

It looks like you’re missing two things: your loop (which I see you attempted) and an output list.

You don’t need a Count if you use a For Loop.

for item in RevitList:
     #your code here#

This will loop through your code for each sublist item in the list RevitList. Assuming RevitList and ExcelList are the same length, this should be all you need.

You will also need an output list. Right now match gets set for each sublist. But it gets overridden each time.

output = []

match = True/False
output.append(match)

First you’ll need to create an empty list (anywhere outside of your if statement). Then after setting match for each sublist you’ll append that value to your output list. Your OUT is now output which will be a list containing each match value for each sublist.

Finally, the reason you’re getting that error is because it thinks List is an undefined variable. You need to use DSCore.List.GetItemAtIndex.


#7

I have an Excel list with revisions to be compared with the current ones in Revit. One list has the Excel information and other has the Revit information.


#8

I just help you fix the syntax. I guess your idea that check whether one item is existing in another list or not.


#9

Can you explain what this bit does?


#10

It help you can call all methods from dynamo (dynamo component) in python script.
In this case, you used some methods from List class (FirstItem, GetItemAtIndex, etc.)