Hiding and Showing the Bubble on Level heads

Hello all, I have to show and hide 100’s of bubbles in the level head. So I wrote a small bit of python code by referring to this

but unfortunately it throws an error. The code follows

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)


doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument


levels = IN[0]
view = uidoc.ActiveView
check = []

TransactionManager.Instance.EnsureInTransaction(doc)

for level in levels:
	level = UnwrapElement(level)
	level.IsBubbleVisibleInView(DatumEnds.End0, view)
	#The line below works and returns True or False
	#check.append(level.HasBubbleInView(DatumEnds.End0, view))
	
TransactionManager.Instance.TransactionTaskDone()	

#OUT = check
OUT = levels

Error it show is

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. 
Traceback (most recent call last):
  File "<string>", line 30, in <module>
Exception: The datum plane cannot be visible in the view.
Parameter name: view

I am confused since the code works for “HasBubbleInView” but not for “IsBubbleInView” or “ShowBubbleInView”

I think not all bubbles are visible in the views that you supply.
You could solve this by trying to catch the errors, like this:

for level in levels:
	level = UnwrapElement(level)
    try:
	       level.IsBubbleVisibleInView(DatumEnds.End0, view)
    except:
           pass
	#The line below works and returns True or False
	#check.append(level.HasBubbleInView(DatumEnds.End0, view))

Don’t just copy paste above code, but retype it with the proper indentation.

4 Likes

@T_Pover thanks a lot, didn’t strike my mind that all the bubbles will be visible in the view.

The first thing i learned in python was not to miss any indentation :slight_smile:

1 Like