If you really want to use Python, after keeping the family file simple, as mentioned above, the following script should work.
__title__ = "Support\nBracket"
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import StructuralType
from Autodesk.Revit.UI import *
from Autodesk.Revit.UI.Selection import *
from System.Collections.Generic import List
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
def get_adaptive_family_symbol():
"""Get the family symbol for the adaptive component"""
collector = FilteredElementCollector(doc).OfClass(FamilySymbol)
for symbol in collector:
if symbol.Family.Name == "ClipBracket":
if not symbol.IsActive:
try:
with Transaction(doc, "Activate Symbol") as t:
t.Start()
symbol.Activate()
t.Commit()
except Exception as e:
print("Error activating symbol: {}".format(str(e)))
return None
return symbol
return None
def create_family(point, angle):
familySymbol = get_adaptive_family_symbol()
if familySymbol is None:
print("Could not find family symbol")
return
try:
with Transaction(doc, "Activate Symbol") as t:
t.Start()
# Create a new instance of the family
newFamily = doc.Create.NewFamilyInstance(point, familySymbol, Structure.StructuralType.NonStructural)
ElementTransformUtils.RotateElement(doc, newFamily.Id, Line.CreateBound(point, point + XYZ.BasisZ), angle)
t.Commit()
except Exception as e:
print("Error creating family: {}".format(str(e)))
pipe = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element, "Pick object"))
location = pipe.Location
locationCurve = location.Curve
point = locationCurve.Evaluate(0.5, True)
rotationFactor = 1
if locationCurve.Direction.CrossProduct(XYZ.BasisZ).Z < 0:
rotationFactor = 1
else:
rotationFactor = -1
angle = locationCurve.Direction.AngleOnPlaneTo(XYZ.BasisY, XYZ.BasisZ) * rotationFactor
create_family(point, angle)
It is working for me. Kindly see the attached video.
Note that, as I mentioned the family file has to be finetuned by setting the required parameters and comnstraints , like pipe diameter etc...