# First Python Script

**URL:** <https://forum.dynamobim.com/t/first-python-script/16751>\
**Category:** Revit\
**Tags:** python, dynamo\
**Created:** [November 22, 2017, 3:45pm UTC](https://forum.dynamobim.com/t/first-python-script/16751 "2017-11-22T15:45:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andaroo](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Andaroo](https://forum.dynamobim.com/u/Andaroo)\
**Post date:** [November 22, 2017, 3:45pm UTC](https://forum.dynamobim.com/t/first-python-script/16751/1 "2017-11-22T15:45:37Z")

</div>

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

```

 ![Capture1](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/a/0ace2b8178e56350f979f249419bef2c7e222c70.PNG) ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/4/a4079df420ef47c110a320076ee5c28259c05697.PNG)

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [November 22, 2017, 4:44pm UTC](https://forum.dynamobim.com/t/first-python-script/16751/2 "2017-11-22T16:44:50Z")

</div>

When pasting code use the Preformatted Text option so others can follow along and copy your code if needed.  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/7/17d1cbd9aed32b54b8affd87b44d5f6e935c2264.png)

---

<div class="post-metadata">

**Author:** ![Andaroo](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Andaroo](https://forum.dynamobim.com/u/Andaroo)\
**Post date:** [November 22, 2017, 4:49pm UTC](https://forum.dynamobim.com/t/first-python-script/16751/3 "2017-11-22T16:49:03Z")

</div>

Fixed!

---

<div class="post-metadata">

**Author:** ![ricardoperucci](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@ricardoperucci](https://forum.dynamobim.com/u/ricardoperucci)\
**Post date:** [November 22, 2017, 4:49pm UTC](https://forum.dynamobim.com/t/first-python-script/16751/4 "2017-11-22T16:49:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![conghau.bdh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/conghau.bdh/32/38092_2.png) [@conghau.bdh](https://forum.dynamobim.com/u/conghau.bdh)\
**Post date:** [November 22, 2017, 4:54pm UTC](https://forum.dynamobim.com/t/first-python-script/16751/5 "2017-11-22T16:54:26Z")

</div>

`  
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  
`

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [November 22, 2017, 4:57pm UTC](https://forum.dynamobim.com/t/first-python-script/16751/6 "2017-11-22T16:57:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Andaroo](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Andaroo](https://forum.dynamobim.com/u/Andaroo)\
**Post date:** [November 22, 2017, 4:57pm UTC](https://forum.dynamobim.com/t/first-python-script/16751/7 "2017-11-22T16:57:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![conghau.bdh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/conghau.bdh/32/38092_2.png) [@conghau.bdh](https://forum.dynamobim.com/u/conghau.bdh)\
**Post date:** [November 22, 2017, 5:04pm UTC](https://forum.dynamobim.com/t/first-python-script/16751/8 "2017-11-22T17:04:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andaroo](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Andaroo](https://forum.dynamobim.com/u/Andaroo)\
**Post date:** [November 22, 2017, 5:04pm UTC](https://forum.dynamobim.com/t/first-python-script/16751/9 "2017-11-22T17:04:54Z")

</div>

> [@conghau.bdh](#):
>
> import clr
> 
> clr.AddReference(‘DSCoreNodes’)
> 
> from DSCore import \*

Can you explain what this bit does?

---

<div class="post-metadata">

**Author:** ![conghau.bdh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/conghau.bdh/32/38092_2.png) [@conghau.bdh](https://forum.dynamobim.com/u/conghau.bdh)\
**Post date:** [November 22, 2017, 5:12pm UTC](https://forum.dynamobim.com/t/first-python-script/16751/10 "2017-11-22T17:12:14Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/b/bb0402c08b3d2a0f069b18d693f6eeca42e02181.png)
