Tutorials BimCraft help Reference

Write an add-on for BimCraft

For add-on authors - where the add-on API is described, the calls BimCraft gives an add-on (the model, edits, pipes and ducts, equipment, fixtures, electrical devices, line sets, assistant tools), developer mode for unsigned add-ons, and how a person allows an add-on's assistant tools.

Written for BimCraft 0.12. The same help is inside the app: press F1.

Where to read

  • The add-on guide and template: the folder, addon.json, testing, packing, review and signing are in the public guide at https://github.com/getcadcraft/addons (docs/GUIDE.md), with a small working add-on to copy.
  • BimCraft's own calls: this topic, and the comment at the top of addons/bimcraft-api.js and addons/bimcraft-api-more.js in BimCraft's code (https://github.com/getcadcraft/bimcraft, folder app/).
  • Comments in the code sometimes name CadCraft's design notes (for example "ADDONS-SPEC § 5.7"). Those notes are internal and not published; everything an author needs is in the guide, the headers and this topic.

Use the API, not the app's modules

Everything below is on the api object your add-on's activate(api) gets. Ask for the version you need in addon.json ("api": "1.6" for the calls marked 1.6). Importing BimCraft's own modules (a host: import or a path into the app) is not part of the API: those modules change from version to version.

AreaCallsSince
The open modelmodel.current, properties, selection, select, onChange, read(fn), write(label, fn), levels, rooms, roomPlans, walls, triangles1.0 to 1.5
Names and propertiesedit.setAttribute, edit.setProperty1.0
Pipes and ductsmep.runs, ports, placeRun, setRunSizes, setRunInstruments, spools, equipment, addPorts1.1 to 1.5
Equipmentmep.equipmentKinds(), mep.placeEquipment({ storey, kind, values, x, y, z, rot, tag }), mep.changeEquipment(guid, changes), mep.removeEquipment([guid])1.6
Refrigerant line setsmep.lineSetFor(kW), mep.placeLineSet(guidA, guidB): the liquid and gas runs between two split or VRF units or refnet joints on one level, fixed to their ports1.6
Plumbing fixturesfixtures.kinds(), fixtures.families(), fixtures.list(), fixtures.place({ storey, family, values, x, y, rot })1.6
Electrical deviceselec.kinds(), elec.devices(), elec.placeDevices([{ storey, kind, at, wall, height, angle, circuit, load, tag }]), elec.changeDevice(guid, changes), elec.removeDevices([guid])1.6
Assistant toolstools.add({ name, title, description, group, inputSchema, run }), tools.granted()1.6
Commands, panels, files, rules, defaultscommands, props.section, ui.panelTab, files.importer and exporter, rules.provide, defaults.provide, problems.source1.0 to 1.5
A building method in New buildingwizard.provide({ id, name, summary, picture?, start(ctx) }): needs the manifest permission wizard; start runs after the building is made and opened (an addition inside 1.6: check typeof api.wizard)1.6

Lengths are millimetres; x, y and at are in the level's plan, heights above the level; storey is a level's GlobalId (model.levels() lists them). Every call that changes the model is one step in Changes, named after your add-on ("MEP maker: pump"), and makes exactly what the person's own tool makes, so ⌘ZCtrl+Z takes it back. A call with a wrong argument throws an error that says what it takes and changes nothing.

Developer mode: try an add-on CadCraft has not signed

Add-ons from the Library are signed by CadCraft. To try your own before it is reviewed:

  1. Open Settings, then Add-ons.
  2. Under Developer mode, tick Also load add-ons that CadCraft has not signed, and reload BimCraft.
  3. Add your package from the browser's console on BimCraft's page: await ccAddons.installPackage({ manifest, files: { 'addon.json': '…', 'main.js': '…' } }), then reload. It is listed with the word "unsigned". Untick the box (and reload) to stop loading unsigned add-ons.

An unsigned add-on runs with the page's full access to your models and files, so switch developer mode on only for add-ons you write or trust, and off again when you are done. Builds from an app store never load unsigned add-ons.

Assistant tools from an add-on

An add-on can offer tools to the assistants and scripts a person allows in Settings › Assistants (see Let an AI assistant work with your model). Each tool is named addon_<your id>_<name>.

  • Nothing is offered until the person allows it: Settings › Add-ons › Assistant tools from add-ons lists every add-on that offers tools, with the tool names, and a box to tick for each.
  • The choice is kept in this browser, for that add-on and that version. When the add-on is updated, or its package changes between signed and unsigned, it is not offered again until the person ticks it again.
  • Unticking takes the tools away at once. Switching the add-on off takes them away too.
  • Settings › Assistants still decides whether assistants may connect at all and what they may do (Read, Change the view and draw, Save, Export): an edit tool from an add-on needs Change the view and draw like any other.
  • tools.granted() tells your add-on whether the person has allowed its tools, so it can say so in its own panel.

See also