Hello hello here,
I am back with another issue.
I have been trying to use the python wrapper for a basic script ( I am doing a course on Revit python shell). Every time I run the script, Revit just crash. I have tried with Revit 2022 and Revit 2023, same issue.
Here is the code:
# Import modules from Autodesk Revit and from Pyton Wrapper
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
from rpw.ui.forms import (FlexForm, Label, ComboBox, TextBox, Separator, Button, CheckBox)
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
components = [Label("Number of Levels"), TextBox("number", Text = "1"), Label("Spacing between levels"), TextBox("spacing", Text = "3150"), Button("Create Levels")]
form = FlexForm("Create Levels", components)
form.show()
spacing = int(form.values.get("spacing"))
number_of_levels = int(form.values.get("number"))
prefix = "Level "
spacing_internal = UnitUtils.ConvertToInternalUnits(spacing, UnitTypeId.Millimeters)
col_levels = FilteredElementCollector(doc).OfClass(Level).WhereElementIsNotElementType()
level_names = [level.Name for level in col_levels]
highest_elevation = 0
for level in col_levels:
if level.Elevation > highest_elevation:
highest_elevation = level.Elevation
start_elevation = highest_elevation + spacing_internal
def level_name (x,y):
if y < 10:
return x + "0" + str(y)
else:
return x + str(y)
t = Transaction(doc)
t.Start("Create new Level")
for i in range(number_levels + len(level_names)):
new_name = level_name(prefix, i)
if new_name not in level_names:
try:
new_level = Level.Create(doc, start_elevation)
new_level.Name = new_name
print(new_name + " has been created")
except:
print(new_name + " has not been created")
pass
start_elevation += spacing_internal
t.Commit()
I am not sure if there is any possible explanation you might have for this behaviour.