No sorrys! I’m so grateful and in awe of all this coding. It worked! well sort of… it turned on all the grids in all the views. Not set the bubbles as the template view
Hahahahahahahaha, my bad again.
The error is due that Dynamo runs everything possible at the same time, so it’s trying to open two transactions (requests to Revit for changing stuff in it) at the same time when you get to set the grids bubbles visibility. I kept everything the same, exception of the last python script where is integrated the two grid end template. Tested and working!
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
items = UnwrapElement (IN[0])
view = UnwrapElement (IN[1])
gridend = IN[2]
gridend1 = IN[3]
TransactionManager.Instance.EnsureInTransaction(doc)
for v in view:
i = 0
j = 0
for grid in items[j]:
if gridend[i] == 0:
grid.HideBubbleInView(DatumEnds.End0, v)
else:
grid.ShowBubbleInView(DatumEnds.End0, v)
i += 1
j += 1
for v in view:
i = 0
j = 0
for grid in items[j]:
if gridend1[i] == 0:
grid.HideBubbleInView(DatumEnds.End1, v)
else:
grid.ShowBubbleInView(DatumEnds.End1, v)
i += 1
j += 1
TransactionManager.Instance.TransactionTaskDone()
OUT = []
Sorry mate, got a busy day…and it was far from fun doing construction documentation. ok, I made a major mistake in my code, wrote the counters in the wrong loop! A bit ashamed, hahaha. Here is the good one:
# import common language runtime and libraries
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# inputs in variables
items = UnwrapElement (IN[0])
view = UnwrapElement (IN[1])
gridend = IN[2]
gridend1 = IN[3]
# define function to turn on/off bubbles according to template
def bubbleHead(views, grids, template, side):
# loop through all views in the views list
for v in views:
# counters to select correct items
j = 0
i = 0
# loop through all grids inside view
for grid in grids[j]:
# set bubble visibility according to template
if template[i] == 0:
grid.HideBubbleInView(side, v)
else:
grid.ShowBubbleInView(side, v)
# increase the counter for template to match next grid in view
i += 1
# increase counter to match next set of grids to view
j += 1
# open transaction manager
TransactionManager.Instance.EnsureInTransaction(doc)
# call function with first set of parameters
one = bubbleHead(view, items, gridend, DatumEnds.End0)
# call function with second set of parameters
two = bubbleHead(view, items, gridend1, DatumEnds.End1)
# end transcation
TransactionManager.Instance.TransactionTaskDone()
OUT = 0