Creation of Master file with Families based on points

Dear Folks I have a problem that I can’t find the solution so I hope you help me. The task that I want to do is base on the families that are in the project insert those families and if those families can be insert report the families that are not insert

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript import Geometry as Geo

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import FilteredElementCollector 

doc = DocumentManager.Instance.CurrentDBDocument

cat = UnwrapElement(IN[0]) # unwraps the input element to get the Revit category

row_elm = IN[1] # number of elements per row
Lev = UnwrapElement(IN[2]) # level to place elements
HOrient = IN[3] # horizontal orientation

# Get all family types in the specified category
family_types = FilteredElementCollector(doc).OfCategoryId(cat.Id).WhereElementIsElementType().ToElements()

# Calculate the number of rows and columns in the grid
num_types = len(family_types)
num_rows = int(num_types / row_elm) + (num_types % row_elm > 0)

# Calculate the starting point for the grid
x = 0
y = 0
z = Lev.Elevation

# Initialize the lists to store the inserted and non-inserted elements
inserted_els = []
non_inserted_els = []

# Loop through all rows and columns and create the grid points
TransactionManager.Instance.EnsureInTransaction(doc)
for row in range(num_rows):
    # Calculate the y-coordinate of the current row
    y = row * 2    
    for col in range(row_elm):
        index = row * row_elm + col
        if index >= num_types:
            break
        
        # Calculate the coordinates of the current point
        x = col * 2
        
        # Create the family instance at the current point
        family_type = family_types[index]
        family_type.Activate()
        reference = Reference(Lev)
        try:
            symbol_id = family_type.Id
            symbol = doc.GetElement(symbol_id)
            new = doc.Create.NewFamilyInstance(reference, Geo.Point.ByCoordinates(x, y, z).ToXyz(), symbol, Structure.StructuralType.NonStructural)
            
        except AttributeError:
            new = doc.Create.NewFamilyInstance(reference, Geo.Point.ByCoordinates(x, y, z).ToXyz(), family_type)
            inserted_els.append(family_type)
            non_inserted_els.append(family_type)
TransactionManager.Instance.TransactionTaskDone()

# Assign the outputs to the OUT variable
OUT = len(inserted_els), non_inserted_els, family_types

Pr-Z-Families-By_Point-Placing-V3.dyn (11.4 KB)