( I ultimately want to “Refresh” all of my Bill of Material viewports for sheets D-6000 to D-6200 at once.
I currently have to open each individual sheet, activate my Bill of Material viewport, then refresh view. This is very time consuming.)
import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System.Core')
from System.Collections.Generic import HashSet
def tolist(obj1):
if hasattr(obj1,'__iter__'): return obj1
else: return [obj1]
# IN variables...
run = tolist(IN[0])[0]
elems = tolist(UnwrapElement(IN[1]))
# Main Code...
if run:
# Get ElementIds to list...
elemIds = HashSet[ElementId]([e.Id for e in elems])
# Set Selection (required for the postable command)...
uidoc.Selection.SetElementIds(elemIds)
uidoc.RefreshActiveView()
# Get RevitCommandId of PostableCommand...
rvtComId = RevitCommandId.LookupPostableCommandId(PostableCommand.ActivateView)
# Run PostableCommand...
uiapp.PostCommand(rvtComId)
OUT = 'Command Has Run'
else:
OUT = 'Please set Run to True';
I presumed you’d feed a list of views filtered by name…
However, Daniel knows more than me and his idea sounds like a better method…
How about you refresh 1… Grab the locations of the out of date ones, delete them and replace with duplicates of the refreshed one? If that makes sense?
Just out of curiousity Daniel, I tried putting the command inside a transaction then tried looping with a range… It gave the ‘not supporting more than one command error’ but shouldn’t this be doing multiple ‘commands’?
Any advice welcome
Mark
# Run PostableCommand...
for r in range(len(elemIds)):
TransactionManager.Instance.EnsureInTransaction(doc)
uiapp.PostCommand(rvtComId)
TransactionManager.Instance.TransactionTaskDone()
Nope, postable commands cannot be run more than once as far as I’m aware, so looping will not work I’m afraid. In fact, I don’t even think you can daisy chain them in the Dynamo graph, although I haven’t tested thoroughly as I try to avoid Postable Commands if I can.
Perhaps you could use the TransactionManager.Instance.ForceCloseTransaction() and put the transaction in your loop rather than outside but I think this will also fail.
Each sheet has a different “Bill of Material”. I use a program called StrucSoft MWF to frame walls and it generates the “Bill of Material” once we create the shop drawings. If the framing in the walls change I “Activate View” of one of the “Bill of Material” Viewport and use the StrucSoft program to “Refresh View”. This updates the “Bill of Material”. I want to figure out a way to “Refresh View” of all 200 different “Bill of Material” at once. Currently I have to open every single sheet, double click on that particular Viewport (there are 3 different viewports on each page), then “Refresh View”. Unfortunately, I don’t think the method you suggest in this instance will work.
I’m not sure what the plugin you mentioned is. But these views are in the project somewhere. Can these only be updated from within the sheet? If you delete one and undo, does it update?
sooo!!!
place copies of all of them with Dynamo
now you dont have to use all of the Sheets
what is that thing btw, a view yes, a schedule? filtered schedule?