Using Cad-PyRx inside BricsCAD opens up the entire Python ecosystem, making it possible to use advanced optimization libraries that simple LISP cannot match. While Google's OR-Tools is the gold standard for complex optimization, it might be "overkill" unless you have high-level constraints (like weight distribution or pick-pathing). For "fitting the most racks in a room," 2D Bin Packing libraries are often more direct. Here is a breakdown of how you can use Python via PyRx to solve this. 1. Recommended Python Libraries Google OR-Tools (Constraint Programming) Best For: When you have a list of different rack sizes or need to respect complex "rules" (e.g., specific racks must be near certain doors). The Approach: Use the Constraint Solver to define the room as a grid and each rack as a variable that cannot overlap with walls or other racks. Installation: You can install it directly within BricsCAD if PyRx is loaded using: PYPIP install ortools HyperPack (2D Bin Packing) Best For: Purely maximizing the number of racks within a boundary. Why it's better for CAD: It is designed specifically for "Rectangles in a Container." It can handle irregular shapes if you decompose your room into a series of rectangles. Installation: PYPIP install hyperpack Shapely (Geometry Logic) Best For: Calculating if a rack is "inside" or "outside" your polyline boundary. Usage: You will likely use this alongside OR-Tools. Shapely can take your BricsCAD Polyline coordinates and perform a "Point-in-Polygon" test to ensure racks stay 100% inside the room. 2. The PyRx Workflow To use these tools, your Python script in BricsCAD would follow this logical flow: Extract Geometry: Use PyRx (specifically PyDb.Polyline) to get the vertex coordinates of your room boundary. Define Obstacles: Identify "No-Go" zones (pillars, doors) as internal polylines. Run Optimization: Pass these coordinates and your Rack/Aisle dimensions into OR-Tools or HyperPack. Insert Blocks: The solver returns a list of (x,y) coordinates. Your script then loops through these coordinates and uses the PyDb.BlockReference class to insert your "Nestainer" blocks at those exact spots. 3. Example Conceptual Code (PyRx + OR-Tools) This is a simplified look at how you might structure the placement logic within a PyRx command: Python import PyRx as Rx import PyDb as Db import PyGe as Ge from ortools.sat.python import cp_model def PyRxCmd_PackRacks(): # 1. Get the Room Boundary from BricsCAD # (Code to select polyline and get bounding box) room_w, room_h = 20000, 30000 # Example mm rack_w, rack_h = 1350, 1200 aisle = 3000 # 2. Setup OR-Tools Model model = cp_model.CpModel() # Define variables for X and Y positions # model.NewIntVar(...) # 3. Add Constraints # - Racks cannot overlap # - Racks must be > 'aisle' distance from certain lines # 4. Solve and Place # Use PyRx to insert blocks db = Db.curDb() model_space = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForWrite) # Example insertion: # new_rack = Db.BlockReference(Ge.Point3d(x, y, 0), block_id) # model_space.appendAcDbEntity(new_rack) 4. A Key "Pythonic" Shortcut If the "Packing Problem" math is too complex to code from scratch, you can use a Grid-Sampling approach with Python: Generate a dense grid of points across the room. Use Shapely to delete any points that are: Outside the room. Too close to the walls (Clearance). Inside the "Aisle" zones (Rectangles you draw to represent the 6m main lane). Place a rack block at every remaining point. Count: print(f"Total Racks Placed: {len(remaining_points)}") Would you like me to help you write a script that specifically uses Shapely to filter out coordinates that are too close to your walls?