How to use Dynamo node core into python

Hi everyone.

Please help me to get the list of Elements that are sorted by Z value and use the python language in dynamo.

I have used “List.SortByKey” in the python script but I can not get the list of Element.

List.SortByKey node in dynamo will be extract 2 sorted list and sortd keys, but I just would like to get the sorted list. In Python script I extract a list of them, however I can not get list of “sorted list” although using “List.GetItemAtIndex”

  1. The list of Elements by using dynamo node.
  2. The list of list when I use “List.SortBykey”

And I do not understand the List.Map node in Dynamo, please help me to know it in detail.

This is code I have use:

if IN[0] == True:
cols = uidoc.Selection.PickObjects(Selection.ObjectType.Element)
Framing =
for i in cols:
Framing1 =
k = doc.GetElement(i)
Framing.append(k)

z =
for i in Framing:
z.append(i.Location.Curve.GetEndPoint(0).ToPoint().Z)

import DSCore
from DSCore import *
z = List.SortByKey(Framing,z)

Thank you for your help.

When I use “List.GetItemAtIndex” it has a problem like the below Image:

And If I use “List.GetItemAtIndex” in dynamo node it does not have any warning.

What is difference between them?

Could you post all your code inside the python script node properly formatted?

Yes, this is my code:

import clr
clr.AddReference(“RevitNodes”)
clr.AddReference(“RevitServices”)
clr.AddReference(“RevitNodes”)
clr.AddReference(“RevitAPI”)
clr.AddReference(“RevitAPIUI”)
clr.AddReference(“ProtoGeometry”)
clr.AddReference(“System.Windows.Forms”)
clr.AddReference(“System.Drawing”)

import System
from System.Windows.Forms import *
from System.Drawing import *
from System.Collections.Generic import *

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from RevitServices.Elements import *

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
view =doc.ActiveView
import Autodesk.Revit.Creation

import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import (XYZ
)

import Autodesk.Revit.UI
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI import (Selection)

import Revit
import Autodesk.DesignScript.Geometry
from Autodesk.DesignScript.Geometry import *

clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

#Code from Here
TransactionManager.Instance.EnsureInTransaction(doc)

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
view =doc.ActiveView

lev = view.GenLevel
if IN[0] == True:
cols = uidoc.Selection.PickObjects(Selection.ObjectType.Element)
Framing = []
for i in cols:
Framing1 = []
k = doc.GetElement(i)
Framing.append(k)

z = []
for i in Framing:
z.append(i.Location.Curve.GetEndPoint(0).ToPoint().Z)

import clr
clr.AddReference(“DSCoreNodes”)
import DSCore
from DSCore import *
z7 = List.SortByKey(Framing,z)

TransactionManager.Instance.TransactionTaskDone()

OUT = z7

1 Like

Why not just use the nodes? Reinventing the wheel is sometimes fun but…

Dear JacobSmall.

I need to know the Dynamo core node because I would like to understand how to change the Dynamo node into Python. It is more usefull when we know how to get information we need to take.

I do not know why the node could be extracted the elements but I can not get the list of them.

In this case if you’re using python it’s likely simplier and a better practice to use the Python equivalent of the Dynamo node.

1 Like

Hi danhyks,

did you find out how to import Dynamo Core into Python?
it would be useful to know how to import it,

thanks in advance :slight_smile: