#Sean Page, 2021
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
App = DocumentManager.Instance.CurrentUIApplication.Application
#List of Directory Paths
paths = IN[0]
#Create an empty list for the values
ObjectStyles = []
#Loop each family path
for path in paths:
#Open the Family
famDoc = App.OpenDocumentFile(path)
#Get all Lines in the Family
lines = FilteredElementCollector(famDoc).OfCategory(BuiltInCategory.OST_Lines).ToElements()
subs = []
#Loop each line to get the Subcategory or Object Style of the Line
for line in lines:
sub = line.LookupParameter("Subcategory").AsElementId()
#Get the Name of the Object Style
subname = famDoc.GetElement(sub).Name
#Check to see if the item already exists in the List so we only show Unique Styles
if not subs.Contains(subname):
#Append it to the list if it isn't already found
subs.append(subname)
#Add the List of Object Syles for that Family to the Overall List
ObjectStyles.append(subs)
#Close the Family Document without saving
famDoc.Close(False)
#Output the List of Object Styles by Family
OUT = ObjectStyles
Nice.
Of course it would be good to add the referring rfa name to the list so you can know where to find the rogue family with the non-compliant object style.
Absolutely, that would be easy to do, but you also have the list of Families right next too it that you can reference. I often try to make my outputs singular so that they are easier to manipulate downstream if you need to do further operations like a Contains or == if you are searching for a specific thing.
Yes, just about like any other file operation it will only work with files that are the same as the current version or older. I am working in R2022 so I wasn’t concerned about that.
The following code would wrap all of it in a try statement which should prevent the error, but I have not tested.
#Sean Page, 2021
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
App = DocumentManager.Instance.CurrentUIApplication.Application
#List of Directory Paths
paths = IN[0]
#Create an empty list for the values
ObjectStyles = []
#Loop each family path
for path in paths:
try:
#Open the Family
famDoc = App.OpenDocumentFile(path)
#Get all Lines in the Family
lines = FilteredElementCollector(famDoc).OfCategory(BuiltInCategory.OST_Lines).ToElements()
subs = []
#Loop each line to get the Subcategory or Object Style of the Line
for line in lines:
sub = line.LookupParameter("Subcategory").AsElementId()
#Get the Name of the Object Style
subname = famDoc.GetElement(sub).Name
#Check to see if the item already exists in the List so we only show Unique Styles
if not subs.Contains(subname):
#Append it to the list if it isn't already found
subs.append(subname)
#Add the List of Object Syles for that Family to the Overall List
ObjectStyles.append(subs)
#Close the Family Document without saving
famDoc.Close(False)
except:
ObjectStyles.append(None)
#Output the List of Object Styles by Family
OUT = ObjectStyles
Theres no nodes for this is there? I need to open a bunch of families. Change the object style name if its not the searched for term, save and close. Sometimes there will be multiple line types which will have to be deleted to make it only one.
I contemplated doing this as a part of the process, but unfortunately I had so many variations I decided it would be much easier to just attack the rogue ones manually and thus stopped here, but I didn’t find nodes specifically for this no.
Hi Sean, Thanks for the code, It works as intended for me.
I was thinking how you could access the object styles of the geometry rather than just the lines in the families.
Would you simply remove the reference to lines in the script? I tried to replace it with Windows = FilteredElementCollector(famDoc).OfCategory(BuiltInCategory.OST_Windows).ToElements()
Ive changed the loop to get the subcategory. However I get an error.
Have you looked into this? And would you have any insight?