Hi,
Is it possible to define the start view using the API ?
At the moment, I can only find a way to access the parameter and find out if a view is defined as the start view.
Thanks š
Solved! Go to Solution.
Link copied
Hi,
Is it possible to define the start view using the API ?
At the moment, I can only find a way to access the parameter and find out if a view is defined as the start view.
Thanks š
Solved! Go to Solution.
Yes, you can. You could probably subscribe to and use the ApplicationInitialized event and the UIDocument.ActiveView property to achieve this:
Thank you for your answer.
It's not quite what i want to do. with your solution the start view will be activated provided the plugin is installed. I prefer "Specify the Starting View for a Model".
Do you think it's possible ?
If you want a solution that does not require programming, I am sorry to say that this is the wrong place to ask. Sorry.
Of course, I want to program.
I simply want to define the starting view once through programming, and then each time the file is opened, no plug-in is required (for example, if I send my mail to a customer).
Aha. Well, as always, perform some research first to ensure that this functionality is present manually in the Revit end user interface. If not, the API will probably not be able to help.
Sure this is possible manually, as explained here : Specify the Starting View for a Model
The GetStartingViewSettings method lets you know if a view is already defined as the starting view. But I'd like to be able to define the starting view automatically via the API ?
use this method to set your Starting View
void SetStartingView ()
{
// Code provided courtesy of:
// Studio A International, LLC
// http://www.studio-a-int.com
// The below code set the Starting View to a specific view that exists in Active Project
FilteredElementCollector feCollector = new FilteredElementCollector(activeDoc);
myView = feCollector.OfClass(typeof(Autodesk.Revit.DB.View)).Cast<Autodesk.Revit.DB.View>().Where<Autodesk.Revit.DB.View>(v => ViewType.ThreeD == v.ViewType && v.IsTemplate == false && v.Name == "my3DStartingView").ToList().FirstOrDefault();
FilteredElementCollector svsCollector = new FilteredElementCollector(activeDoc);
Autodesk.Revit.DB.StartingViewSettings svs = svsCollector.OfClass(typeof(StartingViewSettings))
.Cast<Autodesk.Revit.DB.StartingViewSettings>().ToList().FirstOrDefault();
if (myView is object)
{
ElementId myViewId = new ElementId(Convert.ToInt32((myView.Id.ToString())));
if (svs.IsAcceptableStartingView(myViewId))
{
using (Transaction t = new Transaction(activeDoc, "Set Starting View"))
{
t.Start("Set Starting View");
svs.ViewId = myViewId;
t.Commit();
}
}
}
}
Just out of principle, to continue my endless (and hopeless?) struggle against unnecessary calls to ToList, may I point out that you can replace .ToList().FirstOrDefault() by a more efficient simple single call to FirstElement:
https://www.revitapidocs.com/2024/c8c1cae0-4ac8-a309-e915-6d491137d47e.htm
If your model happens to contain 1000 views, the call to ToList will marshal all 1000 views objects and their entire data into a list before throwing out the 999 unneeded ones.