> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ploterr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Define a room

> Give a name, a number and an area to a space.

export const LiveExample = ({path, title = 'Live example', height = 460}) => {
  return <Frame>
      <iframe src={`https://floorkit-examples.ploterr.com/floorkit/${path}?embed=1`} ref={frame => {
    if (!frame || !['localhost', '127.0.0.1'].includes(window.location.hostname)) return;
    const local = `http://localhost:5555/${path}?embed=1`;
    if (frame.src !== local) frame.src = local;
  }} title={title} loading="lazy" allow="fullscreen" style={{
    width: '100%',
    height: `${height}px`,
    border: 0,
    display: 'block'
  }} />
    </Frame>;
};

A room is an outline with a name. Floorkit calculates its area and its perimeter. Use rooms for labels on a plan and for area lists.

<LiveExample path="guides/define-a-room" />

## Before you start

You have a session from [Start a building](/floorkit/guides/start-a-building).

## Write the room

The outline follows the inner faces of the walls. For walls 0.2 metres thick on a 6 by 4 metre outline, the room starts 0.1 metres inside.

```typescript theme={null}
import type { BmSpace, BuildingSession } from '@opengeometry/floorkit';

export const livingRoom: BmSpace = {
  id: 'living-room',
  name: 'Living room',
  number: '01',
  profile: {
    outerRing: [
      [0.1, 0.1],
      [5.9, 0.1],
      [5.9, 3.9],
      [0.1, 3.9],
    ],
  },
};
```

## Add it to the storey

A room is an entry in the `spaces` list of its storey.

```typescript theme={null}
export function addRoom(session: BuildingSession): void {
  session.apply(
    {
      kind: 'add-element',
      buildingId: 'building',
      storeyId: 'ground',
      list: 'spaces',
      element: livingRoom,
    },
    session.revision,
  );
}
```

The `add-element` command adds the room to the list, and the session builds it. You keep the session and its undo history. The command rejects an id that the list has.

## Read the area

After the build, get the room from the session and read its values.

```typescript theme={null}
import { Space } from '@opengeometry/floorkit';

export function roomArea(session: BuildingSession): number | undefined {
  const room = session.currentBuild.elementsById.get('living-room');
  return room instanceof Space ? room.area : undefined;
}
```

## Rules

* You give the outline. Floorkit does not find rooms from walls.
* `area` is in square metres. Holes in the outline are subtracted.
* `show3D: true` shows the room as a translucent volume.

## Next

<CardGroup cols={2}>
  <Card title="Add a storey" icon="layer-group" href="/floorkit/guides/add-a-storey">
    Put a second floor on the building.
  </Card>

  <Card title="Space API" icon="code" href="/floorkit/api/architecture/space">
    See each option of a space.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.