Create New Family Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have been researching and learning python to write code to perform this task using pyrevit to build my tab and buttons.
I am attempting create a pushbutton tool to insert a generic annotation symbol into the active view within revit. I have had success with creating the pushbutton and getting the tool to insert the family using XYZ(0,0,0). What I would like to have happen is to have the user place the symbol using the mouse instead of a coordinate system because it could be multiple places and not always the same.
My second issue that this currently does not work with nested families. When using the tool it places every type within the family in the same location. I would like to be able to use the same family but create different buttons for each family type.
The code I got from this site on a post from about two years ago and that post is now locked.
If someone could take a look and offer some advice or help modify the code below that would be awesome.
Thank you!
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 = 'CN_AIRFLOW ARROW'
#create a filtered element collector set to Category OST_Mass and Class FamilySymbol
collector = FilteredElementCollector(doc)
collector.OfCategory(BuiltInCategory.OST_GenericAnnotation)
collector.OfClass(FamilySymbol)
famtypeitr = collector.GetElementIdIterator()
famtypeitr.Reset()
#Search Family Symbols in document.
for item in famtypeitr:
famtypeID = item
famsymb = doc.GetElement(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.Create.NewFamilyInstance(loc, famsymb, doc.ActiveView)
t.Commit()