Skip to content

Instantly share code, notes, and snippets.

@chuongmep

chuongmep/FlattenDSCore.py

Last active Sep 29, 2020
Embed
What would you like to do?
Flatten In Dynamo
# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('DSCoreNodes')
from DSCore.List import Flatten
OUT = Flatten(IN[0])
import collections
def flattenList(unflattened_list):
if isinstance(unflattened_list,collections.Iterable):
return [sub_element for element in unflattened_list for sub_element in flattenList(element)]
else:
return [unflattened_list]
OUT = flattenList(IN[0])
# The inputs to this node will be stored as a list in the IN variables.
def flatten(x):
result = []
try:
for el in x:
if hasattr(el, "__iter__") and not isinstance(el, basestring):
result.extend(flatten(el))
else:
result.append(el)
except:
result = x
return result
OUT = flatten(IN[0])
@chuongmep

This comment has been minimized.

Copy link
Owner Author

@chuongmep chuongmep commented Aug 11, 2020

Screenshot_1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.