Revit 2022 and 2023 crashes with python wrapper (rpw)

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)

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)
        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:
            new_level = Level.Create(doc, start_elevation)
            new_level.Name = new_name
            print(new_name + " has been created")
            print(new_name + " has not been created")
        start_elevation += spacing_internal


I am not sure if there is any possible explanation you might have for this behaviour.

1 Like

Error message or end of the Revit journal could help.

there is no error message when Revit crashes, here is a screen shot of the Revit Journal

Here is the Revit journal:

It runs just fine on my computer except for the typo

for i in range(number_of_levels+ len(level_names)):

using the flexform I usually had issues because of the IPY engine attached to pyRevit

I tried with the 2.77 one and it works

Sorry my ignorance, what do you mean you tried with the 2.77? is that the version of some of these plug-ins?

No pb at all.
With the pyRevit CLI you can tell pyrevit to use a specific iron python engine version: 2.77, 2.11, …

That will give you an idea of the list of engines

That being said, some of the references in the rps /rpw wrapper call for different methods depending on the engine your pyrevit is attached and that can cause errors at best, crashes in other cases.

Read the beginning to get an idea on how to attach your pyrevit install to a different engine:

I cannot find the pyRevit CLI installer, it seems disappeared from the links i found on the internet.
And if I check what pyRevit CLI I have installed, it just show me the latest pyRevit version

The CLI is installed with pyrevit by default.

Try this in the windows command line:

pyrevit env