Set grid bubbles by template view

No worries. unfortunaetly I get this error now… Sorry to be such a pain…

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

items = UnwrapElement (IN[0])
view = UnwrapElement (IN[1])
gridend = IN[2]

for v in view:
    i = 0
    j = 0
    for grid in items[j]:
       if gridend[i] == 0:
          grid.HideBubbleInView(DatumEnds.End0, view)
       else:
          grid.ShowBubbleInView(DatumEnds.End0, view)
    i += 1
j += 1

OUT = []

Alright, my bad again:
Change view in these two lines for v:

   if gridend[i] == 0:
      grid.HideBubbleInView(DatumEnds.End0, v)
   else:
      grid.ShowBubbleInView(DatumEnds.End0, v)

Sorry!

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 :confused:

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 = []
1 Like

thanks man. looks great. Not sure what im doing wrong, still just turned on all the bubbles.


template

view applied too

Ok, do you mind sharing your files with us? It will be easier to check what is going on

Thank you so much!

Dynamo 1.3 Revit 2019

Grid Example.rvt (452 KB)

Grid Bubbles_Set By Template View.dyn (37.3 KB)

Will take a look at it tomorrow!

1 Like

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
1 Like

Apologies I haven’t been following this, but something that might be of interest…

I tend to use the Propogate Extents method to push grid head visibility across views…

http://www.revitapidocs.com/2019/4512810a-93c3-d127-6197-94da427d54a2.htm

Probably not useful in this instance, but maybe in future :slight_smile:

3 Likes

haha ow no Revit already does it!!! hahahaha

1 Like

No worries I know the grind. Thank you so much for putting your stuff aside to help out!

Hahaha, the perks of using Dynamo, sometimes you don’t even think about doing stuff OOTB!