Revit - C# - How to activate viewport programmatically?

Revit - C# - How to activate viewport programmatically?

Maltezc
Advocate Advocate
978 Views
2 Replies
Message 1 of 3

Revit - C# - How to activate viewport programmatically?

Maltezc
Advocate
Advocate

Hi all, I'm curious to see if anyone has come up with a way of programmatically activating a viewport that exists on a sheet yet? I've been searching for a way for about a year now but haven't had any luck.

 

The closest thing I've gotten so far is uidoc.showElements(viewport) but that doesn't quite cut it.

 

Has anyone else come up with a way yet?

0 Likes
979 Views
2 Replies
Replies (2)
Message 2 of 3

BenoitE&A
Collaborator
Collaborator

Hey,

I'm curious too. What for?

Do you mean that you want to work on the associated View? If so, there is a property called OwnerViewId which allows you to find the Owner, on which you can make modifications.

You can also find the Viewports of the view using View.GetAllViewports().

Benoit


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes
Message 3 of 3

Michael.Vrňata
Explorer
Explorer

This should work.

 

Viewport viewport = Viewport.Create(Service.Document, viewSheet.Id, newView.Id, origin);

 

Service.UIDocument.Selection.SetElementIds(new List<ElementId> { viewport.Id });

RevitCommandId commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.ActivateView);
Service.UIApplication.PostCommand(commandId);

0 Likes