Compare two versions
Compare a version with the one before it from code, read the categories, the similar changes and a shared move, follow objects to the new version, and turn an upload's changes into BUL.
For an integration that reports what changed in a new upload, re-points its own references to the objects of the new version, or hands the changes on. A compare takes two versions and a BCOL definition and returns every object in one category; the request and result are described in full on reference/bcol#api, and the app does the same in its compare panel (Compare versions).
Before you start#
- A login with the
query:runscope (andmodel:writeto record an upload as a transaction) and read rights on both models. The calls do not check the BCOL feature, which switches on the compare editor in the app. - The version UUIDs (List the tree).
1. Compare#
const previous = await client.fs.previousVersion(latest);
const result = await client.ifc.compareModels({
left: previous.uuid,
right: latest.uuid,
bcol: "compare (attribute.Name, geometry);"
});
for (const category of result.categories) {
console.log(category.label, category.count);
}
// the objects of a category as a QidSet, and the object a pair pairs
const removed = result.objects("top.removed", "left");
const before = result.counterpart(latest.uuid + "-43");
// changes that are alike, and a move most objects share
for (const cluster of result.clusters) {
console.log(cluster.label, result.clusterObjects(cluster.id).size);
}
if (result.alignment) {
console.log("everything moved by", result.alignment.translation);
}Over HTTP it is CompareModels, and GetCompareResult reads a stored result again, page by page. A bcol can be BCOL text, the name of a built-in definition or a stored Compare action, or the definition as JSON.
2. What a version changed, and where objects went#
// what the latest upload changed, and where stored objects went
const [changes] = await client.ifc.versionChanges(latest.uuid, {onlyStored: true});
const mapped = await client.ifc.mapQids({from: previous.uuid, to: latest.uuid, oids: [43, 44]});GetVersionChanges gives the counts of the default compare with the version before, which the server computes on upload; MapQids maps objects of one version to their counterparts in another, for re-pointing issues, notes or saved selections. CompareObjects compares any two objects as one pair, and ExportCompareResult downloads a stored result as Excel, CSV, JSON or BCF.
3. The changes as BUL#
// the upload's changes as BUL, and the upload replaced by a transaction with them
const bul = await client.ifc.getCompareBul(previous.uuid, latest.uuid);
console.log(bul.coverage.in_bul + " of " + bul.coverage.changes + " changes", bul.bul);
if (bul.record.possible) {
await client.ifc.recordUploadAsTransaction(latest.uuid);
}GetCompareBul writes what changed as BUL statements on the older version and says what BUL cannot write; RecordUploadAsTransaction replaces the upload by a transaction with those changes when all of them can be written (explanation/comparing-versions#from-a-compare-back-to-an-edit). The pairs fixed by hand are SetComparePairOverride, ListComparePairOverrides and DeleteComparePairOverride, with GetMatchCandidates for the candidates.
Check#
Compare the latest version of a model with the one before it: the counts of result.categories are the ones the model row in the app shows on its change badge, and versionChanges returns them too.