Reputation: 9
I am trying to activate a view using Revit API. What I want to do exactly is to display the level or floor plan view. So the view I want to activate ( I mean, I want this view to be actually shown on screen) already exists, and I can access its Id.
I have seen threads about creating, browsing, filtering views, but nothing on activating it... It's a Floor Plan view. (What I want is that by selecting a level/ floor plan, it displays that level/ floor plan on-screen(it's like opening that floor plan from the already existing Revit model to display on the user screen).
Upvotes: 0
Views: 2241
Reputation: 96
Revit api docs link for RequestViewChange Method
use uidoc.RequestViewChange("Your View")
sometimes view can't be changed while on processing transactions. On such case Force Close the Transaction. before this line uidoc.RequestViewChange("Your View")
Upvotes: 2
Reputation: 9
FilteredElementCollector viewCollector = new FilteredElementCollector(doc);
viewCollector.OfClass(typeof(View));
foreach (Element viewElement in viewCollector)
{
yourview = (View)viewElement;
break;
}
}
uidoc.ActiveView = yourview;
Upvotes: 0
Reputation: 327
Here is an example how to switch to the default 3d-view https://thebuildingcoder.typepad.com/blog/2011/09/activate-a-3d-view.html
you can do the same with all other available views like this
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
uidoc.ActiveView = yourview;
to create a view from a level your code can look like this
ViewFamilyType viewFamilyType = (from elem in new
FilteredElementCollector(doc)
.OfClass(typeof(ViewFamilyType))
let type = elem as ViewFamilyType
where type.ViewFamily == ViewFamily.FloorPlan
select type).FirstOrDefault();
using (Transaction t = new Transaction(doc))
{
t.Start("Create View");
var floorPlan = ViewPlan.Create(doc, viewFamilyType.Id, yourLevel.Id);
floorPlan.Name = "NewView";
t.Commit();
}
Upvotes: 0
Reputation: 588
Super easy to do:
# normally you have the ui set at the start of your script
ui = __revit__.ActiveUIDocument
# then just set the ActiveView as your view (not the ViewId)
ui.ActiveView = yourView
Upvotes: 0