Python script cannot proceed

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:

# 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:

# 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

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.

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.

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

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

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

3 Likes

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.

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

It’s a Net method