Error: Illegal_Entity_Modification

Hi Guys.
Sorry for my english

I have this recurrent error when I try to create new objects of an own class. The error is not common, but I need reliability.

In summary, I get all the revit areas and regions of the project and extract their Boundaries(I do all the process of Unwrap, and later the ToProtoType), and with these lists of curves I create a customize geometric object(It includes, take these curves and creates polycurves and surfaces, extract points, etc., all based in the Autodesk.DesignScript.Geometry). The code of this class is in an external .py file, with others classes, and also the development of the script.

This script , in general, do some geometric operations, mainly intersection, to find relations between those geometric objects. The average of intersections is about 10.000 - 20.000, mostly between surfaces and curves. And this is my project test, in production this script maybe have to do about 50.000-100.000 intersections.

I want to know if this problem has solution, or is just a limitation of Dynamo or Revit. If it’s the case, what alternative would I have?

Thank you!

Could you post your script?

This is the code of that node. The class “SubunidadPrivada”, take the curves and create a serie of geometry objects like a polycurve, surface,extract poins, and so, all based on the functions of Autodesk.DesignScript.Geometry.
The code of this class is an external .py file.

#Funcion para extraer los segmentos que forman el contorno de un elemento region
def regionSegmentos (region):
regionRvt = UnwrapElement(region)
x = regionRvt.GetBoundaries()
segments =
for t in x:
crvs =
for j in t:
return segments

def nombreNivelRegion(region):
region = UnwrapElement(region)
return doc.GetElement(region.OwnerViewId).GenLevel.Name

#Lista de objetos filled region de revit, que representan el origen de las subunidades privadas
rvt_regiones_subuni_priv = IN[1]

#Creacion de los diferentes tipos de objetos del proyecto
subuni_priv = [SubunidadPrivada(region, regionSegmentos(region), nombreNivelRegion(region)) for region in rvt_regiones_subuni_priv]

#Asigne la salida a la variable OUT.
OUT = subuni_priv

Are you able to share you .py file?