DynamoDS / Dynamo

Open Source Graphical Programming for Design
https://dynamobim.org
Other
1.74k stars 634 forks source link

change of active view in python script disabled!!!!!!!!!!!!! #5651

Closed epeter- closed 6 years ago

epeter- commented 9 years ago

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. Traceback (most recent call last): File "", line 25, in Exception: Setting active view is temporarily disabled.

here the code (actually working in iron python shell enviroment

import clr import math clr.AddReference('RevitAPI') clr.AddReference('RevitAPIUI') from Autodesk.Revit.DB import * clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager doc = DocumentManager.Instance.CurrentDBDocument uiapp = DocumentManager.Instance.CurrentUIApplication app = uiapp.Application uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

collector = FilteredElementCollector(doc).OfClass((ViewPlan)) active = uidoc.ActiveView outlist = [] outlist.append(("active view = %s" %active.Name)) for el in collector: elName = el.Name actName = active.Name if elName != actName: break

uidoc.ActiveView = el outlist.append(("new active view = %s" %uidoc.ActiveView.Name)) OUT = outlist

ksobon commented 9 years ago

So trying to do this particular task poses a challenge. To set an ActiveView in Revit you cannot have any transactions open at the time. As far as I understand how Dynamo works is that it keeps a transaction open at all the time and anything that you are doing inside of Python is effectively "inside of Transaction". That's why setting an Active View would fail. It seems like Dynamo team decided to not deal with this, and just disabled it. That's one way to do it. :-) Just to make sure it's really not going to work, can you try manually closing a transaction like this: TransactionManager.Instance.ForceCloseTransaction() Put that code before you try to set the active view. If this doesn't work then I am afraid you are out of luck.

johnpierson commented 6 years ago

I know this is an old post.. But, using some logic defined here, http://thebuildingcoder.typepad.com/blog/2017/02/setting-active-view-during-idling.html

we can do this as an async process along with the TransactionManager.Instance.ForceCloseTransaction() @ksobon mentioned.

import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
app = DocumentManager.Instance.CurrentUIApplication.Application
uiapp = DocumentManager.Instance.CurrentUIApplication

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

view = UnwrapElement(IN[0])
# output a result
output = []

TransactionManager.Instance.ForceCloseTransaction()
try:
    # request view change as an async process
    uiapp.ActiveUIDocument.RequestViewChange(view)
    output = view
except:
    output = []

OUT = output