import Autodesk
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
import RevitServices
from Autodesk.Revit.DB import *
from Autodesk.DesignScript.Geometry import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#The inputs to this node will be stored as a list in the IN variables.
test=IN[0]
result=[]
result=Flatten(test)
OUT=result
Any idea whats wrong? I use several other nodes…and they work just fine.
Hi Hannes,
You need to import DSCore for DesignScript nodes to work and then use it like this, where the second argument is the amount of levels to flatten:
He thx for your help! @ T_Pover…With your solution i got a different error:
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File "<string>", line 16, in <module>
IOError: System.IO.IOException: Could not add reference to assembly DSCoreNotes
at IronPython.Runtime.ClrModule.AddReference(CodeContext context, String name)
at IronPython.Runtime.ClrModule.AddReference
python code:
import clr
clr.AddReference("RevitAPI")
clr.AddReference("ProtoGeometry")
clr.AddReference("RevitNodes")
clr.AddReference("RevitServices")
clr.AddReference('RevitAPIUI')
import Autodesk
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
import RevitServices
from Autodesk.Revit.DB import *
from Autodesk.DesignScript.Geometry import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#The inputs to this node will be stored as a list in the IN variables.
clr.AddReference('DSCoreNotes')
import DSCore
from DSCore import *
@T_Pover I usually prefer “import DSCore as DS” so I can keep track of what I am using in case there are functions with the same name in different libraries. @Kulkul. That’s really nice. I wish I had more time for learning code. Now I tend to copy code from other places.
I found this link: http://code.activestate.com/recipes/577470-fast-flatten-with-depth-control-and-oversight-over/ -
some flatten functions for python with depth control.
@ Hannes - use List Comprehensions - they are much faster than loops:
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
dataEnteringNode = IN[0]
OUT = [i for sublist in IN[0] for i in sublist]
@T_Pover
Could you tell me why do you know we have to import DSCore into Python Script? Where do I find it or know it ? @Kulkul
Thanks for your example. It’s useful to learn about definition in Python
I know this is an old post but I just bumped into it as I was searching for a question.
I found your method pretty nice and changed it a bit so it runs without error in case there are for instance also numbers in the list.