# Python script cannot proceed

**URL:** <https://forum.dynamobim.com/t/python-script-cannot-proceed/65590>\
**Category:** Revit\
**Tags:** python, dynamo\
**Created:** [June 28, 2021, 9:02am UTC](https://forum.dynamobim.com/t/python-script-cannot-proceed/65590 "2021-06-28T09:02:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Austin21](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@Austin21](https://forum.dynamobim.com/u/Austin21)\
**Post date:** [June 28, 2021, 9:02am UTC](https://forum.dynamobim.com/t/python-script-cannot-proceed/65590/1 "2021-06-28T09:02:02Z")

</div>

![Dynamo Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/c/1ca3d89f78d83661765b93a2912f905a44d5dafe.png)

Hello,

I created a simple dynamo for checking intersection which is the first watch node in the screen capture. And I want to simplify the result to the second watch node. For this I  
wrote a script to do it which is successful as shown.

However, when I tried to integrated the second part into the first part of the Python script. It simply doesn’t work and I cannot figure out the reason.

Could anyone tell me why it cannot work?

Here is the script I used in the first python node:

```auto
# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
geo1 = IN[0] #Geometry 1
geo2 = IN[1] #Geometry 2

def intersection(in1):
    x = []
    for a in geo2:
        x.append(in1.Intersect(a))
    return x
    
result = list(map(intersection, geo1))

temp = []   
output = []

def flatsub(data):
    for item in data:
        if isinstance(item, list):
            if not len(item):
            	temp.append(0)
            else:
            	flatsub(item)
        else:
            temp.append(item)

for element in result:
    if isinstance(element, list):
        flatsub(element)
        output.append(temp)
        temp = []
    else:
        output.append(element)

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

```

And here is the second one which is the same of the lower part of the first python script:

```auto
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

# Place your code below this line

result = IN[0]
temp = []   
output = []

def flatsub(data):
    for item in data:
        if isinstance(item, list):
            if not len(item):
            	temp.append(0)
            else:
            	flatsub(item)
        else:
            temp.append(item)

for element in result:
    if isinstance(element, list):
        flatsub(element)
        output.append(temp)
        temp = []
    else:
        output.append(element)

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

```

Thanks.  
Austin

---

<div class="post-metadata">

**Author:** ![haganjake2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/haganjake2/32/119069_2.png) [@haganjake2](https://forum.dynamobim.com/u/haganjake2)\
**Post date:** [June 28, 2021, 9:33am UTC](https://forum.dynamobim.com/t/python-script-cannot-proceed/65590/2 "2021-06-28T09:33:03Z")

</div>

It could be any number of reasons that the Python once combined is erroring.

Rather than posting the 2 that work can you post the version where it is combined and not? This way it can be debugged properly.

---

<div class="post-metadata">

**Author:** ![Austin21](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@Austin21](https://forum.dynamobim.com/u/Austin21)\
**Post date:** [June 28, 2021, 9:50am UTC](https://forum.dynamobim.com/t/python-script-cannot-proceed/65590/3 "2021-06-28T09:50:26Z")

</div>

It shows no error at all, but the results after combined is the same before I combined. It makes me don’t know to debug.

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [June 28, 2021, 10:45am UTC](https://forum.dynamobim.com/t/python-script-cannot-proceed/65590/4 "2021-06-28T10:45:05Z")

</div>

Hello  
the method `Geometry.Intersect(Geometry)` return an Net Array not a Python list

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/7/07993cc6deef16703c6b078d9dca3e4032837401.png)

it works on the second node, because Dynamo out wrapper converted it

try to use `if hasattr(result, ' __iter__'):` instead of `isinstance(result, list):`

---

<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:** [June 28, 2021, 4:29pm UTC](https://forum.dynamobim.com/t/python-script-cannot-proceed/65590/5 "2021-06-28T16:29:11Z")

</div>

Again, it’s hard to help without seeing the combined code.

The intersections are returning a list, which is expected. Before you make any changes, be sure that you won’t miss anything by reducing the list structure. Intersections return a list because the intersection of two objects can potentially have multiple intersecting geometries. If you know for sure that your intersections will only ever return a singular geometry then you can reduce the structure, otherwise you may be removing some intersections.

As for the code cleanup…  
As previously stated, the intersection returns a list. The first thing to do is check to see if that list is empty - I’d recommend checking list length - then return either a 0 or the first item in the intersection list depending on length condition.

---

<div class="post-metadata">

**Author:** ![Austin21](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@Austin21](https://forum.dynamobim.com/u/Austin21)\
**Post date:** [June 29, 2021, 1:32am UTC](https://forum.dynamobim.com/t/python-script-cannot-proceed/65590/6 "2021-06-29T01:32:43Z")

</div>

@c.poupin It works now. Thanks a lot.  
Is that if the object is under Autodesk from GetType(), it is not a python object? I tried to search net array to find more reference but little relevant result is shown.

@Nick_Boyts The first code I pasted is the combined one. The second one is omitting the intersection part from the first one. Anyway, thanks for your reply.

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [June 29, 2021, 9:00am UTC](https://forum.dynamobim.com/t/python-script-cannot-proceed/65590/7 "2021-06-29T09:00:02Z")

</div>

> [@Austin21](#):
>
> Is that if the object is under Autodesk from GetType(), it is not a python object? I tried to search net array to find more reference but little relevant result is shown.

It’s a Net method

> **[Object.GetType Method (System)](https://learn.microsoft.com/en-us/dotnet/api/system.object.gettype?view=net-5.0)**
>
> Gets the Type of the current instance.
