Hide Linked-In model Grids

Hello,

I have been trying to find a way to hide the grid lines for linked-in models in Revit. for the purpose of development and testing i have been working with a sample project.

My end goal is to be able to feed a list of views into a node and in the end hide all the grid lines related to the linked in model.

Currently i can hide the grid lines only on my current (Active) document, and i can also change the active document through Dynamo.

Whenever i feed a list of views to my node, it does not seem to process the code in the flow that it should, the flow i assume it should is this:

view 1 -> pull elements in view -> filter grid elements out -> add grid elements to array -> hide all grid elements in array -> loop to next view repeating all previous steps.

What it actually does when i run it.

view 1 -> pull elements in view-> filter grid elements out -> add grid elements to array -> hide all grid elements in array -> loop to next view -> not actually update view and pull elements from view not including visual elements like grids -> loop through full list only effecting first item in list

Visually this looks like Dynamo thinking for a few seconds, then Revit rapidly cycling through views.

Dynamo1

My code has lots of debugging bits in it, adding items to lists for output to follow what was happening, so it can seem a bit messy in some places.
The Hide Grids node full code:

RepeatLoop = 0
import time
while RepeatLoop < 1:
RepeatLoop = RepeatLoop + 1
import clr
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
import time

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIDocument

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


import System
from System.Collections.Generic import *


import sys
pyt_path = r'C:\program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)


DataEnteringNode = IN


def ProcessList(_func, _list):
	return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )


def Unwrap(item):
	return UnwrapElement(item)

errorReport = ""
Output = ""
PreOutput = ""
ViewListCount = 0
View = Unwrap(IN[0][0])
OutputList = []
StageLevel = "0"
ItemList = []
ids = List[ElementId]()
PassCount = 0
FailCount = 0
Item = []
ItemNames = []
IsHidden = 0
ListCount = 0
LoopList = []


while ViewListCount < len(IN[0]):
	LoopList.Add("Loop Started")
	ListCount = ListCount + 1
	TransactionManager.Instance.ForceCloseTransaction()
	#uidoc.RequestViewChange( View )
	LoopList.Add(View)
	LoopList.Add(ListCount)
	ViewListCount = ViewListCount + 1
	if ViewListCount < len(IN[0]):
		View = Unwrap(IN[0][ViewListCount])
	collector = FilteredElementCollector(doc,doc.ActiveView.Id).ToElements();
	
	for i in Unwrap(collector):

		if Element.Name.GetValue(i) != "ElectricalSystem" and Element.Name.GetValue(i).startswith("Elevation") != True and Element.Name.GetValue(i).startswith("Space") != True and Element.Name.GetValue(i).startswith("Workshop") != True and Element.Name.GetValue(i).startswith("Standard") != True and Element.Name.GetValue(i).startswith("XHHW") != True and Element.Name.GetValue(i).startswith("GFCI") != True and Element.Name.GetValue(i).startswith("Model ") != True and Element.Name.GetValue(i).startswith("Section ") != True and Element.Name.GetValue(i).startswith("Hall ") != True and Element.Name.GetValue(i).startswith("3D ") != True and Element.Name.GetValue(i).startswith("Mechanical") != True and Element.Name.GetValue(i).startswith("North") != True and Element.Name.GetValue(i).startswith("South") != True and Element.Name.GetValue(i).startswith("West") != True and Element.Name.GetValue(i).startswith("East") != True and Element.Name.GetValue(i).startswith("Duct") != True and Element.Name.GetValue(i).startswith("STB ") != True:
			LoopList.Add(i)
			LoopList.Add(Element.Name.GetValue(i))
			if Element.Name.GetValue(i) == "Grid Line":
				LoopList.Add("Pass1")
				ItemNames.Add(Element.Name.GetValue(i))	
				Item.Add(i)
				if not i.IsHidden(doc.ActiveView) and i.CanBeHidden(doc.ActiveView):				
					PassCount = PassCount + 1
					ids.Add(i.Id)
					LoopList.Add("Added to ids")
			else:			
				FailCount = FailCount + 1
				LoopList.Add("Fail1")
					
					
			if Element.ToString(i) == "Autodesk.Revit.DB.Grid":
				LoopList.Add("Pass2")
				ItemNames.Add(Element.ToString(i))
				Item.Add(i)
				if not i.IsHidden(doc.ActiveView) and i.CanBeHidden(doc.ActiveView):				
					PassCount = PassCount + 1
					ids.Add(i.Id)
					LoopList.Add("Added to ids")
				
			else:			
				FailCount = FailCount + 1
				LoopList.Add("Fail2")
		
		
			
	doc = DocumentManager.Instance.CurrentDBDocument
	LoopList.Add("Check if list is populated")
	LoopList.Add(len(ids))
	if len(ids) != 0:	
		TransactionManager.Instance.EnsureInTransaction(doc)
		doc.ActiveView.HideElements(ids)
		uidoc = DocumentManager.Instance.CurrentUIDocument
		TransactionManager.Instance.TransactionTaskDone()
		ids = List[ElementId]()
		IsHidden = IsHidden + 1
		LoopList.Add("Current View")
		LoopList.Add(View)
		LoopList.Add("List Hidden")
	
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add(ListCount)	
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add(ListCount)	
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add(ListCount)	
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add(ListCount)	
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
	LoopList.Add("Loop Ended /////////////////////// Loop Ended")
			
#Assign your output to the OUT variable.
ListCountOutput = "List Count: " + str(ListCount)
IsHiddenOutput = "Lists Hidden: " + str(IsHidden)
PassCountOutput = "Items Passed: " + str(PassCount)
FailCountOutput = "Items Failed: " + str(FailCount)
ItemsHidden = "Items have been hidden"
if (PassCount + IsHidden) == 0:
	ItemsHidden = "All items hidden already"

OUT = RepeatLoop, ids, Item, ItemNames, PassCountOutput, FailCountOutput, IsHiddenOutput, ListCountOutput, ItemsHidden, LoopList, IN[1];

rename your Grid Type, filter out other ones (by Type Name) in a ViewTemplate

2 Likes

Could you clarify? Current i only know how to pull the element I.D’s from the Active view document, however dynamo wont update the active view during the code, so it repeatedly collects the same data from the first active view.

I need to be able to hide grids on specific views but not all views, so if i go through a template wont that hide all grids?

I am unsure if there is a way to hide elements when they are not in the active view, if there is then that would bypass my need to change the view and all i would need is to feed the list of views. Which also would cause less graphical processing on revit because it would no longer cycle through 15+ views in a couple seconds.

its easy,
in every view you dont want those grids, put in a filter, no dynamo needed.
As i said make your own Grids to having a Type name thats unique, filter out the rest

Currently we already filter the linked-in models like this, this manual method of doing it has become a long and daunting task as there are 100+ items we have to do this to per project. This is why we are looking into a way to automate it with Dynamo.

Often times we have models with the grids already available, so re-naming them all would likely be just as daunting of a task, unless there is a way to simultaneously name several grids at once that i’m missing?

You dont rename the Grids, you rename the Grid Type

At the moment this is still no more efficient then what we currently do.

Is there a way to control the visibility graphics override through the API in Dynamo? because if i could control that per view then it would solve the overall problem.

I came here to say the same thing as Marcel.

In our projects we name our grid type Grid-MEP. Then we have a filter in our project that says “hide Grids where Grid Name != Grid-MEP” that hides everybody else’s grids in all our views (except where we want to see them.) Once you have the filter set up in your view templates you never have to worry about new grids or rerunning your dynamo script. It just works. It might seem like it takes just as long as your current method, but it is much more efficient.

1 Like

Wouldn’t you still have the problem if each of your disciplines was in a separate model?

Here is a potential fix:

I’d prefer to have it in the custom settings for the link in the template though, as more than just grids need hidded in the links.

we do this as well, easy enough to just have 1 more filter in all your view templates, and done.

1 Like