Hello!
I am having a hard time creating a revit family programmatically. Specifically with the function NewExtrusion which gets the error:
Exception: A managed exception was thrown by Revit or by one of its external applications.
Script Executor Traceback:
Autodesk.Revit.Exceptions.InternalException: A managed exception was thrown by Revit or by one of its external applications.
at Autodesk.Revit.ApplicationServices.Application.NewFamilyDocument(String templateFileName)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at IronPython.Compiler.PythonCallTargets.OriginalCallTarget3(PythonFunction function, Object arg0, Object arg1, Object arg2)
at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`8.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at IronPython.Compiler.Ast.CallExpression.Invoke3Instruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at IronPython.Compiler.Ast.CallExpression.Invoke2Instruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at IronPython.Compiler.PythonCallTargets.OriginalCallTarget3(PythonFunction function, Object arg0, Object arg1, Object arg2)
at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
at Microsoft.Scripting.Interpreter.DynamicInstruction`6.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)
And here is my code: (error happens at the line with NewExtrusion)
counter_top_level = 0
boundary = [
XYZ(0, 0, counter_top_level), # Start point at counter height (3 feet)
XYZ(6, 0, counter_top_level), # Right leg
XYZ(6, 2, counter_top_level), # Right leg width
XYZ(2, 2, counter_top_level), # Connection point
XYZ(2, 4, counter_top_level), # Left leg
XYZ(0, 4, counter_top_level), # Left leg end
XYZ(0, 0, counter_top_level) # Back to start
]
thickness = 3/12
create_custom_extrusion_family(state, boundary, thickness)
def create_custom_extrusion_family(state, boundaries, thickness):
doc = state['doc']
app = doc.Application
template_path = app.FamilyTemplatePath
template_name = "Metric Casework.rft"
template_file = System.IO.Path.Combine(template_path, template_name)
family_doc = app.NewFamilyDocument(template_file)
family_editor_create_extrusion(state, family_doc, boundaries, thickness)
# we dont get here anyway
doc.LoadFamily(family_doc.Id)
def family_editor_create_extrusion(state, family_doc, boundaries, thickness):
assert isinstance(boundaries, list)
doc = state['doc']
t = Transaction(family_doc, "Create Extrusion")
t.Start()
create_app = doc.Application.Create
sketch_planes = FilteredElementCollector(family_doc).OfClass(SketchPlane)
sketch_plane = None
for i in sketch_planes:
if i.Name == "Ref. Level":
sketch_plane = i
break
curve_arr_array = CurveArrArray()
curve_array = CurveArray()
for i in range(len(boundaries) - 1):
line = Line.CreateBound(boundaries[i], boundaries[i + 1])
curve_array.Append(line)
curve_arr_array.Append(curve_array)
family_creator = family_doc.FamilyCreate
extrusion = family_creator.NewExtrusion(True, curve_arr_array, sketch_plane, thickness)
t.Commit()
return extrusion
The sketch plane returns the SketchPlane element which I am quite sure has its normal correct (as ground). I also tried False instead of True.
Anyone experienced similar issue?
I did follow the Great Jeremy Tammik up unto this error https://thebuildingcoder.typepad.com/blog/2011/06/creating-and-inserting-an-extrusion-family.html