Alter View templates in project via dynamo

Hi All

Im after help on how to grab all active View templates within my revit project with dynamo and turn off the import element of VG so that all my views do not get contaminated with imported AutoCAD dwg.

Ideally, I need this as a dynamo script as I have hundreds of projects to repair.

I may want to filter by view name, i.e., begins with β€œXX.”

Hi,
I’m not sure this function is available in Revit API, a workaround is to disable categories (CADLink)

import clr
import sys
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

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

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

viewtemplates = DB.FilteredElementCollector(doc).OfClass(DB.View).ToElements().FindAll(lambda x : x.IsTemplate)
cadlinkTypes = DB.FilteredElementCollector(doc).OfClass(DB.CADLinkType)

TransactionManager.Instance.EnsureInTransaction(doc)
for view in viewtemplates:
	if view.Name.startswith("XX."):
		for cadlLnkType in cadlinkTypes:
			if Element.Name.GetValue(cadlLnkType).endswith(".dwg"):
				view.SetCategoryHidden(cadlLnkType.Category.Id, True)
		
TransactionManager.Instance.TransactionTaskDone()

OUT = cadlinkTypes
1 Like

Hi

Thanks for this, im totally new to the dynamo, how do I use this in a script. Does this need adding to a python node then attached to some input / outputs?

Just copy and paste inside a python Node

That’s great.

one more question how can I get this to look fo more than one type

Example

β€œXX”
β€œ01_”
β€œ02_”
β€œ03_”

Many thanks in advance

startswith() method can accept a tuple as a parameter

if view.Name.startswith(("XX", "01_", "02_", "03_")):

https://docs.python.org/3.7/library/stdtypes.html#string-methods

1 Like