Very simple Python Script, but it's not worked

I just make a node like below and I insert a level to this python script from a node(Levels). I don’t know why this Python script’s not working. it’s basic node so I think it don’t need additional importing…


# 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
a = Level.Elevation(IN[0])
# Assign your output to the OUT variable.
OUT = a

It might be wise to show what the input is into this node plus what is the error that is indicated?

If working with revit element, then you need to add the import modules for revit

import clr

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

IF you are inputting dynamo revit elements into this python node then you also need to unwrap the element accordingly with

#Input and unwrapping 
input=UnwrapElement(IN[0])

Lastly if you are inputting a list of elements into this python node you should really do a loop to iterate over the list.

OUT=[]

for ele in input:
	OUT.append(ele.Elevation)

This then means the completed code would look like the following if all of the above is true

import clr

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

#Input and unwrapping 
input=UnwrapElement(IN[0])

OUT=[]

for ele in input:
	OUT.append(ele.Elevation)

Example:

Edit: added a image to help show the code in practice plus that the data from Elevation is in feet and therefore may need to be converted to your units if needed. EG in my case we usually utilise Millimeters.

3 Likes

Please use the code format </> in the editor menu to make the code more readable

Although we can access the Dynamo namespace in a Python node, for simple access such as this a Code Node is going to be more straightforward.
image
image

2 Likes

My python script is differ with your 2nd case??

IF you fully read what i have indicated it should help you understand what each bit of code does and then there is a completed code example that implements all of what i said.

Hopefully this helps but do indicate what your original error was!

2 Likes

Hello, this is if you don’t have a loop to manage.

import clr
clr.AddReference("RevitAPI")
#class you want
from Autodesk.Revit.DB import Level
lvl=UnwrapElement(IN[0])
OUT = lvl.Elevation*0.3048

the base node also exists


Sincerely
christian.stan