Help Needed: Fitting Room Boxes into Area using generative design

I’m working on a Dynamo script to find out how many rooms of different sizes can fit into a given area in the most optimal way.

Goal:
Given a total usable area (for example, 3500 sq.ft), I want to fill it efficiently with rooms of 100 sq.ft and 50 sq.ft.

Here’s the workflow I’m using:

  1. Select Revit Room
    → Select Model Element → Element.Geometry
  2. Get Bounding Box and Generate Grid
    → BoundingBox.ByGeometry
    → BoundingBox.Min and BoundingBox.Max
    → Create X and Y ranges
    → Generate points using Point.ByCoordinates
  3. Create and Translate Room Boxes
    → Rectangle.ByWidthLength (example size: 7400mm x 3053mm)
    → Geometry.Translate to place rectangles at grid points
  4. Check if Room Fits in Area
    → Geometry.Contains to check if room box is inside room boundary
  5. Filter valid placements
  6. Optional:
    → Use DirectShape.ByGeometry to visualize rooms in Revit

Issue:
I’m currently stuck at the placement step. The room boxes are not fitting correctly, and I’m not getting a clean combination of different room sizes (100 and 50 sq.ft). I’ve attached an image showing where I’m stuck.


Rooms.dyn (102.8 KB)
Next Step:
I also want to make this script work with Generative Design to explore different room size combinations and placements to maximize area usage.

Any help with fixing the placement issue and setting up the script for Generative Design would be really appreciated.

Thanks in advance!

@_Vijay have you tried using the “Refinery Toolkit” package with Bin Packing?

Not yet. I’ll try that—thanks for the directions

1 Like