1

I would like to create a BIM Collaboration File using the Xbim Toolkit. I'm having difficulty implementing xbimBCF due to my lack of programming experience. I was wondering if there any samples that could help me implement xbimBCF, please? Thank you.

gallagrp
  • 33
  • 4

1 Answers1

1

The best to start is to have a look in tests like this. BFC is very simple schema. You can find documentation, examples and additional information on the official buildingSMART website.

Complete working example:

using System;
using System.Collections.Generic;
using System.IO;
using Xbim.BCF;
using Xbim.BCF.XMLNodes;

namespace CreateBCF
{
    class Program
    {
        static void Main()
        {

            var bcf = new BCF {
                Project = new ProjectXMLFile {
                    Project = new BCFProject {
                        Name = "Sample Project",
                        ProjectId = "0HE7wY7irAE9b6u8RhVcUT"
                    }
                },
                Version = new VersionXMLFile("1.0"),
                Topics = new List<Topic> {
                    new Topic {
                        Markup = new MarkupXMLFile {
                            Header = new BCFHeader {
                                Files = new List<BCFFile> {
                                    new BCFFile {
                                        Date = DateTime.Now,
                                        Filename = "Sample.ifc",
                                        IfcProject = "0HE7wY7irAE9b6u8RhVcUT",
                                        IfcSpatialStructureElement = "3sYjbGNsP7hQb8RP1A$gnO"
                                    }
                                }
                            },
                            Comments = new List<BCFComment> {
                                new BCFComment(
                                    Guid.NewGuid(), 
                                    Guid.NewGuid(), 
                                    "open", 
                                    DateTime.Now, 
                                    "Blaseius Aichel", 
                                    "This needs to be replaced completely!") {
                                    Topic = new AttrIDNode(new Guid("9B981279-4B63-46A0-ABF0-432E27B5ADC0"))
                                }
                            },
                            Topic = new BCFTopic(new Guid("9B981279-4B63-46A0-ABF0-432E27B5ADC0"), "Sample Topic"),
                            Viewpoints = new List<BCFViewpoint> {
                                new BCFViewpoint(Guid.NewGuid()) { Snapshot = "snapshot01.png", Viewpoint = "Base Viewpoint"}
                            }
                        },
                        Snapshots = new List<KeyValuePair<string, byte[]>> {
                            new KeyValuePair<string, byte[]>( "snapshot01.png", File.ReadAllBytes("snapshot01.png"))
                        },
                        Visualization = new VisualizationXMLFile {

                        }
                    }
                }
            };

            using (var output = File.Create("sample.bcf"))
            {
                var data = bcf.Serialize();
                data.CopyTo(output);
                output.Close();
            }
        }
    }
}
Martin Cerny
  • 344
  • 3
  • 9
  • Martin thanks for the reply. I can create the objects needed to create the BCF but i'm not sure how to call 'BCF.Serialize()' to get a stream of the BCFzip file." – gallagrp Mar 30 '17 at 16:39
  • You just need to save the stream to file. You can check [this SO answer](http://stackoverflow.com/a/5515894/6345585) to see how to do it. – Martin Cerny Mar 31 '17 at 08:48
  • Hi Martin - still can't get it to work (due to my inexperience). Just wondering are there any plans to have an example (like ExcelReportExample) on XbimSamples? Thanks for your help though. – gallagrp Apr 04 '17 at 13:59
  • I've just extended the answer to contain complete working example. – Martin Cerny Apr 05 '17 at 16:13
  • Thanks a million Martin. Can adapt it to my needs now. – gallagrp Apr 06 '17 at 11:13