Hi,
I’m putting together a routine which places some bricks on a generic model face.
Currently I’m using Dynamo to place the face based ‘Brick’ family, but due to issues with Dynamo removing the ‘bricks’ from every time the routine is rerun I’m now looking at placing the families using Python.
The API has this method for placing face based families which looks like the one to use:
NewFamilyInstance(Face, XYZ, XYZ, FamilySymbol) Inserts a new instance of a family onto a face of an existing element, using a location, reference direction, and a type/symbol.
So I’ve put this code together to place using the above method:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
# Import Revit elements
from Revit.Elements import *
# Import DocumentManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
import sys
sys.path.append('C:/Program Files (x86)/IronPython 2.7/Lib')
from math import atan2, radians, cos, sin, degrees, sqrt, ceil
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
adoc = doc.ActiveView
facetoplace = IN[0][0]
familysym = IN[1]
#NewFamilyInstance(Face, XYZ, XYZ, FamilySymbol) Inserts a new instance of a family onto a face of an existing element, using a location, reference direction, and a type/symbol.
#Find family Symbol
familysymname = "Brick"
familysymtouse = 0
collector = FilteredElementCollector(doc).OfClass(FamilySymbol)
famtypeitr = collector.GetElementIdIterator()
famtypeitr.Reset()
for item in famtypeitr:
getfelement = doc.GetElement(item)
getffamily = getfelement.Family
getfname = getffamily.Name
if getfname == familysym:
familysymtouse = getfelement
b1 = doc.Create.NewFamilyInstance(facetoplace, XYZ(1,0,0), XYZ(0,0,0), familysymtouse)
OUT = [familysymtouse]
This is the Dynamo part:
When I run the code, it fails with the NewFamilyInstance with the error: TypeError: expected XYZ, got Surface.
I believe I’ve given the code all the correct inputs, so I can’t see why the code fails.
I’d appreciate some pointers.
Thanks.