Arrange grids in dynamo in revit 2024

I used the dynamo to correct the arrangement of the grids. Is there another solution, whether vertical or horizontal?