I am trying to create a pushbutton which activates NewProjectDocument(template_file) method which creates Revit project with company’s template which is stored in central location. The problem is, as far as I understand, that new project is in memory and I cannot see it in Revit UI. Does anyone know how to activate it? I saw someone offered a solution with ShowElements(), but it does not work for me.
I think you might need to save it to a path first, then open it using OpenAndActivateDocument
You can save and then open. But if you don’t want to do that…
You need to find an element to view. Any element will do. In the example, I just grab the first viewpport I can find. But you could look at your opening page properties and find something on that view to use. Now if you use a completely empty project - there could be nothing to get. In that case you may have to make something first.
There may be warnings you want to suppress.
import clr
import System
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
uiapp = __revit__.Application
app = uiapp
template_file = r"C:\ProgramData\Autodesk\RVT 2024\Templates\English-Imperial\Default-Multi-discipline.rte"
newdoc = app.NewProjectDocument(template_file)
viewport = FilteredElementCollector(newdoc).OfClass(Viewport).WhereElementIsNotElementType().FirstElement()
newuidoc = UIDocument(newdoc)
newuidoc.ShowElements(viewport.Id)
Thank you. I tried exactly that, but when I use ShowElemenets(x) 2 things happen that I’m not happy about: message appears saying “there is no open view that shows any of the highlighted elements…” which I don’t know how to hide in the first place and workset toolbar (at the bottom of Revit UI) is not shown which can confuse Revit users if they run my script. The idea is launch new project without saving to avoid all those clean ups, enable worksharing, create company’s list of worksets and let Revit user manually save to cloud.
The warning dialog is easily suppressed. I’m sure you’ll find posts here in how to do that. I know Jeremy has posted extensively on that as well. You can create the worksheets of course and even initiate the save to cloud for the user.
The worklet option bar should be visible in the UI to the user once the worklets are created.
…and remember, worksets are not layers.