Message 1 of 6
Place a family instance by Python

Not applicable
08-03-2018
02:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear All,
I am trying to place a family instance by the code from: http://wiki.theprovingground.org/revit-api-py-family. I opened an Mass.rtf file, pasted the code in Interactive Python Shell, but it doesn’t work.
import clr clr.AddReference('RevitAPI') clr.AddReference('RevitAPIUI') from Autodesk.Revit.DB import * app = __revit__.Application doc = __revit__.ActiveUIDocument.Document t = Transaction(doc, 'Create family instance.') t.Start() #Family symbol name to place. symbName = 'BoxFamily' #create a filtered element collector set to Category OST_Mass and Class FamilySymbol collector = FilteredElementCollector(doc) collector.OfCategory(BuiltInCategory.OST_Mass) collector.OfClass(FamilySymbol) famtypeitr = collector.GetElementIdIterator() famtypeitr.Reset() #Search Family Symbols in document. for item in famtypeitr: famtypeID = item famsymb = doc.get_Element(famtypeID) #If the FamilySymbol is the name we are looking for, create a new instance. if famsymb.Family.Name == symbName: #location to place family loc = XYZ(0,0,0) #NewFamilyInstance() familyInst = doc.FamilyCreate.NewFamilyInstance(loc, famsymb, Structure.StructuralType.NonStructural) t.Commit() __window__.Close()
As a poor rookie, I was confused by the 'BoxFamily' which I guess it is a family instance, introduced and defined by the programmer. So I want to print all family names, so I tried:
for item in famtypeitr:
famtypeID = item
famsymb = doc.get_Element(famtypeID)
print (famsymb.Family.Name)
Still nothing.
So can anyone tell me how to print all the family name? and how to define a symbol such as the 'BoxFamily' so I can place my own instances?
Thank you for your help to a rookie who has now been crazy.
Robin