Python if family has certain name

Hey guys,

Fiddling around. currently I check if an (the first it encounters) instance is mirrored. Check.
However I want to get some control which instance it uses.
In my case I want to check for a certain instance (which fam. name contains a keyword).

Currently:

def groupelements(group):
	memberlist = []
	try:
		for member in group.GetMemberIds():
			memberlist.append(group.Document.GetElement(member).ToDSType(True))
	except:
		pass
	return memberlist

def getfirstfamilyinstanceorientation(groupelements):
	try:
		return UnwrapElement([i for i in groupelements if isinstance(i,Revit.Elements.FamilyInstance)][0]).Mirrored
	except:
		return False

But it should be like:

def getfirstfamilyinstanceorientation(groupelements):
    	try:
    		if i in groupelements familyName has "keyword"
                return UnwrapElement([i for i in groupelements if isinstance(i,Revit.Elements.FamilyInstance)][0]).Mirrored
    	except:
    		return False

So if a certain familyname isn’t present in group: exit.
if it is: get that familyinstance mirror status.

Makes sense? if so: how to?

are you looking for something like this:

passingFamilies = [i for i in groupelements if "keyword" in i.Name]
if len(passignFamilies) > 0:
    # do something here
1 Like

@Konrad_K_Sobon, yes. I lack the knowledge of the way of coding in python and therefor the ‘flow’ / approach is sometimes counter intuitive. I know php but it’s slighty different :confused:
So reusing shorthand coding in python is sometimes a fun puzzle for me :slight_smile:

I ended up with this approach.

test = []
def getfirstfamilyinstanceorientation(groupelements):
	refGroupMembers = groupelements.GetMemberIds()	
	for member in refGroupMembers:
		elem = groupelements.Document.GetElement(member)	
		if elem.GetType().ToString() == "Autodesk.Revit.DB.FamilyInstance" and "wrap" in elem.Symbol.Family.Name:
			#test.append(elem.Symbol.Family.Name)
			return elem.Mirrored		
			break