- Notifications
You must be signed in to change notification settings - Fork3
A .NET library and a command line utility for converting BCF (Building Collaboration Format) files into json and vice versa.
License
bimspot/bcf-toolkit
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This C# NuGet library allows you to easily build up and convert data into BCFfiles. It gives you a straightforward API to build your BCF objects exactly howyou want in your order.
You can install theBcfToolkit
library via NuGet Package Manager or by addingit to your project's .csproj file.
nuget install Smino.Bcf.Toolkit
To create a BCF Model,BcfBuilder
class can be used. Then, variousfunctions provided by the builder can be used to fulfill the BCF model objects.
Here are some examples:
usingBcfToolkit.Builder.Bcf30;varbuilder=newBcfBuilder();varbcf=builder.AddMarkup(m=>m.SetTitle("Simple title").SetDescription("This is a description").AddLabel("Architecture").SetPriority("Critical").SetTopicType("Clash").SetTopicStatus("Active").AddComment(c=>c.SetComment("This is a comment").SetDate(DateTime.Now).SetAuthor("jimmy@page.com")).AddViewPoint(v=>v.SetPerspectiveCamera(pCam=>pCam.SetCamera(cam=>cam.SetViewPoint(10,10,10))),snapshotData))// Provide a snapshot data here.SetExtensions(e=>e.AddPriority("Critical").AddPriority("Major").AddPriority("Normal").AddPriority("Minor").AddTopicType("Issue").AddTopicType("Fault").AddTopicType("Clash").AddTopicType("Remark").AddTopicLabel("Architecture").AddTopicLabel("Structure").AddTopicLabel("MEP")).SetProject(p=>p.SetProjectId("projectId").SetProjectName("My project")).SetDocumentInfo(dI=>dI.AddDocument(d=>d.SetFileName("document.pdf").SetDescription("This is a document"))).Build();
TheBcfBuilder
class can also consume BCF files as a stream and build up themodel objects.
usingBcfToolkit.Builder.Bcf30;awaitusingvarstream=newFileStream(source,FileMode.Open,FileAccess.Read);varbuilder=newBcfBuilder();varbcf=awaitbuilder.BuildFromStream(stream);
The default builders can be used if the user prefers not to deal with fillingthe required fields. Thebuilder.WithDefaults()
function serves this.However in certain cases the user may need to replace the component IDs of IFCobjects with the actual GUIDs during the build process.
usingBcfToolkit.Builder.Bcf30;varbuilder=newBcfBuilder();varbcf=builder.WithDefaults().Build();
TheBCF
worker is designed to facilitate the conversion ofBCF
files toJSON
and vice versa using predefined workflows. The appropriate workflow isselected based on the file extensions of the source and target. For example, ifthe source file ends with.bcfzip
, theBcfZipToJson
converter is used.
usingBcfToolkit;varworker=newWorker();awaitworker.Convert(source,target);
You can also call specific converters directly for converting betweenBCF
andJSON
.
usingBcfToolkit.Converter.Bcf30;varconverter=newConverter()converter.BcfZipToJson(source,target);
usingBcfToolkit.Converter.Bcf30;varconverter=newConverter()converter.JsonToBcfZip(source,target);
The library supports consumingBCF
archives as streams. The code determinesthe version of the source and delegates the conversion to the appropriate nestedconverter object, converting it toBCF
3.0 as needed.
usingBcfToolkit;awaitusingvarstream=newFileStream(source,FileMode.Open,FileAccess.Read);varworker=newWorker();varbcf=awaitworker.BcfFromStream(stream);
The worker can generate a file stream from a specifiedBCF
object, convertingit to the desired version.
IMPORTANT: The user is responsible for disposing of the stream after use.
usingBcfToolkit;varworker=newWorker();varstream=awaitworker.ToBcf(bcf,BcfVersionEnum.Bcf30);// custom code to use the stream...awaitstream.FlushAsync();
You can define an output stream to which the conversion results will be written.
usingBcfToolkit;varworker=newWorker();varoutputStream=newMemoryStream();worker.ToBcf(bcf,BcfVersionEnum.Bcf30,outputStream);// custom code to use the stream...awaitoutputStream.FlushAsync();
The worker supportsCancellationToken
to allow for the cancellation ofasynchronous operations.
usingBcfToolkit;varworker=newWorker();varoutputStream=newMemoryStream();varsource=newCancellationTokenSource();vartoken=source.Token;worker.ToBcf(bcf,BcfVersionEnum.Bcf30,outputStream,token);// custom code to use the stream...awaitoutputStream.FlushAsync();
The structure of the BCF is perthe standard. There is, however, nostandard for the JSON format other than theBCF API specification.
The naming convention for this converter is taken from the BCF API, but theoutput is opinionated:
There is one JSON for everyMarkup
and within the structure of the informationfollows that of the XML. There are no separate files for screenshots, they arebase64 encoded in the fieldsnapshot_data
of theViewpoint
. The files arenamed using theuuid
of theTopic
within.
|- json |- 2ea98d1e-77ae-467f-bbc9-1aed1c1785f6.json |- 3395f1b1-893f-4ca0-8b7d-c2d17d7a9198.json |- c799e527-a413-43f8-8871-80918a52b0f0.json |- ... |- project.json |- extensions.json |- documents.json |- version.json
The development of the tool is ongoing, the table below shows the currentlycompleted features.
BCF 2.0 | BCF 2.1 | BCF 3.0 | JSON 2.0 | JSON 2.1 | JSON 3.0 | |
---|---|---|---|---|---|---|
BCF 2.0 | ||||||
BCF 2.1 | X | |||||
BCF 3.0 | X | |||||
JSON 2.0 | ||||||
JSON 2.1 | X | |||||
JSON 3.0 | X |
The models for the BCF in-memory representation were auto-created from thelatest XSDs using theXmlSchemaClassGenerator
.
~ dotnet tool install --global dotnet-xscgen~ xscgen -n [namespace] version.xsd
To publish, run the script atdist/publish.sh
.
Code style guide can be found in thebcf-toolkit.sln.DotSettings
file.
About
A .NET library and a command line utility for converting BCF (Building Collaboration Format) files into json and vice versa.