Create new Revit .rfa file with geometry

Hi,
I could not find what I need to know in old topics, so I decided to post a new topic.
What I am trying to is that to know python program to convert Rhino object to new Revit generic model,
I could create new .rfa file with material parameter but could not find the way to add geometry in it.
In my program, to get rhino object and convert to Revit solid geometry is succeeded.
So just I need to know is how to add the solid geometry to family document.
I used chat-gpt but found no solution.
I would really appreciate if anyone give me some advise.

I need to create hundreds of same type of .rfa file at a time and want to do it automatically with python script instead of using grasshopper component such as “Create Family Component”.

Here is my python program


import rhinoscriptsyntax as rs
import scriptcontext as sc
from RhinoInside.Revit import Revit, Convert

import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
from Autodesk.Revit import DB
from Autodesk.Revit.DB import *
from System.IO import Directory, File


#from layers
layers = rs.LayerNames()    
rhobjs = sc.doc.Objects.FindByLayer(layers[6])
rhgeo = rhobjs[0].Geometry

# Convert Rhino geometry to Revit geometry
revit_geo = Convert.Geometry.GeometryEncoder.ToGeometryObject(rhgeo)

#Generic model family template path
template_path  = family_template_path
rvdb =  Revit.ActiveDBDocument.Application
fam_doc = rvdb.NewFamilyDocument(template_path)

# Get the family manager
famMgr = fam_doc.FamilyManager

#famName = "TestFamily"

new_file_path = "C:/test_folder/TestfamilyFile.rfa"



with DB.Transaction(fam_doc, "createfamilyfile") as t:
        t.Start()
        
        #this space need some cords to add new solid geomety 
        
        famMgr.AddParameter("material name", DB.BuiltInParameterGroup.PG_MATERIALS, DB.ParameterType.Material, False)
        t.Commit()
if File.Exists(new_file_path):
    File.Delete(new_file_path)
    fam_doc.SaveAs(new_file_path,SaveAsOptions(OverwriteExistingFile=True))
else:
    fam_doc.SaveAs(new_file_path,SaveAsOptions(OverwriteExistingFile=True))
    
fam_doc.Close(False)

Doing so in Native components is pretty straight forward and completes 250 families in a few minutes. Any particular reason you need a custom scripted workflow (especially if you’re not familiar with python & the Revit API)

Thank you Japhy,

The hundreds of layers has different object and need to create each of the .rfa file with material parameter.
That is the reason I am looking for the solution with python.
As you mentioned, I am not an expert guy with python and Revit api, but I like trying to do programming and I think it is good for study for understanding how Revit data structure is.

You can try checking if the node in code option (in the guide below to utilize already existing nodes in your code) has the “New Component Family” and “Add Geometry DirectShape” (which takes geometry and material)

1 Like

Thank you, Mohamed,

You reminded me that I must read web pages entirely.
I will read Rhino.Inside.Revit site thoroughly.

Have a good day!