Skip to content

Project Contents ​

Everything inside a project that you can change in the app, you can change through the API: page setup, detection rules, zones, line and ring measurements, annotations and legend positions. Symbols work the same way and are covered in the REST API.

All of it is free. Examples use $API for https://api.plancount.ai/api/v1, $KEY for your key, and $PROJECT and $PDF for a project id and a drawing id. Positions are in page units from the top-left corner of the page, with y growing downward. See Coordinates.

List and batch ​

Each collection has two endpoints:

  • GET /projects/{id}/<collection> reads it and returns the project's stateVersion.
  • POST /projects/{id}/<collection>/batch changes it.

A batch looks like this:

json
{
  "ops": [ { "op": "create", "...": "..." }, { "op": "delete", "id": "..." } ],
  "expectedVersion": 12
}

and answers:

json
{ "stateVersion": 13, "results": [ { "op": "create", "id": "...", "...": "..." }, { "op": "delete", "id": "..." } ] }

The rules that apply to every batch:

  • 1 to 500 operations, applied in order. The answer has one result per operation, in the same order.

  • All or nothing. If any operation is invalid, nothing is applied. The answer is 422 VALIDATION_FAILED and lists every bad operation, not just the first:

    json
    {"error":{"code":"VALIDATION_FAILED","message":"One or more operations are invalid; nothing was applied","details":{"ops":[{"index":0,"code":"OUT_OF_BOUNDS","message":"The whole legend box must lie on the page","details":{"pageWidth":842,"pageHeight":595}}]}}}

    index counts from 0. A batch with no operations, or more than 500, is also 422 VALIDATION_FAILED, with code INVALID_BATCH at index 0. (The symbols batch answers 400 INVALID_REQUEST for the same mistake.)

  • expectedVersion is optional. Send the stateVersion you last read and the batch is refused with 409 VERSION_CONFLICT if the project has changed since, so you never overwrite something you have not seen. The answer carries details.currentVersion. Leave it out to apply regardless.

  • Every successful batch raises stateVersion by 1.

  • Server-made ids. You never choose an id. The server makes one for each created item and returns it in the result.

  • ref lets one batch refer to something it creates. Give a create operation a ref (any short text, unique in the batch), and later operations in the same batch can say { "ref": "that-text" } where an id is expected. A reference to a name that has not been defined yet is UNKNOWN_REF, and a name used twice is DUPLICATE_REF. The linear example below uses ref.

  • Limits only stop growth. A project that is already at a limit can still be edited and have items deleted; it just cannot gain more. The error is LIMIT_REACHED.

  • Open tabs keep up. If the project is open in the app, the tab picks up the change within about 10 seconds while it is visible, once the user is not in the middle of an edit, and merges it with what the user is doing.

Per-operation codes common to every collection: PDF_NOT_IN_PROJECT (the drawing is not in this project), PAGE_OUT_OF_RANGE, OUT_OF_BOUNDS (a shape does not lie on the page), NOT_FOUND (no item with that id), INVALID_COLOR (colours are #rrggbb), TEXT_TOO_LONG, INVALID_VALUE, LIMIT_REACHED, DUPLICATE_REF, UNKNOWN_REF.

Page setup ​

GET /projects/{id}/page-setup lists each drawing with its scale and its pages:

bash
curl -s $API/projects/$PROJECT/page-setup -H "Authorization: Bearer $KEY"
json
{"stateVersion":2,"drawingProfile":"LIGHTING","hiddenLabels":[],"pdfs":[{"pdfId":"7d205b92-8fe6-4e5b-a5de-d08ad552799d","filename":"level1.pdf","orderIndex":0,"scale":{"ratio":100,"unit":"metric","label":"1:100","isDefault":true},"pages":[{"page":1,"width":842,"height":595,"rotation":0,"excluded":false},{"page":2,"width":842,"height":595,"rotation":0,"excluded":false}]}]}

Operations (POST /projects/{id}/page-setup/batch):

OperationFieldsEffect
excludePagespdfId, pages: [n, ...]Leaves pages out of counts, the takeoff and exports
includePagespdfId, pagesCounts the pages again
setScalepdfId, scale: { ratio, unit, label? }Sets the drawing's scale. ratio is a whole number from 1 to 10,000 (100 means 1:100). unit is metric or imperial
clearScalepdfIdGoes back to the default, 1:100 metric
hideLabelslabels: [text, ...]Leaves every symbol with these labels out of the totals
showLabelslabelsCounts them again
bash
curl -s -X POST $API/projects/$PROJECT/page-setup/batch \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"ops":[{"op":"setScale","pdfId":"'$PDF'","scale":{"ratio":100,"unit":"metric"}},{"op":"hideLabels","labels":["S1"]}]}'
json
{"stateVersion":6,"results":[{"op":"setScale","pdfId":"7d205b92-8fe6-4e5b-a5de-d08ad552799d","scale":{"ratio":100,"unit":"metric","label":"1:100","isDefault":false}},{"op":"hideLabels","labels":["S1"],"hidden":true}]}

The scale decides every length and area. A drawing with no scale set is measured at 1:100 metric, and isDefault: true tells you so. Check the scale before trusting a length.

Rules ​

A rule tells detection which text on the drawing is a symbol. GET /projects/{id}/rules lists them in the order they are tried (the first rule whose pattern matches a piece of text takes it), together with the drawing profile:

json
{"stateVersion":1,"drawingProfile":"LIGHTING","rules":[{"id":"lighting","name":"Lighting (L#)","type":"LIGHTING","pattern":"^L\\d+(?:/[A-Z0-9]+)?$","color":"#eab308","enabled":true,"displayLabel":"","kind":"text","serverDetection":"on"}]}

A rule is one of two kinds, shown in kind:

  • text has a pattern (a regular expression, tested against each piece of text on the drawing, ignoring case). Symbols are found automatically.
  • manual has an empty pattern. It never finds anything by itself. You use it for symbols you place by hand.

type is one of LIGHTING, EMERGENCY_LIGHTING, LIGHTING_CONTROL, POWER, FIRE, DATA, SECURITY, MECHANICAL, UNKNOWN. displayLabel is the rule's Plan Label: when it is set, every symbol of the rule shows that label instead of its text.

Operations (POST /projects/{id}/rules/batch):

OperationFieldsEffect
createname, type, and either pattern or match: { mode, value }; optional color, enabled, displayLabel, refAdds a rule. mode is startsWithNumber (matches X1, X2... for value X), startsWith or exact. The server builds the pattern from value as the app's rule form does, without escaping it, so characters such as . and + keep their regular-expression meaning
updateid, any of the same fieldsChanges a rule. Disabling a rule stops it finding symbols
deleteidDeletes the rule and every symbol of that rule, hand-placed ones included. The result says symbolsDeleted
setDrawingProfileprofile, replaceRulesSets the drawing profile (LIGHTING, NETWORK, POWER, FIRE, SECURITY). With replaceRules: true the rules are replaced by the profile's own; symbols placed by hand for rules that no longer exist are kept
bash
curl -s -X POST $API/projects/$PROJECT/rules/batch \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"ops":[{"op":"create","name":"Exit signs (X#)","type":"EMERGENCY_LIGHTING","match":{"mode":"startsWithNumber","value":"X"},"displayLabel":"EXIT"}]}'
json
{"stateVersion":8,"results":[{"op":"create","id":"3fkl3dj6b","rule":{"id":"3fkl3dj6b","name":"Exit signs (X#)","type":"EMERGENCY_LIGHTING","pattern":"^X\\d+$","color":"#22c55e","enabled":true,"displayLabel":"EXIT","kind":"text","serverDetection":"on"}}],"textDetection":{"redetected":true,"drawings":[{"pdfId":"7d205b92-8fe6-4e5b-a5de-d08ad552799d","status":"detected","symbols":9}]}}

A matching change runs detection again ​

When a batch changes what is matched (a rule is added with a pattern, a pattern changes, a text rule is enabled or disabled, a rule with a pattern is deleted, or the profile's rules are replaced), the server runs text detection again on every drawing in the project and stores the result, in the same change. textDetection in the answer says what happened: redetected and, for each drawing, how many symbols were found. Symbols you moved by hand keep their position.

Changes that do not alter matching (name, colour, type, Plan Label) only update the rule's symbols. No drawing is read.

The server writes a drawing's exact detection or nothing. It never leaves a drawing half-detected, so when it cannot do the re-run exactly, the whole batch is refused and nothing is changed:

  • 422 REDETECTION_NOT_POSSIBLE: the rules cannot be run exactly by the server. details.reason says why, and details.ruleIds names the rules where it can. The fix is in the message: usually change or disable those rules.
  • 422 REDETECTION_TOO_LARGE: the project is too large to detect again within one request. Try again with fewer drawings, or make the rule change in the app.
  • 503 PDF_BUSY or 422 PDF_PROCESSING_FAILED with details.retryable: true: the reader was busy or a file could not be read this time. Try the same batch again.

Patterns the server accepts ​

Only patterns the server can run exactly are accepted when you write a rule. Use plain ASCII letters, digits and simple regular-expression syntax: literals, ., ^, $, |, groups, character classes, \d, \w, \s, \b, and repeats such as +, *, ? and {n,m}. Not accepted: backreferences, lookahead and lookbehind, named groups, inline flags, and non-ASCII characters such as Ø. The error codes are:

CodeMeaning
INVALID_PATTERNThe pattern is not a valid regular expression (for example C++)
UNSUPPORTED_PATTERNThe pattern is valid but the server cannot run it. details.reason says why (for example not_ascii, syntax, too_complex)
TEXT_TOO_LONGThe pattern is too long

match is checked the same way: in startsWith mode, value C++ builds the pattern ^C++, which is not valid, so it is refused with INVALID_PATTERN. Use letters and digits in value, or write the pattern yourself and escape what you mean literally.

Each rule in the list shows serverDetection: on when the server can run the pattern, off when it cannot (for example a pattern with Ø, which the app can store), invalid when the pattern is not a valid regular expression (it matches nothing, in the app too), and null for a manual rule with no pattern. An enabled rule marked off, which only the app can create, blocks matching changes through the API until it is changed in the app or disabled.

Run detection again by hand ​

POST /projects/{id}/text-detection with an optional { "pdfId": "..." } detects drawings that have no detected symbols (for example after an upload reported not_run). A drawing that already has detected symbols is left as it is. It is free.

Zones ​

Zones are polygons on one page of one drawing. There are three types, and they behave differently:

TypeWhat it does
INCLUSIONGroups. Lists the symbols inside it, for example lights per control group. It never changes the totals
EXCLUSIONRemoves. Symbols whose centre is inside it are left out of every total. This applies whether or not the zone is shown (visible: false still excludes)
AREAMeasures. Reports the polygon's area in square metres or feet at the drawing's scale. Counts nothing

GET /projects/{id}/zones?pdfId=&page=:

json
{"stateVersion":5,"zones":[{"id":"186olp4bg","pdfId":"7d205b92-8fe6-4e5b-a5de-d08ad552799d","page":1,"name":"Plant room","type":"EXCLUSION","points":[{"x":550,"y":250},{"x":700,"y":250},{"x":700,"y":350},{"x":550,"y":350}],"visible":true,"color":"#ef4444","area":{"squareMeters":18.667824074074073,"value":18.667824074074073,"unit":"m2","formatted":"19 m²","scaleIsDefault":true}}]}

Every zone has an area. value is in the drawing's unit (m2 for metric, ft2 for imperial) and scaleIsDefault says the drawing has no scale of its own.

Operations (POST /projects/{id}/zones/batch):

OperationFields
createpdfId, page, type, points; optional name, color, visible, ref
updateid (or { ref }) and any of name, points, type, color, visible
deleteid (or { ref })

A zone never moves to another drawing or page. Delete it and create a new one. Names default to the app's (Zone 1, Exclude 1, Area 1) and colours to the app's colours. A polygon needs at least 3 points, all on the page, and must enclose an area.

bash
curl -s -X POST $API/projects/$PROJECT/zones/batch \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"ops":[{"op":"create","pdfId":"'$PDF'","page":1,"type":"INCLUSION","name":"Line B","points":[{"x":90,"y":70},{"x":430,"y":70},{"x":430,"y":110},{"x":90,"y":110}]}]}'
json
{"stateVersion":21,"results":[{"op":"create","id":"5k2xq8d1m","zone":{"id":"5k2xq8d1m","pdfId":"7d205b92-8fe6-4e5b-a5de-d08ad552799d","page":1,"name":"Line B","type":"INCLUSION","points":[{"x":90,"y":70},{"x":430,"y":70},{"x":430,"y":110},{"x":90,"y":110}],"visible":true,"color":"#a855f7","area":{"squareMeters":16.925493827160494,"value":16.925493827160494,"unit":"m2","formatted":"17 m²","scaleIsDefault":false}}}]}

The takeoff then lists the three symbols inside Line B while the project total stays the same.

Linear measurement ​

Linear measurement covers lines (cable runs, LED strip, conduit) and rings (circles, for example round duct). It has three kinds of item:

  • A linear rule names what is being measured: name, a short symbol (up to 5 characters, stored in upper case), and unitLength, the length of one unit in metres (a roll, a stick).
  • A line is a path drawn on a page for a rule: a start point and segments, each one STRAIGHT (to) or CURVE (to, cp1, cp2, the two control points of a curve).
  • A ring is a circle on a page for a ring rule: a center and a radius in page units.

Line rules and ring rules ​

A rule is either a line rule or a ring rule (isRingRule: true). They are kept apart: lines go only on line rules and rings only on ring rules. Putting the wrong kind on a rule is RULE_KIND_MISMATCH, and so is changing isRingRule on a rule that already has items.

How length and units are worked out ​

  • A line's length is the length of its path in page units, converted to metres with the drawing's scale. At 1:100, 400 page units is 400 / 72 inches on paper, times 100, times 0.0254, which is 14.11 m. On an imperial drawing, lengths are also given in feet.
  • A line rule's units needed is the total length of its lines divided by unitLength, rounded up. Three lines of 14 m on a 5 m rule need ceil(42 / 5) = 9.
  • A ring's diameter is twice its radius in metres, and its length is its circumference. Ring size is always shown as a diameter and ring length as a circumference.
  • For a ring rule, each ring is rounded up to whole units on its own, and the counts are added. Three 6 m rings on a 5 m rule need 2 + 2 + 2 = 6, not 4.

The values are the same ones the app shows and the CSV export writes.

GET /projects/{id}/linear?pdfId=&page= returns the rules (each with totals per drawing) and the paths:

json
{"stateVersion":12,"rules":[{"id":"linear-1795783725374-2k0co","name":"LED strip","symbol":"LED","unitLength":5,"color":"#10b981","enabled":true,"displayMode":"length","isRingRule":false,"totals":[{"pdfId":"7d205b92-8fe6-4e5b-a5de-d08ad552799d","unit":"m","pathCount":1,"ringCount":0,"lengthMeters":14.11111111111111,"length":14.11111111111111,"units":3}]}],"paths":[{"id":"linear-1795783725376-227cl5buo","identifier":"LED.1","kind":"path","pdfId":"7d205b92-8fe6-4e5b-a5de-d08ad552799d","page":1,"ruleId":"linear-1795783725374-2k0co","name":null,"start":{"x":100,"y":200},"segments":[{"type":"STRAIGHT","to":{"x":400,"y":200}},{"type":"STRAIGHT","to":{"x":400,"y":300}}],"visible":true,"color":"#10b981","unit":"m","lengthMeters":14.11111111111111,"length":14.11111111111111,"units":3}]}

(Shortened to the line rule and its line.) identifier (LED.1) is the label the app shows, numbered in the order lines were made. When you filter by page, paths is filtered but totals still cover every page of the drawing.

Operations (POST /projects/{id}/linear/batch):

OperationFields
createRulename, symbol; optional unitLength (metres), color, enabled, displayMode, isRingRule, ref
updateRuleid (or { ref }) and any of the same
deleteRuleid. Deletes the rule and all its lines and rings on every drawing (deletedPaths in the result)
createPathpdfId, page, rule (id or { ref }), start, segments; optional name, color, visible, ref
createRingpdfId, page, rule, center, radius; optional name, color, visible, ref
updatePathid, any of start, segments, name, color, visible
updateRingid, any of center, radius, name, color, visible
deletePathid (a line or a ring)

displayMode is unit (show how many units) or length (show the length). One batch can create a rule and the items on it by using ref:

bash
curl -s -X POST $API/projects/$PROJECT/linear/batch \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"ops":[
    {"op":"createRule","ref":"led","name":"LED strip","symbol":"LED","unitLength":5},
    {"op":"createRule","ref":"duct","name":"Round duct","symbol":"RNG","unitLength":2,"isRingRule":true},
    {"op":"createPath","pdfId":"'$PDF'","page":1,"rule":{"ref":"led"},"start":{"x":100,"y":200},
     "segments":[{"type":"STRAIGHT","to":{"x":400,"y":200}},{"type":"STRAIGHT","to":{"x":400,"y":300}}]},
    {"op":"createRing","pdfId":"'$PDF'","page":1,"rule":{"ref":"duct"},"center":{"x":650,"y":450},"radius":40}]}'

The answer has one result per operation. The line's result:

json
{"op":"createPath","id":"linear-1795783725376-227cl5buo","path":{"identifier":"LED.1","kind":"path","lengthMeters":14.11111111111111,"units":3}}

and the ring's:

json
{"op":"createRing","id":"ring-1795783725377-353vjeixo","path":{"identifier":"RNG.1","kind":"ring","lengthMeters":8.866272600131195,"units":5,"diameterMeters":2.8222222222222224}}

(Each result's path also holds the full item; only the measured fields are shown.) The ring's circumference is 8.87 m, so on a 2 m rule it needs 5 units.

Checks: every point (and control point) must be on the page, a line needs at least one segment and a length above zero, a ring's radius must be at least 5 and the whole circle must lie on the page, unitLength is between 0.01 and 10,000 metres, a name has no control characters.

Annotations ​

Annotations are three kinds of box on a page: cloud boxes (a scalloped border, optionally with text), text notes (a sticky note) and highlights (a semi-transparent marker). They appear in the app and in marked-up PDFs.

GET /projects/{id}/annotations?pdfId=&page=:

json
{"stateVersion":13,"cloudBoxes":[{"id":"cloud-11bb0ad7-50bd-4f66-b075-15840cffb0aa","pdfId":"7d205b92-8fe6-4e5b-a5de-d08ad552799d","page":1,"x":80,"y":60,"width":200,"height":60,"color":"#3b82f6","visible":true,"text":"Revised: add two downlights","textAlignH":"center","textAlignV":"middle","fontScale":1}],"textNotes":[],"highlights":[{"id":"highlight-be5f047f-c02b-4b39-82cf-7f849482eb61","pdfId":"7d205b92-8fe6-4e5b-a5de-d08ad552799d","page":1,"x":480,"y":470,"width":120,"height":30,"color":"#fbbf24","name":"Check clash","visible":true}]}

Operations (POST /projects/{id}/annotations/batch):

OperationFields
createkind (cloudBox, textNote or highlight), pdfId, page, x, y, width, height; optional color, name, visible, ref, and for cloud boxes and notes text, textAlignH (left, center, right), textAlignV (top, middle, bottom), fontScale (0.5 to 2)
updatekind, id (or { ref }), any of the same except pdfId and page. name: null removes a name
deletekind, id (or { ref })

A text note needs text. A highlight has no text, alignment or font scale. The whole box must be on the page and at least 4 units wide and high. Default colours are the app's: blue for cloud boxes and notes, yellow for highlights.

bash
curl -s -X POST $API/projects/$PROJECT/annotations/batch \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"ops":[{"op":"create","kind":"cloudBox","pdfId":"'$PDF'","page":1,"x":80,"y":60,"width":200,"height":60,"text":"Revised: add two downlights"}]}'
json
{"stateVersion":13,"results":[{"op":"create","kind":"cloudBox","id":"cloud-11bb0ad7-50bd-4f66-b075-15840cffb0aa"}]}

Legend placement ​

Each page of a drawing has a legend: the colour key that is drawn on the page in the app and in the marked-up PDF. Its placement is a box (x, y, width, height), whether it is visible, and its font size.

GET /projects/{id}/legends?pdfId= lists every page of each drawing. A page whose legend you have not moved shows the default (x: 50, y: 50, width: 220, height: 300, fontSize: 10) with isDefault: true:

json
{"stateVersion":14,"legends":[{"pdfId":"7d205b92-8fe6-4e5b-a5de-d08ad552799d","page":1,"x":600,"y":250,"width":220,"height":300,"visible":true,"fontSize":12,"isDefault":false},{"pdfId":"7d205b92-8fe6-4e5b-a5de-d08ad552799d","page":2,"x":50,"y":50,"width":220,"height":300,"visible":true,"fontSize":10,"isDefault":true}]}

Operations (POST /projects/{id}/legends/batch):

OperationFieldsEffect
setpdfId, page, and any of x, y, width, height, visible, fontSizeChanges only the fields you send, on top of the current placement (or the default)
resetpdfId, pageGoes back to the default placement

width and height must be at least 100, fontSize is a whole number from 6 to 24, and the whole box must lie on the page. A legend that is not visible is left out of the marked-up PDF. The legend box is 300 units high by default, so on a 595-unit page its y must be 295 or less:

bash
curl -s -X POST $API/projects/$PROJECT/legends/batch \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"ops":[{"op":"set","pdfId":"'$PDF'","page":1,"x":600,"y":250,"fontSize":12}]}'
json
{"stateVersion":14,"results":[{"op":"set","legend":{"pdfId":"7d205b92-8fe6-4e5b-a5de-d08ad552799d","page":1,"x":600,"y":250,"width":220,"height":300,"visible":true,"fontSize":12,"isDefault":false}}]}

With y: 340 the same request is refused with OUT_OF_BOUNDS, because the box would run off the bottom of the 595-unit page.

Plan Count User Guide