How-to guide·ChecksJavaScript · Java · .NET

Run an IDS check via the API

Validate an IDS and check one or more versions against it from JavaScript, Java, .NET or the OpenAPI, read the per-object results and the status per specification, and download them as BCF.

This guide runs an IDS against model versions from code. The same check in the browser is Run an IDS check.

Before you start#

You need the IDS as an XML string (IDS 1.0), the Vids of processed versions, and a client with the checks:run scope. A check can take a while on large models: the JavaScript call waits up to ten minutes, the Java task and the .NET call up to an hour.

Steps#

  1. Run the check. Pass the versions and the IDS; one call checks all of them together.

    const factory = new BimWorksClientFactory("https://bim.works");
    const client = await factory.createClientWithApiToken("<your API token>");
    
    const ids = await (await fetch("specification.ids")).text();
    const result = await client.checks.runIdsCheck(["<version uuid of the first demo model>"], ids);
    console.log(result.results.checkResults);
    try (BimWorksClientFactory factory = new BimWorksClientFactory("https://bim.works");
         BimWorksClient client = factory.createClientWithApiToken("<your API token>")) {
    	String ids = Files.readString(Path.of("specification.ids"));
    	Set<UUID> versions = Set.of(UUID.fromString("<version uuid of the first demo model>"));
    
    	ObjectNode result = client.modelChecks.runIdsCheck(ids, versions).executeAsync().get();
    	System.out.println(result.get("results").get("checkResults"));
    }
    using (BimWorksClientFactory factory = new BimWorksClientFactory(new Uri("https://bim.works")))
    using (BimWorksClient client = factory.CreateClientWithApiToken("<your API token>"))
    {
        string ids = File.ReadAllText("specification.ids");
        IdsCheckResult result = client.Checks.RunIdsCheck(Guid.Parse("<version uuid of the first demo model>"), ids);
        Console.WriteLine(result.OverallResult);   // ERROR when any object fails
    }
    ADDRESS="https://bim.works"
    IDS=$(jq -Rs . < specification.ids)
    curl -s -X POST "$ADDRESS/openapi/ifc/Check" \
      -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
      -d '{"models": [{"type": "VersionModelIdentifier", "uuid": ""<version uuid of the first demo model>""}], "ids": '"$IDS"'}'
  2. Read the result. The response has two members:

    • modelMapping — the model UUID of each checked version, keyed by version UUID; results refer to objects by Qid.
    • results.checkResults — the result tree. Its results array holds one ModelChecksContainer per IDS specification (with the specification's name and description), and each container's results holds one ObjectCheckResult per applicable object with checkResult (SUCCESS, ERROR, WARNING or INFO), the object's objectInfos[].qid and the evaluation of every requirement. Each container also carries a summary with the counts per outcome. An entry's type field says which of the two it is.
    JavaScript#
    function failed(container, out = []) {
    	for (const entry of container.results) {
    		if (entry.type == "ModelChecksContainer") {
    			failed(entry, out);
    		} else if (entry.type == "ObjectCheckResult" && entry.checkResult == "ERROR") {
    			out.push(...entry.objectInfos.map((info) => info.qid));
    		}
    	}
    	return out;
    }
    const errorQids = failed(result.results.checkResults);

    The .NET SDK reads the tree for you: IdsCheckResult has the tree as CheckResultNodes in Root, one container per specification in Specifications, and the object results in ObjectResults and FailingObjectResults. Each object result names its objects as CheckedObjects, with the Qid, name, GlobalId and IFC type.

    .NET#
    List<string> errorQids = result.FailingObjectResults
        .SelectMany(node => node.Objects)
        .Select(o => o.Qid)
        .ToList();
  3. Or download the results as BCF, one issue per failed object with a viewpoint, to hand to the modeller. The type is "IdsCheck" ("Check3" for a BCL definition).

    const url = await client.checks.downloadCheckResultsAsBcfDirect(["<version uuid of the first demo model>"], "IdsCheck", ids);
    window.open(url);   // a download URL for the .bcf file
    DownloadCheckResultsAsBcfDirect download = client.modelChecks.downloadCheckResultsAsBcfDirect(versions, "IdsCheck", ids);
    download.executeAsync();
    try (OutputStream out = Files.newOutputStream(Path.of("results.bcf"))) {
    	download.downloadTo(out);
    }
    curl -s -X POST "$ADDRESS/openapi/ifc/Check" -H "Authorization: Bearer $TOKEN" \
      -H "Content-Type: application/json" -H "Accept: application/bcf" \
      -d '{"models": [{"type": "VersionModelIdentifier", "uuid": ""<version uuid of the first demo model>""}], "ids": '"$IDS"'}' -o results.bcf

The OpenAPI operation is Check; it takes an ids or a bcl definition and returns JSON or, with Accept: application/bcf, the BCF archive. An IDS that is not valid XML is refused with INVALID_CHECK_DEFINITION (400) before any object is checked; an empty model set is allowed and validates the IDS without checking anything. Identical requests that arrive while the check runs share that run; nothing is stored, so a later call runs the check again.

runIdsCheck returns at most 200,000 object results (one per applicable object and specification; the server setting checks.ids.legacy_max_object_results). A larger result is refused with the error RESULT_TOO_LARGE, whose payload holds the counts per specification. To get only the counts, ask Check for "format": "summary": it answers summary, the counts per outcome, without the object results.

POST/openapi/ifc/CheckCheck reference
Authorization
Bearer <auth token>
Content-Type
application/json
Body
1 2 3 4 5
Authorization: Bearer <auth token>
Content-Type: application/json
Accept: application/json
curl -X POST "$BIMWORKS_URL/openapi/ifc/Check" \
  -H "Authorization: Bearer $BIMWORKS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "models": [{"type": "VersionModelIdentifier", "uuid": BIM_WORKS_FIRST_MODEL}],
  "ids": "<the IDS document as a string>",
  "format": "summary"
}'
Send to see the response

The status of every IDS specification is not in that summary. The task RunCheckSummary with models, input (the IDS) and specifications: true adds it, through the SDKs' low-level client: specifications has one entry per IDS specification, in document order, with its status (PASSED, FAILED, NOT_APPLICABLE or EVALUATION_ERROR), reason, and the numbers of applicable, passing and failing objects.

In .NET that is client.Checks.RunIdsCheckSummary, which has no limit on the number of objects. It returns an IdsCheckSummary with the counts and one IdsSpecificationResult per specification, each with its requirements' counts. When RunIdsCheck is refused with RESULT_TOO_LARGE, Checks.ReadTooLargeSummary(e) reads the same summary from the refusal.

.NET#
IdsCheckSummary summary = client.Checks.RunIdsCheckSummary(Guid.Parse("<version uuid of the first demo model>"), ids);
foreach (IdsSpecificationResult specification in summary.Specifications)
{
    Console.WriteLine($"{specification.Name}: {specification.Status}, {specification.Failing} of {specification.Applicable} failing");
}

Validate an IDS without running it#

The task ValidateAction with main_type: "IDS" and input (the IDS) checks that the IDS is well-formed XML and valid against the IDS 1.0 schema, without a model. It answers null for a valid IDS and refuses an invalid one with VALIDATION_EXCEPTION, whose message names the line and the element. Entity names are not looked up: an entity that is no IFC class applies to no object when the IDS runs. Regular expressions are checked when the IDS runs: an invalid pattern gives an ERROR result titled "IDS validation error" in the run's results.

In .NET, client.Checks.ValidateIds returns an IdsValidationResult. An invalid IDS is an answer, not an exception; other refusals (no login, a missing scope) still throw BimWorksException.

.NET#
IdsValidationResult validation = client.Checks.ValidateIds(ids);
if (!validation.IsValid)
{
    Console.WriteLine(validation.Message);   // e.g. cvc-complex-type.2.4.a: Invalid content was found starting with element ...
}

Check#

Colour the failed objects red in a viewer: objectStateManager.changeColor(errorQids, "#EC4339") marks exactly the objects the BIM.works UI lists under the specification with Show only errors.