I feel like I’m almost complete with my first script, but I’m having a hard time finding something in the documents. I want to only allow the selection of family components. I can’t find anything similar to: DB.BuiltInCategory.OST_Grids. I can’t find any BuiltInCategory for ‘families’. Am I going about this the wrong way?
I’m referring to an instance of a placed family. I’m piecing together different pieces of code while I’m learning Python. I have pasted the pertinent portion below. I’m essentially wanting the user to run the script, then select certain families which need to be exported. I don’t want them to be able to selected system elements (like walls, etc).
I started this script based off of the ‘toggle grid’ script from PyChilizer.
def __init__(self, cat):
self.categ = cat
def AllowElement(self, e):
if e.Category.Id.IntegerValue == int(self.categ):
grid = doc.GetElement(revit.uidoc.Selection.PickObject(UI.Selection.ObjectType.Element, CustomISelectionFilter(DB.BuiltInCategory.OST_Grids), 'Pick a Family'))
with revit.Transaction('Family Select'):
except Exception as e:
Since you’re learning python (and programming in general, i guess), let me give you some random tips:
the “I” of “ISelectionFilter” stand for “Interface”, that is, something to follow to be able to talk to other objects; when you implement an interface with code you can lose the “I”, since yours is a concrete implementation.
the if condition: return True; else: return False is a long and convoluted way to do the same as return condition
Also: please remember to wrap the code in triple backticks (```) for better readability. I’ve done it for you, but keep it in mind for the future. Thanks
I almost always follow the EAFP principle: it’s easier to ask for forgivenes than permission, that’s why I suggested the try/except way.
At least in standard python, exceptions are cheap, so as long as the case catched is an… exception (= not so frequent), it is slightly faster than always check for the attribute presence (that is the C# way, LBYL: look before you leap!)
In this specific case, it is difficult to know how frequently the exceprion is raised, it depends on whether the end user understands the tool or not