Skip to main content
In Floorkit, the user does not change a mesh. The user sends a command, such as “move this door to 2.5 metres”. A BuildingSession applies the command to the building model and builds the geometry again. This gives you three things for free: a model that is always valid, undo and redo, and a 2D view and a 3D view that always agree.

What a session does with a command

1

Check

The session checks the command and the model that results from it.
2

Build

It builds the new geometry apart from your scene. Walls join again and openings cut again.
3

Publish

If the build is good, the session puts the new geometry below session.root and adds the edit to the history.
If one step fails, the session throws an error and changes nothing. The old model, the old geometry and the history stay as they were.

Send a command

The commands

See each field in the BuildingEditCommand type.

Add, replace and remove

add-element, replace-element and remove-element name a list of the storey: slabs, roofs, spaces, stairs, columns, beams, railings, instances, annotations or roomSeparators. An add gives the new element. A replace gives the elementId and the full new element. A remove gives only the elementId.
add-building-element, replace-building-element and remove-building-element work in the same way on a list of the building: grids or levels. They have a buildingId and no storeyId. An asset is the definition that an instance shows. The asset commands have an assetId, and add-asset and replace-asset have the asset. add-storey has the full storey. remove-storey has its storeyId. replace-storey-settings has the storeyId and the settings: the name, the elevation, the height and the usage together. replace-mass has the mass, or no mass to remove it, and the settings of each storey of the building in the new order. A storey id that stays keeps its elements. add-building has the full building; remove-building has its buildingId. replace-site has the full site, or no site to remove it. The session rejects these commands in these conditions:
  • An add with an id that exists: an element in its list, an asset in the model, a storey in its building.
  • A replace or a remove with an id that does not exist.
  • A replace-element whose new element has a different id.
  • A remove-asset of an asset that an instance uses.
  • A remove-storey of the last storey of a building.
  • A replace-mass that removes a storey that holds an element.
  • An add-building with an id that any object of the model has, and a remove-building of the last building.
  • A replace-site with no site when the model has none.
A session does not know the views of your project. A ProjectManager does, and it also rejects a remove-storey or a replace-mass that removes a storey that a plan view names (storey-in-use), a remove-building of a building that a saved view shows (building-in-use), and a replace-site that removes a site that a view lists (site-in-use).

Wall settings

replace-wall-settings has the wallId and the settings of the wall: thickness, height, material, color, labelName, locationLine, locationOffset, priority, joins, curtain and the property sets, together. A setting that you leave out is removed. The wall keeps its id, its points, its place in the storey and its doors and windows at their offsets. The points of a wall are its location line, so a new thickness keeps that line where it is: with locationLine: 'left', the left face stays and the wall grows to the right. The walls join again after the change. If a door or a window of the storey stops fitting, the session rejects the command with opening-does-not-fit and the fit numbers. The settings can name a wall type with typeRef in place of thickness and material. The wall then takes its thickness from the layers of the type, and flipped reverses the order of the layers. The same location-line and fit rules apply.

Wall types

Wall types are model-level edits: add-wall-type, replace-wall-type and remove-wall-type each make one undo step. Adding or removing a type builds nothing again. Replacing a type builds again only the walls of the storeys that use it, and only the walls whose thickness or join changes get new bodies, so the work of the step does not grow with the size of the building. If a door or a window stops fitting on a wall of the new type, the session rejects the command with opening-does-not-fit and the fit numbers. A type that walls still use cannot be removed: the error wall-type-in-use lists the walls.

Doors and windows in walls

A door, a window or a hole fits on its wall when its whole cut lies between the joints of that wall. Then the wall has a hole for it. Floorkit uses this one fit rule in the build, in the commands and in the drags. add-hosted-opening puts a door or a window at an offset along a wall. move-hosted-opening and rehost-hosted-opening move a door, a window or a hole to an offset. The opening must fit at that offset, or the session rejects the command. The issue opening-does-not-fit of the error gives the offsets where the opening fits and the nearest one. add-hosted-opening and rehost-free-opening also reject an opening over the seam of a T stem; the offsets in the issue then keep clear of the seams. These commands need the geometry kernel: applyBuildingEdit rejects them with resolved-edit-required. It also rejects a move-wall-point of any wall in a storey with hosted openings, because the move can make a door of another wall stop fitting. replace-hosted-opening changes a door, a window or a hole in place: its size, type, hinge and swing, sill, label or property sets. Send the whole opening with the same id, kind and offset; a different kind or offset is rejected. The opening keeps its wall and its place in the list. If it fitted before and does not fit with the new values, the session rejects the command with opening-does-not-fit and the fit numbers. An opening that did not fit before can still change. A saved model can have an opening that does not fit at its offset. Opening the model does not change it. The build draws the opening at its saved offset without a hole, and gives the warning opening-does-not-fit in session.currentBuild.warnings, with the same numbers. To repair it, move the opening to an offset where it fits. An edit does not change an opening that it does not carry. The session rejects an edit that makes an opening that fits stop fitting, or that puts the seam of a T stem under it. An opening that does not fit never blocks an edit. An edit of the wall of an opening carries the opening at the same distance from the start of its segment. A drag on a door in a drawing becomes a move-hosted-opening with resolveViewEditCandidate. Give it the current build. The drag starts at the saved offset, and the door stops at the nearest place where it fits, as in the live editor. A drag that cannot move the door gives the error invalid-drag.

A batch of commands

One change of the user can need several commands, such as a paste of several elements. Put them in one batch. The session applies the commands in order to one model, builds one time and adds one step to the history. One undo takes all of them back.
  • A batch is all or nothing. If one command fails, apply throws the error of that command and the session changes nothing. The message starts with the place of the command, such as command 3 of 6:.
  • If one command has a wrong field or an unknown kind, the code is invalid-command, and the message starts with the place of the command too.
  • Each command works on the result of the commands before it. Thus a batch can add a storey and then add an element to that storey.
  • The batch is judged on the model after its last command. Between two commands the model can be invalid. For example, two move-hosted-opening commands swap two windows: after the first one the windows overlap, and after the second one they do not. The batch lands.
  • The model after the last command gets every check that one command gets: the validation of the whole model, the holes that stairs link to, and the fit of each door, window and void that a command added, moved or changed. If it fails, the message names the command after which the problem stays to the end, such as command 1 of 2: result BuildingModel is invalid: overlaps "w1" …. The issues give the path of the element. If an opening does not fit, the message names the last command that placed or changed that opening.
  • The rules of each command stay the same in a batch. A command whose target is not there, or whose fields are wrong, fails at once. For example, a remove-asset of an asset that an instance uses fails. A command that changes the walls with the kernel, such as move-network-wall-end, keeps its own refusals, and it can refuse an invalid model that it starts from.
  • A move-wall-point and a translate-network-wall of a batch are judged on the end state too. One may take a door off its wall, or make it stop fitting, when a later command moves it, removes it or deletes its wall. A door that no later command places is refused, named, at the command that took it off (command 1 of 2: wall reshape: door "d" would leave wall "w" …). The walls of the end state are resolved, and a door, window or void that fitted before the batch and does not fit after it, or gets the seam of a T joint under it, is refused with its fit numbers at the last command that reshaped a wall of its storey. In a batch, a translate-network-wall with the default openings: 'keep-place' moves the walls in the kernel without their openings, so the kernel never cuts the openings of a middle state.
  • A batch must have one command or more, and it cannot hold a batch. In TypeScript, a batch in a batch does not compile. A list with the type BuildingEditCommand[] does not go into a batch, because that type permits a batch. Give the list the type of its commands, such as ElementListCommand[], or the type BatchCommand['commands'].
  • session.lastEditCommand gives the batch.
  • With a ProjectManager, a batch can also hold commands of the views, sheets and markers, as one step. See Project manager.

The revision number

A session has a revision. It goes up by one after each edit, undo or redo. apply takes the revision that the edit started from. If a different edit came first, the number does not agree and apply throws stale-revision. This stops an old drag from overwriting a newer change. Read the revision when the user starts the action. Do not read it again at the end. A ProjectManager has one revision for its one history: manager.revision and manager.session.revision are always the same number. It goes up by one after each step of the building and after each step of the views, sheets and markers. With a manager, read manager.revision. A building edit that read the revision before a step of a sheet, a view or a marker gets stale-revision, as after any other step. The session sends no event for a step of the views, sheets and markers, so the revision of a session event can go up by more than one.

Undo and redo

A new edit clears the redo list. The history lives in the session and is not saved in the project file.

Keep an edit fast

A host app sends many edits. These rules keep each edit short.
  • Send one command through apply for one change of the user. If the change needs several commands, send one batch. After a command for one slab, roof, room, stair, column, beam, railing, block instance, loose door, loose window or basic shape, Floorkit builds again only that element. The other elements of the storey keep their geometry. After a command for a wall, or for a door or window in a wall, Floorkit joins the walls of the storey again and builds again only the walls, doors and windows that changed. A command that adds a storey or changes its settings builds that storey. A command that changes an asset, or the settings of a storey in a building with a mass, builds the whole building again. A batch builds again what its commands build, one time.
  • Do not call session.snapshot(), manager.snapshot(), manager.save(), saveProject or new BuildingSession(model) at each edit or at each frame of a drag. Each of them copies, writes or builds the whole model. Save on an action of the user or on a timer.
  • To draw a view or export a sheet after an edit, pass the session: drawProjectView(project, viewId, { session }). It reads the live build and does not build the model again. Without { session }, drawProjectView and the exports build a temporary copy of the whole model. Do not draw at each frame of a drag.
  • While a bound plan or 3D editor has a gesture open (a grip drag, a push/pull, a move or a turn), its live preview is not saved, and a draw with { session } throws ProjectDrawingError with code live-edit-open. Keep the drawing that you have, and draw again in the editor’s onGestureEnd. It is called once per press of a grip or a body, after the press ends, moved or not, with kind commit (after the step) or cancel (also for a press with no move), and a draw in it works. ProjectManager.exportSheet and exportPdf refuse in the same way.
  • Do not open a new session for a change that a command covers, as replaceBuilding in Start a building does. A new session builds the whole building and has an empty undo history. Open one to load or replace a whole building.
  • Read the new revision from what apply returns, and read the built element from session.currentBuild.elementsById. Do not keep an element object across a change: read the element again by its id after each change. A changed slab, roof, stair, column, beam, railing, space, basic shape, block or loose door or window is a new object, and Floorkit disposes the old object. A changed wall, and a door, a window or a hole on a wall, can stay the same object with new geometry, or can be a new object. Do not call snapshot() to see the result. snapshot() copies the whole model.
  • After a change, refresh only what the event names. The event of session.subscribe and of manager.subscribe has changed: the ids of the built elements that the step built again, added or removed. An element that the list does not name keeps its object. Read each id from session.currentBuild.elementsById, or from session.currentBuild.modelObjectsById for a basic shape. An id that is in neither map was removed. If changed is absent, the whole building was built again: refresh all.
  • When a step fails, the model and the revision stay as they were. If the failed step already changed built elements, Floorkit builds them again from the saved model and sends one event with the kind restore (the cause restore from the manager) and with changed. Refresh these elements as after a step.

Doors and windows follow their wall

When a wall moves, its doors and windows move with it and the wall is cut again. If an opening that fits stops fitting, Floorkit rejects the edit with opening-does-not-fit. It does not remove or move the opening without telling you. A delete-wall keeps the doors and windows of the wall as loose openings (with openings: 'delete', as the editors’ Delete sends, it deletes them with the wall), and deletes its voids with one void-deleted-with-wall warning for each. See What a delete does to openings.

Interactive editors

You do not have to write commands by hand for pointer actions. Floorkit has two editors that make the commands for you. Give the same session to both, and the plan and the 3D view show the same building. In both editors, Delete removes the selected element in one undo step. An inspector saves the fields of an element with ProjectManager.replaceFields, also as one undo step.

Plan editor

Edit walls and openings in a 2D plan.

3D editor

Edit the same building in your Three.js view.
Last modified on November 28, 2026