> ## 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.

# Add a door

> Put a door in a wall. The wall gets a real opening.

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 door belongs to a wall. You give its position along the wall and its size. Floorkit cuts the opening and adds the frame, the panel and the plan symbol.

<LiveExample path="guides/add-a-door" />

## Before you start

Your building has the room `room-walls` from [Draw a wall](/floorkit/guides/draw-a-wall).

## Add the door

The centre of this door is 2 metres from the first point of the wall, on the first side of the room.

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

export function addDoor(session: BuildingSession): void {
  session.apply(
    {
      kind: 'add-hosted-opening',
      buildingId: 'building',
      storeyId: 'ground',
      wallId: 'room-walls',
      opening: {
        id: 'entry-door',
        kind: 'door',
        offset: 2,
        width: 0.9,
        height: 2.1,
        doorQuadrant: 1,
      },
    },
    session.revision,
  );
}
```

## Set the swing

`doorQuadrant` sets the hinge side and the swing side. Stand at the first point of the wall and look along the wall.

| `doorQuadrant` | Hinge | Swings to your |
| - | - | - |
| `1` | Near jamb, at the smaller `offset` | Left |
| `2` | Far jamb, at the larger `offset` | Left |
| `3` | Near jamb | Right |
| `4` | Far jamb | Right |

`swingAngleDegrees` sets the angle of the open door panel.

## Rules

* `offset`, `width` and `height` are in metres.
* The full door, with its frame, must fit in the wall. It must not overlap a different opening.
* `baseHeight` lifts the threshold above the base of the wall. The default is 0.
* If the door does not fit, `apply` throws an error and the building does not change.

## Move or remove the door

```typescript theme={null}
export function moveDoor(session: BuildingSession): void {
  session.apply(
    {
      kind: 'move-hosted-opening',
      buildingId: 'building',
      storeyId: 'ground',
      wallId: 'room-walls',
      openingId: 'entry-door',
      offset: 3,
    },
    session.revision,
  );
}

export function removeDoor(session: BuildingSession): void {
  session.apply(
    {
      kind: 'remove-hosted-opening',
      buildingId: 'building',
      storeyId: 'ground',
      wallId: 'room-walls',
      openingId: 'entry-door',
    },
    session.revision,
  );
}
```

## Move the door to another wall

`rehost-hosted-opening` takes the door out of its wall and puts it in a different wall of the same storey. `offset` is the distance along the new wall.

```typescript theme={null}
export function moveDoorToWall(session: BuildingSession): void {
  session.apply(
    {
      kind: 'rehost-hosted-opening',
      buildingId: 'building',
      storeyId: 'ground',
      wallId: 'room-walls',
      openingId: 'entry-door',
      toWallId: 'garden-wall',
      offset: 3,
    },
    session.revision,
  );
}
```

The door keeps its size and its data. The old wall has no cut there after the edit, and the new wall has one. If the door does not fit in the new wall, `apply` throws an error and the building does not change.

## Next

<CardGroup cols={2}>
  <Card title="Add a window" icon="window-maximize" href="/floorkit/guides/add-a-window">
    Put a window in the same wall.
  </Card>

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


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