after my transaction I am ensuring that the transaction has ended but the process is not ending.
That is my Revit doesn’t go back to normal so I can proceed with my work.
Not sure why this is happening.
Please provide a bit more context of your code
More often than not, you don’t need to use script.exit() as this is handeld in your context manager.
if you use for example:
with revit.Transaction('some transaction'):
# do something
import clr
clr.AddReference("System")
from System.Collections.Generic import List
import os
from pyrevit import script
from Autodesk.Revit.DB import*
from Autodesk.Revit.UI import*
from pyrevit import forms,UI, revit
uiapp = __revit__
uidoc = uiapp.ActiveUIDocument
doc = uiapp.ActiveUIDocument.Document
folder = forms.pick_folder(title="Select Folder Containing Family Files")
if not folder:
forms.alert("No folder selected.", title="Cancelled")
raise Exception("No folder selected.")
# Get all .rfa files
family_files = [f for f in os.listdir(folder) if f.lower().endswith(".rfa")]
if not family_files:
forms.alert("No .rfa files found in selected folder.", title="Empty Folder")
raise Exception("No family files to load.")
t = Transaction(doc, "Load Families from Folder")
t.Start()
for fname in family_files:
full_path = os.path.join(folder, fname)
success = doc.LoadFamily(full_path)
if success:
print("Loaded:", fname)
else:
print("Failed to load:", fname)
t.Commit()
if t.HasEnded():
forms.alert("Family loading complete.", title="Done")
script.exit()
I am getting the prompt that family loading has been complete but the command is still running. (it is not going back to normal after it is run like it should.
try like so
import os
from pyrevit import forms, revit
doc = revit.doc
# Select folder containing family files
folder = forms.pick_folder(title="Select Folder Containing Family Files")
if not folder:
forms.alert("No folder selected.")
exit()
# Get all .rfa files
family_files = [f for f in os.listdir(folder) if f.lower().endswith(".rfa")]
if not family_files:
forms.alert("No .rfa files found in selected folder.")
exit()
# Load families using transaction context manager
with revit.Transaction("Load Families from Folder"):
for fname in family_files:
full_path = os.path.join(folder, fname)
success = doc.LoadFamily(full_path)
print("{}: {}".format("Loaded" if success else "Failed", fname))
forms.alert("Family loading complete.")`
I tried this, but after the “Family loading complete” window my file gets hanged
Add
-*- coding: utf-8 -*-
to the top of the script, your families might have non-ASCII characters that crash the script.
Also make sure the families you are loading is not corrupt. (Which might cause this)
Do you mean the command is over but ribbon buttons are greyed out?
Try gripping Revit by the top of the window like you are dragging to another screen, but then snap it back up to the top of the screen and it should make your ribbon responsive again.
yes this is exactly what I mean.
I am unable to grip Revit by the top of the window as you suggested, its not letting me
Can you reproduce with only a few families and provide families for us to reproduce