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.
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];