Hi! I am working with Revit APIs in Dynamo thorugh Python. The script below works with the IronPython2 interpreter but not with the CPython3 interpreter, returing the error in this figure.
I need to work through CPyton3 for using the numpy library. Have you suggestions on how to solve this issue? Many thanks for the help you can provide me.
#! python3
# IMPORT LIBRARIES
import sys
import System
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import Transaction
from Autodesk.Revit.UI import TaskDialog
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import XYZ, UV, Line, CurveLoop, Level, Floor, FloorType
from System.Collections.Generic import List
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Function to convert centimeters to feet
def centimeters_to_feet(centimeters):
return centimeters * 0.0328084
doc = DocumentManager.Instance.CurrentDBDocument
# Coordinates
a = 0.0
b = 10.0
c = IN[0]
# Input elevation (in centimeters)
elevation_cm = c
elevation_ft = centimeters_to_feet(elevation_cm)
# Create a new level at the given elevation
new_level = None
# Start a new transaction to modify the Revit document creating a new level
transaction = Transaction(doc, 'Create New Level')
transaction.Start()
try:
new_level = Level.Create(doc, elevation_ft)
# Assign a new name to the level
new_level_name = "elBS_BuildingStorey_{:.0f}cm".format(elevation_cm)
new_level.Name = new_level_name
transaction.Commit()
except Exception as e:
# If an error occurs, roll back the transaction and show an error message
transaction.RollBack()
TaskDialog.Show('Error', 'Failed to create level. Error: {}'.format(e))
if new_level:
TaskDialog.Show('Success', 'Level created at elevation: {} centimeters'.format(elevation_cm))
# Create new floor
point0 = XYZ(a, a, c)
point1 = XYZ(b, a, c)
point2 = XYZ(b, b, c)
line01 = Line.CreateBound(point0,point1)
line12= Line.CreateBound(point1,point2)
line23 = Line.CreateBound(point2,point0)
curv=CurveLoop()
curv.Append(line01)
curv.Append(line12)
curv.Append(line23)
# Collect floor types
floortypes = FilteredElementCollector(doc).OfClass(FloorType)
floortypes = [f for f in floortypes]
floortypes_id = [f.Id for f in floortypes]
floortype_id = floortypes_id[0]
# Collect building storeys
el_BuildingStoreys = FilteredElementCollector(doc).OfClass(Level)
el_BuildingStoreys_id = []
for el in el_BuildingStoreys:
el_BuildingStoreys_id.append(el.Id)
level_id = el_BuildingStoreys_id[0]
# Start transaction
t = Transaction(doc, "Create new floor")
t.Start()
# Create the floor
new_floor = Floor.Create(doc,List[CurveLoop]([curv]), floortype_id, new_level.Id)
t.Commit()