Changing active view is temporarily disabled?

@chrisishere I’ve recently created a tool in Dynamo which needs to set a particular view. I thought I’d share this code snippet as there is another method you can use which does successfully set views. Its worth mentioning that you can’t set the uidoc.ActiveView in Revit’s Idling event. That’s a major drawback for Dynamo, since Dynamo operates inside this event (i.e. its not possible). Instead you need to use RequestViewChange(). Its executes asynchronously, so if you need to set a view first, then perform an action that’s dependent on this event inside the same node then you’ve got a problem. Also, a transaction has to be opened first and force closed using ForceCloseTransaction(), otherwise this method will still fail:

#Copyright 2016. All rights reserved. Bimorph Consultancy LTD, 5 St Johns Lane, London EC1M 4BH www.bimorph.co.uk
#Written by Thomas Mahon @Thomas__Mahon info@bimorph.co.uk Package: bimorphNodes
#GitHub: https://github.com/ThomasMahon/bimorphNodes/
#Follow: facebook.com/bimorphBIM | linkedin.com/company/bimorph-bim | @bimorphBIM

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIDocument

TransactionManager.Instance.EnsureInTransaction(doc)
TransactionManager.Instance.ForceCloseTransaction()

view = UnwrapElement(IN[0])
uidoc.RequestViewChange( view )
12 Likes