Export Mesh/Directshape Geometry to Families

Hello everyone,

First of all, I am very new to Dynamo. I have already been able to import my .obj files and convert them from mesh geometry to a DirectShape. I have assigned the geometries to the special equipment category.
I would now like to save the individual geometries as .rfa. Unfortunately nothing happens and there is no error message, could someone help me? The script is included below.

Alternatively, I have already tried the FamilyInstance.ByGeometry node, which does not accept the Mesh/DirectShape as a geometry. I have also tried to convert the DirectShape to Solid Geometry, but I am not getting anywhere either.

Thank you very much for your help

import clr
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitAPI")
import Autodesk
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

# Close all transactions
trans = TransactionManager.Instance
trans.ForceCloseTransaction()

fams = IN[0]
paths = IN[1]

# Unwrap the Dynamo elements and convert the map to a list
fams = [UnwrapElement(x) for x in fams]

success_count = 0

for i in range(len(fams)):
    try:
        famDoc = doc.EditFamily(fams[i].Symbol.Family)
        print("Opened family document for", fams[i].Symbol.Family.Name)
        
        print("Saving family to path:", paths[i])
        famDoc.SaveAs(paths[i])
        
        famDoc.Close(False)
        print("Closed family document")
        
        success_count += 1
    except Exception as e:
        print("Error:", e)

OUT = success_count

What is the error you are getting?

I believe that if you’ve created the direct shapes in the Revit environment you won’t be3 able to use the EditFamily method, as they aren’t families in a traditional sense. You should instead push the mesh into a family document as a new directshape there, and then create an instance.