Classic .NET SDK
The classic, hand-written .NET SDK (the BIM.works_SDK NuGet package) — requirements, the client factory and its login methods, the sub-APIs of a client, IDS validation and IDS checks, exceptions and error codes, and the DocFX reference.
The classic .NET SDK is the task-API client for C# and the other .NET languages: nodes, uploads, queries, IDS checks, scoped tokens and the Actions tree, with async tasks for the long-running calls.
Package#
| Package | BIM.works_SDK on nuget.org, version equal to your BIM.works server (beta releases carry a -b.n suffix) |
| Install | dotnet add package BIM.works_SDK --version <version> or <PackageReference Include="BIM.works_SDK" Version="<version>" /> |
| Namespace | BIM.works_SDK |
| Target | .NET Standard 2.0, so .NET Core 2.0 and later, .NET 5 and later, and .NET Framework 4.6.1 and later |
| JSON | Results are System.Text.Json JsonElements where the shape follows the query |
Client factory#
BimWorksClientFactory(Uri address) is created once; the factory and every BimWorksClient are IDisposable, so wrap them in using.
| Method | Logs in with |
|---|---|
CreateClientWithApiToken(string) |
An API token — the normal way. |
CreateClientWithUsernamePassword(string, string) |
A user's credentials; for testing. |
CreateClientWithAuth(AuthToken) |
An auth token obtained elsewhere. |
CreateAnonymousClient() |
No credentials; a very small set of calls. |
using System;
using System.Text.Json;
using BIM.works_SDK;
using (BimWorksClientFactory factory = new BimWorksClientFactory(new Uri("https://bim.works")))
{
using (BimWorksClient client = factory.CreateClientWithApiToken("<your API token>"))
{
TreeNode root = client.Fs.GetRootNode();
Guid version = Guid.Parse("<version uuid of the first demo model>");
JsonElement results = client.Bim.Query(version, "GET qid, attribute.Name WHERE type = IFCWALL");
Console.WriteLine(results.GetArrayLength());
}
}Sub-APIs#
The client exposes its APIs as public read-only fields:
| Field | Class | What it does |
|---|---|---|
client.Auth |
Auth |
Login and the current token (SetAuthToken, GetAuthToken are on the client itself). |
client.Fs |
Fs |
Nodes and versions: GetRootNode, GetRootNodeUuid, GetNodeByPath, GetNodeByUuid, GetNodeByVersionUuid, ListNodes, ListNodesRecursive, CreateNode, CreateNodeIfNotExists, RenameNode, DeleteNode, DeleteNodeIfExists, UndeleteNode, NodeExists, ListNodeVersions, GetNodeVersion, DeleteNodeVersion, ListNodeErrors. |
client.Upload |
Upload |
UploadModel(UploadBuilder): an AsyncUploadTask whose GetUploadResponse() waits for the new version. |
client.Bim |
Bim |
BQL: Query(Guid version, string bql) for one model, Query2(ISet<Guid> versions, string bql) for several, and Query2(..., Guid queryUuid) for a stored query. |
client.Tokens |
Tokens |
CreateVersionsToken, CreateNodesToken, CreateRecursiveNodeToken, each with a request object and a response holding the AuthToken. The requests take an ISet<Scope> (Scopes); the constructors with a task-name list are obsolete. |
client.Gis |
Gis |
Geo-references. |
client.Actions |
Actions |
The Actions tree: GetRootAction, ListActions, AddFolder, AddQuery (a saved BQL query, run with client.Bim.Query2(versions, queryUuid)), DeleteAction. |
client.Checks |
Checks |
IDS: ValidateIds, RunIdsCheck (the result tree with every checked object), RunIdsCheckSummary (the status and counts per specification) (IDS checks). |
client.Admin |
Admin |
CreateApiToken(nodeUuid, name, scopes, expiresOn) returns the new API token; the variant with ApiTokenCredential.READ/WRITE is the legacy one. |
client.Info |
Info |
Server information. |
client.QueryDelegated and client.QueryWithToken are left over from the retired delegated query and no longer return results: the signed table export they set up carries the deprecated JSON query object (BimQueryV1) and asks for JSON output, while the server's table export takes BQL and writes XLSX, XLS or CSV. To let another client query, give it a versions token with the query:run scope (Create a versions token); client.CreateAsyncTask(request), client.Execute(...) and client.GetTask(uuid) reach any task the SDK has no method for. An AsyncTask is returned by every long-running call; Get() waits for the Response, whose getOutput() is the JSON result. One client can run many uploads at the same time, started from one thread: the synchronous calls only share the thread-safe HttpClient, but the list of running tasks the client keeps is not synchronised (Upload models concurrently from .NET).
Scopes#
A token or API token is restricted to scopes, the Scope enum (Scope.FS_READ, Scope.GEOMETRY_READ, Scope.QUERY_RUN, …); scope.ToWire() gives the server's name ("fs:read") and Scopes.FromWire the reverse. A token never gets a scope the credential that issues it lacks (Create a versions token).
ISet<Scope> scopes = new HashSet<Scope> { Scope.FS_READ, Scope.GEOMETRY_READ, Scope.QUERY_RUN };
AuthToken auth = client.Tokens.CreateVersionsToken(
new CreateVersionsTokenRequest(Collections.CreateHashSet(versionUuid), scopes, TimeSpan.FromMinutes(30))).GetAuth();IDS checks#
client.Checks validates an IDS and runs it on model versions. The IDS is the XML text of an IDS 1.0 document; it travels with every call and nothing is stored on the server.
| Method | Returns |
|---|---|
ValidateIds(ids) |
An IdsValidationResult: IsValid, or the server's reason in Message. Checks that the IDS is well-formed XML and valid against the IDS schema; an invalid IDS is an answer, not an exception. |
RunIdsCheck(version or versions, ids) |
An IdsCheckResult: OverallResult, the result tree (Root, Specifications), and ObjectResults and FailingObjectResults, each with the checked objects (Qid, name, GlobalId, IFC type). Needs checks:run. |
RunIdsCheckSummary(version or versions, ids, specifications = true) |
An IdsCheckSummary: the counts, and per specification its status (PASSED, FAILED, NOT_APPLICABLE, EVALUATION_ERROR) with its counts and its requirements' counts. Not limited in size. Needs checks:run. |
Checks.ReadTooLargeSummary(e) |
The summary a RESULT_TOO_LARGE refusal of RunIdsCheck carries, or null. |
An IDS that cannot run is refused with INVALID_CHECK_DEFINITION.
string ids = File.ReadAllText("specification.ids");
Guid version = Guid.Parse("<version uuid of the first demo model>");
IdsValidationResult validation = client.Checks.ValidateIds(ids);
if (!validation.IsValid)
{
Console.WriteLine(validation.Message);
return;
}
IdsCheckResult result = client.Checks.RunIdsCheck(version, ids);
foreach (CheckResultNode failed in result.FailingObjectResults)
{
foreach (CheckedObject o in failed.Objects)
{
Console.WriteLine($"{o.Type} {o.Name} {o.GlobalId}");
}
}Run an IDS check via the API has the same calls in JavaScript and Java.
Errors#
Every call throws BimWorksException; GetEnum() returns the error constant (BimWorksErrorCode.NODE_NOT_FOUND, BimWorksQueryError.SYNTAX_ERROR, AuthorizationError.NON_AUTHORIZED_SCOPE, …), GetCode() its number and Message the server's message. GetDomain() and GetErrorType() give the server's names ("BimWorksErrorCode", "NODE_NOT_FOUND"); for an error newer than your SDK version GetEnum() is null and those two still tell you what happened. GetUserSafeMessage() is the server's message for an end user, and GetPayload() the data some errors carry (a RESULT_TOO_LARGE refusal its summary). Codes are listed on the error codes page.
try
{
client.Fs.GetNodeByPath("/does/not/exist");
}
catch (BimWorksException e)
{
if (BimWorksErrorCode.NODE_NOT_FOUND.Equals(e.GetEnum())) { /* create it */ } else { throw; }
}An answer the server could not send as a result, an HTTP error status, also arrives as a BimWorksException, with the status as GetCode(). A value the server adds to an enum later (a new discipline, node type or status) reads as a fallback instead of failing the call: UNKNOWN where the SDK's enum has one, FOLDER or MODEL for a node type.
Generated reference#
The .NET API catalogue documents the types and members of BIM.works_SDK, generated from DocFX metadata and XML documentation comments. It shares this site's navigation, styling and search, including signatures, overloads, parameters and inheritance.
Used in#
- .NET — NuGet and prereleases.
- Log in with an API token — the factory and the token.
- Run a BQL query —
client.Bim.Query. - Upload models concurrently from .NET — a batch of uploads checked in at the same time.
- Run an IDS check via the API —
client.Checks.
Pages#
- .NET API catalogueAll SDK types and members generated from the source.