Placing a new family on a face in Python

Kevin.Bell
Advisor

Placing a new family on a face in Python

Kevin.Bell
Advisor
Advisor

Hi,

 

I'm putting together a routine to place face based families on a face of a generic object.

 

Looking at the API documentation, there is a method for doing this which look the one the 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.

 

 

I'm using Python through dynamo, I select the family symbol using a FilteredElementCollector.

 

When I run the code, it fails with the NewFamilyInstance with the error: TypeError: expected XYZ, got Surface

 

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:

 

Capture.png

Whats going wrong, I believe I'm giving all the required inputs?

 

Thanks.

0 Likes
Reply
2,219 Views
1 Reply
Reply (1)

aignatovich
Advisor
Advisor

Hi, Kevin!

Try

doc.Create.NewFamilyInstance.Overloads[Face, XYZ, XYZ, FamilySymbol](facetoplace, XYZ(1,0,0), XYZ(0,0,0), familysymtouse)

instead.

0 Likes