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

# Save and reopen

> Save the project as text and open it again later.

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 project is one piece of JSON text. It holds the building model, the views and the sheets. Your app stores the text where it wants: in a database, in a file or in the browser.

<LiveExample path="guides/save-and-reopen" />

## Before you start

You have a project. See [Create a plan view](/floorkit/guides/create-a-plan-view).

## Open the project

A `ProjectManager` holds one open project. It builds the building, and it keeps the views and the sheets. Add `manager.root` to your scene one time.

```typescript theme={null}
import type * as THREE from 'three';
import { ProjectFileError, ProjectManager, type ProjectFile } from '@opengeometry/floorkit';

export function openManager(scene: THREE.Scene, project: ProjectFile): ProjectManager {
  const manager = new ProjectManager(project);
  scene.add(manager.root);
  return manager;
}
```

## Save

`save()` returns the project as text, with the current building.

```typescript theme={null}
export function save(manager: ProjectManager): string {
  return manager.save();
}
```

## Reopen

`ProjectManager.open` reads the text, checks it and builds the building. Open the new manager first. Then remove the old one.

```typescript theme={null}
export function closeManager(scene: THREE.Scene, manager: ProjectManager): void {
  scene.remove(manager.root);
  manager.dispose();
}

export function reopen(scene: THREE.Scene, current: ProjectManager, text: string): ProjectManager {
  const next = ProjectManager.open(text);
  closeManager(scene, current);
  scene.add(next.root);
  return next;
}
```

`dispose()` removes the plan editors of the manager and its session.

## Handle a bad file

`ProjectManager.open` throws `ProjectFileError` for a bad file. The error has a `code` and a `path`.

```typescript theme={null}
export function tryOpen(text: string): ProjectManager | undefined {
  try {
    return ProjectManager.open(text);
  } catch (error) {
    if (error instanceof ProjectFileError) {
      console.error(`${error.code} at ${error.path}`);
      return undefined;
    }
    throw error;
  }
}
```

A file can be valid and have a building that Floorkit cannot build. Then `ProjectManager.open` throws `BmBuildError` or `Error`.

## What the file holds

| In the file | Not in the file |
| - | - |
| The building model | Meshes and other geometry |
| The saved views | The linework of the views |
| The sheets and their viewports | Undo history |

Floorkit makes the things in the right column again when you open the file.

## Rules

* Do not use `JSON.parse` and a type cast in place of `ProjectManager.open`. Only Floorkit checks the file.
* Files from earlier Floorkit versions open. Floorkit writes them in the current format when you save.
* Keep the old manager until the new one is ready. If the new project does not open, the user still has the old one.
* You do not copy the building into the project before you save. `save()` reads the current building.

## Without the manager

If your app makes the `BuildingSession` itself, use `saveProject` and `openProject`. See the [project file API](/floorkit/api/exports/project-file).

## Next

<CardGroup cols={2}>
  <Card title="Export a PDF" icon="file-pdf" href="/floorkit/guides/export-a-pdf">
    Give the sheets to other people.
  </Card>

  <Card title="ProjectManager API" icon="code" href="/floorkit/api/editor/project-manager">
    See each member of the manager and the project commands.
  </Card>
</CardGroup>


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