Select grids and turn on / off the bubble

Hi, how could we select those grids and turn on/ off them by using python? Anyone has done the code before? (select grids rather than chose view to turn on and off) Many Thanks.

Use an Element Selection node by Category. Then you will need to supply the Grid end (0 or 1) and then if you want to Show or Hide it.

#Sean Page, 2022
import clr

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#Preparing input from dynamo to revit
grids = UnwrapElement(IN[0])
end = IN[1]
show = IN[2]

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for grid in grids:
	if end == 1:
		if show:
			grid.ShowBubbleInView(DatumEnds.End1,doc.ActiveView)
		else:
			grid.HideBubbleInView(DatumEnds.End1,doc.ActiveView)
	else:
		if show:
				grid.ShowBubbleInView(DatumEnds.End0,doc.ActiveView)
		else:
			grid.HideBubbleInView(DatumEnds.End0,doc.ActiveView)

TransactionManager.Instance.TransactionTaskDone()

OUT = grids
6 Likes

Hi SeanP,

Many thanks. I have restructured in this way but somehow out2 give me trouble. Even if i make it as a list but still doesn’t work do you know why?




TransactionManager.Instance.EnsureInTransaction(doc)

	
for grid in gridslst:
		if gridtop:
			grid.ShowBubbleInView(DatumEnds.End1,doc.ActiveView)
			out1="Top Bubbles Shown"
			if gridtail:
			    	grid.ShowBubbleInView(DatumEnds.End0,doc.ActiveView)
			    	out2="Tail Bubbles Shown"
			else:
					grid.HideBubbleInView(DatumEnds.End0,doc.ActiveView)
					out2="Tail Bubbles Hide"
		else:
			grid.HideBubbleInView(DatumEnds.End1,doc.ActiveView)
			out1="Top Bubbles Hide"
			if gridtail:
			    	grid.ShowBubbleInView(DatumEnds.End0,doc.ActiveView)
					out2="Tail Bubbles Shown"
			else:
					grid.HideBubbleInView(DatumEnds.End0,doc.ActiveView)
					out2="Tail Bubbles Hide"			
			
TransactionManager.Instance.TransactionTaskDone()

doc.Regenerate()
uidoc.RefreshActiveView()

OUT = out1,out2

What is the error message?

Hi Sean,

IronPythonEvaluator.EvaluateIronPythonScript operation failed.
unexpected indent

then i test it line by line it seems out1 is fine. just out2 has issues. in this case how we get out2 normally?

Looks like there is a space after out1 before the comma.

Hi Sean, dont know why this way works? it seems weird.

TransactionManager.Instance.EnsureInTransaction(doc)

	
for grid in gridslst:
		if gridtop:
			grid.ShowBubbleInView(DatumEnds.End1,doc.ActiveView)
			out1="Top Bubbles Shown"
			if gridtail:
			    	grid.ShowBubbleInView(DatumEnds.End0,doc.ActiveView)
				out2="Tail Bubbles Shown"
			else:
					grid.HideBubbleInView(DatumEnds.End0,doc.ActiveView)
					out2="Tail Bubbles Hide"
		else:
			grid.HideBubbleInView(DatumEnds.End1,doc.ActiveView)
			out1="Top Bubbles Hide"
			if gridtail:
			    	grid.ShowBubbleInView(DatumEnds.End0,doc.ActiveView)
			   	out2="Tail Bubbles Shown"
			else:
					grid.HideBubbleInView(DatumEnds.End0,doc.ActiveView)
					out2="Tail Bubbles Hide"			
			
TransactionManager.Instance.TransactionTaskDone()

doc.Regenerate()
uidoc.RefreshActiveView()

Oh, I couldn’t tell by the post formatting, but yeah now it’s obvious there are issues with your indenting. It should either always be one single tab per level, or four spaces.

2 Likes

@SeanP

Thank you! This will be a huge time saver!

I added some Data-Shapes UI so I could add it to My Toolbar!

1 Like

@SeanP

Any idea why the script won’t work when I use Data-Shapes? I’m getting the grids, the number, and the boolean but nothing happens in the model. When I use the Code Block it works.

hello, you send a list, dig on this side
Sincerely
christian.stan

I gathered that, how to I convert it to something other than a list? I assumed a code block is also sending a list that is only 1 item long.

edit:

cordially
christian.stan

1 Like

Thank you so much, that worked! I’ve had this issue before with lists and never knew about this solution.

1 Like