Revit 2023, Floor.Create Problem

In revit 2023, The Api of NewFloor.Create(), change To DB.Floor.Create().
when i using pyrevit and python3 script always raise error as

ArgumentException : The input curve loops cannot compose a valid boundary, that means: the “curveLoops” collection is empty; or some curve loops intersect with each other; or each curve loop is not closed individually; or each curve loop is not planar; or each curve loop is not in a plane parallel to the horizontal(XY) plane; or input curves contain at least one helical curve.

#! python3
from System.Collections.Generic import List
from Autodesk.Revit import DB

# Test.py
doc = __revit__.ActiveUIDocument.Document

def transaction(func):
    def wrapper(*args, **kwargs):
        t = DB.Transaction(doc, 'Create Elements')
        t.Start()
        func(*args, **kwargs)
        t.Commit()

    return wrapper

@transaction
def main():
    level_data = {level.Elevation: level for level in DB.FilteredElementCollector(doc).OfClass(DB.Level)}
    level = level_data[list(level_data.keys())[0]]
    default_floor_type = DB.Floor.GetDefaultFloorType(doc, False)
    p1 = DB.XYZ(0, 0, 0)
    p2 = DB.XYZ(20, 0, 0)
    p3 = DB.XYZ(20, 15, 0)
    p4 = DB.XYZ(0, 15, 0)
    cloop = DB.CurveLoop()
    cloop.Append(DB.Line.CreateBound(p1, p2))
    cloop.Append(DB.Line.CreateBound(p2, p3))
    cloop.Append(DB.Line.CreateBound(p3, p4))
    cloop.Append(DB.Line.CreateBound(p4, p1))
# if i use the [cloop] / cloop, not the List[DB.CurveLoop](cloop)
# it will raise typeerror : No method matches given arguments for Create: (<class 'Autodesk.Revit.DB.Document'>, <class 'list'>, <class 'Autodesk.Revit.DB.ElementId'>, <class 'Autodesk.Revit.DB.ElementId'>)
    DB.Floor.Create(doc, List[DB.CurveLoop](cloop), default_floor_type, level.Id)

main()

If i use BoundaryValidation.IsValidHorizontalBoundary() method to check the curveloop, it will return False.
someone can fix this problem :frowning: ?

Code seems to check out, so we’re probably dealing with some wrong assumptions. My first guess is that perhaps the creation of the List[DB.CurveLoop] is not acting as expected…
Can you change this

    DB.Floor.Create(doc, List[DB.CurveLoop](cloop), default_floor_type, level.Id)

to this?

curves = List[DB.Curveloop](cloop)
for curveloop in curves:
    for c in curveloop:
        print(c)
DB.Floor.Create(doc, curves , default_floor_type, level.Id)

All I changed is adding some print statements to check if the curveloop list is actually created
You should see an output of 4 lines

Nothing is displayed on pythonshell, only Error msg shown.

curves = List[DB.Curveloop](cloop)

It sees that an empty list is created.

Ok great! That means we’ve probably found the culprit. Your curveloop list is empty.
So that probably means that List[DB.CurveLoop](cloop) is not doing what we expect it to do.
Try this instead

curveloops = List[DB.CurveLoop]()
curveloops.Add(cloop)
DB.Floor.Create(doc, curveloops, default_floor_type, level.Id)

It Work!!! Thank you.