Exemplo n.º 1
0
        public void Sync(Document doc)
        {
            var bc = new BuildingGraphClient(@"http://*****:*****@"{ChangeRequest (IsComplete:false){Changes{ParameterName, NewValue, ChangeSource{BIMRevitElementID}}}}";
            var vars  = new Dictionary <string, object>();

            vars.Add("IsComplete", false);

            var task = Task.Run(() => AsyncContext.Run(() => bc.ExecuteQuery(query, vars)));

            //after a lot of issues with thread blocking... this was found to be a working interim solution.
            //see https://msdn.microsoft.com/en-us/magazine/mt238404.aspx for explanation
            //ideally, we wouldn't block Revit's main thread, but in most cases the query will complete very quickly.
            //The majority of time spent is in writing the parameter values with Revit which, due to constraints of the Revit API, can only be synchronous.
            //so not a lot to be gained by making this truly asynchronous

            foreach (dynamic cr in task.Result.ChangeRequest)
            {
                foreach (var cg in cr.Changes)
                {
                    var peramName = cg.ParameterName.Value;
                    var newValue  = cg.NewValue.Value;
                    var elmId     = cg.ChangeSource.BIMRevitElementID.Value;

                    var elm = doc.GetElement(new ElementId((int)elmId));
                    if (elm == null)
                    {
                        continue;
                    }
                    var param = elm.GetParameters((string)peramName).FirstOrDefault();
                    if (param == null)
                    {
                        continue;
                    }
                    var hlParam = new HLRevitParameter(param);
                    hlParam.Value = newValue;
                }
            }

            var docIdent = HLApps.Revit.Utils.DocUtils.GetDocumentIdent(doc);
            var docVars  = new Dictionary <string, object>();

            docVars.Add("modelIdent", docIdent);
            var modelElementsQuery = @"query($modelIdent:String){
  Model (Identity:$modelIdent){
    Identity
    ModelElements {
      UniqueId
      AbstractElement {
        __typename
        Name
      }
    }
  }
}";

            var modelElementQResult = bc.ExecuteQuery(modelElementsQuery, docVars);
            var model = modelElementQResult.Result.Model;
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            this.Phase = GH_SolutionPhase.Collecting;

            var Query = string.Empty;

            DA.GetData("Query", ref Query);

            var variableNames = new List <string>();

            DA.GetDataList("Variable Names", variableNames);

            var variableValues = new List <object>();

            DA.GetDataList("Variable Values", variableValues);

            var inputVariables = Utils.GHInputsToDictionary(variableNames, variableValues);

            var endpoint = string.Empty;

            DA.GetData("Endpoint", ref endpoint);

            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
            if (_client == null || _client.EndPointUrl != endpoint)
            {
                _client = new BuildingGraphClient(endpoint);
            }
            var result = _client.ExecuteQuery(Query, inputVariables);

            DA.SetData("Result", result);
            DA.IncrementIteration();

            this.Phase = GH_SolutionPhase.Computed;
        }
Exemplo n.º 3
0
        public void QureyModelElements()
        {
            var bc = new BuildingGraphClient(@"http://*****:*****@"query($modelIdent:String){
  Model (Identity:$modelIdent){
    Identity
    ModelElements {
      UniqueId
      AbstractElement {
        __typename
        Name
      }
    }
  }
}";
            var vars  = new Dictionary <string, object>();

            vars.Add("modelIdent", @"8764c510-57b7-44c3-bddf-266d86c26380-0000c160:TestModel.rvt");


            var res = bc.ExecuteQuery(query, vars);

            var models = res.Model;

            Dictionary <string, dynamic> modElmCache = new Dictionary <string, dynamic>();

            if (models != null)
            {
                foreach (var model in models)
                {
                    foreach (var modelElement in model.ModelElements)
                    {
                        var meID = modelElement.UniqueId.Value;
                        if (meID == null)
                        {
                            continue;
                        }
                        if (!modElmCache.ContainsKey(meID))
                        {
                            modElmCache.Add(modelElement.UniqueId.Value, modelElement);
                        }
                        else
                        {
                            //there shouln't be multiple
                            modElmCache[meID] = modelElement;
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void QureyFCuElements()
        {
            var bc = new BuildingGraphClient(@"http://*****:*****@"
query($fcuid:ID!){
 FanCoilUnit (Id:$fcuid){
   Id
   ModelElements{
      Id
      UniqueId
     }
   Space{
        Id
     }
   }
}";
            var vars  = new Dictionary <string, object>();

            vars.Add("fcuid", "68a3e4eb-edcc-4df8-9e5b-bdd13096afa7");


            var res = bc.ExecuteQuery(query, vars);

            if (res.FanCoilUnit != null)
            {
                var fcu = res.FanCoilUnit[0];
                foreach (var modelelemet in fcu.ModelElements)
                {
                    var id = modelelemet.Id;
                }

                if (fcu.Space != null)
                {
                    var spaceId = fcu.Space.Id.Value;
                }
            }
        }
Exemplo n.º 5
0
        public void Write(MEPRevitGraph mepGraph, BuildingGraphMapping clientMapping, Autodesk.Revit.DB.Document rootDoc)
        {
            var track  = new Dictionary <MEPRevitNode, PendingNode>();
            var models = new Dictionary <string, PendingNode>();
            var types  = new Dictionary <string, PendingNode>();
            var levels = new Dictionary <string, PendingNode>();

            var rootModelNode  = new Model.RevitModel();
            var rootModelIdent = DocUtils.GetDocumentIdent(rootDoc);

            rootModelNode.Name = rootDoc.PathName;
            rootModelNode.ExtendedProperties.Add("Identity", rootModelIdent);
            rootModelNode.ExtendedProperties.Add("DateTimeStamp", System.DateTime.Now.ToShortDateString());

            var schema = _gdbClient.GetSchema();

            //gather data from the graph about nodes which already exist
            string dGather = @"query($modelIdent:String){
  Model (Identity:$modelIdent){
    Identity
    ModelElements {
      UniqueId
      AbstractElement {
        NodeType: __typename
        Name
        ... on Space{
          Number
          Name
          Area
          Id
        }
        ... on Level{
          Name
          Elevation
        }
      }
    }
  }
}";


            var vars = new Dictionary <string, object>();

            vars.Add("modelIdent", rootModelIdent);
            var res = _gdbClient.ExecuteQuery(dGather, vars);

            var     dbModels    = res.Result.Model;
            dynamic dbRootModel = null;
            Dictionary <string, dynamic> modElmCache = new Dictionary <string, dynamic>();

            if (models != null)
            {
                foreach (var model in models)
                {
                    dbRootModel = model;
                    foreach (var modelElement in dbModels.ModelElements)
                    {
                        var meID = modelElement.UniqueId.Value;
                        if (meID == null)
                        {
                            continue;
                        }
                        if (!modElmCache.ContainsKey(meID))
                        {
                            modElmCache.Add(modelElement.UniqueId.Value, modelElement);
                        }
                        else
                        {
                            //there shouldn't be multiple
                            modElmCache[meID] = modelElement;
                        }
                    }
                }
            }



            var         rootparams = MEPGraphUtils.GetNodePropsWithElementProps(rootModelNode, rootDoc.ProjectInformation, schema, clientMapping, true);
            PendingNode seid       = null;

            if (dbRootModel == null)
            {
                seid = _gdbClient.Push(rootModelNode.Label, rootparams);
            }
            else
            {
                seid = _gdbClient.Push(rootModelNode.Label, rootparams);
            }

            models.Add(rootModelIdent, seid);

            var exprops = new Dictionary <string, object>();

            exprops.Add("test", 1);


            //add the nodes
            foreach (var mepNode in mepGraph.Nodes)
            {
                var npNode      = mepNode.AsAbstractNode;
                var elmAbParams = npNode.GetAllProperties();


                if (!string.IsNullOrEmpty(mepNode.OrginDocIdent))
                {
                    var elmNode  = mepNode.AsElementNode;
                    var elmParms = elmNode.GetAllProperties();

                    var elmdoc = DocUtils.GetDocument(mepNode.OrginDocIdent, rootDoc.Application);
                    var elm    = elmdoc.GetElement(new Autodesk.Revit.DB.ElementId(mepNode.OriginId));
                    if (elm != null)
                    {
                        elmParms    = MEPGraphUtils.GetNodePropsWithElementProps(elmNode, elm, schema, clientMapping, true);
                        elmAbParams = MEPGraphUtils.GetNodePropsWithElementProps(npNode, elm, schema, clientMapping, true);
                    }

                    var atid = _gdbClient.Push(npNode.Label, elmAbParams);
                    track.Add(mepNode, atid);

                    var elmid = _gdbClient.Push(elmNode.Label, elmParms);

                    //relate the element node to the abstracted model node
                    _gdbClient.Relate(atid, elmid, Model.MEPEdgeTypes.REALIZED_BY, null);


                    PendingNode modelId = null;
                    //create up model nodes
                    if (models.ContainsKey(mepNode.OrginDocIdent))
                    {
                        modelId = models[mepNode.OrginDocIdent];
                    }
                    else
                    {
                        var modelNode = new Model.RevitModel();
                        modelNode.ExtendedProperties.Add("Identity", mepNode.OrginDocIdent);
                        var mparams = modelNode.GetAllProperties();

                        var ldoc = DocUtils.GetDocument(mepNode.OrginDocIdent, rootDoc.Application);
                        if (ldoc != null)
                        {
                            mparams = MEPGraphUtils.GetNodePropsWithElementProps(modelNode, ldoc.ProjectInformation, schema, clientMapping, true);
                        }

                        modelId = _gdbClient.Push(modelNode.Label, mparams);
                        models.Add(mepNode.OrginDocIdent, modelId);
                    }

                    var elmedgeProps = MEPGraphUtils.GetEdgeProps(elm);
                    //connect up model node to element node
                    _gdbClient.Relate(elmid, modelId, Model.MEPEdgeTypes.IS_IN, elmedgeProps);

                    Autodesk.Revit.DB.Element typeElm = null;


                    if (elm is Autodesk.Revit.DB.FamilyInstance)
                    {
                        typeElm = (elm as Autodesk.Revit.DB.FamilyInstance).Symbol;
                    }
                    else
                    {
                        var mpType = elm.GetTypeId();
                        typeElm = elmdoc.GetElement(mpType);
                    }



                    //create type nodes
                    if (typeElm != null)
                    {
                        PendingNode tsId = null;
                        if (!types.ContainsKey(typeElm.UniqueId))
                        {
                            var edgeProps = MEPGraphUtils.GetEdgeProps(typeElm);
                            var tsNode    = new Model.ElementType();
                            tsNode.Name = typeElm.Name;
                            var tsprops1 = MEPGraphUtils.GetNodePropsWithElementProps(tsNode, typeElm, schema, clientMapping, true);

                            tsId = _gdbClient.Push(tsNode.Label, tsprops1);
                            types.Add(typeElm.UniqueId, tsId);

                            var tselmNode = new Model.ModelElement();
                            var tsprops2  = MEPGraphUtils.GetNodePropsWithElementProps(tsNode, typeElm, schema, clientMapping, true);
                            var tselmId   = _gdbClient.Push(tselmNode.Label, tsprops2);

                            _gdbClient.Relate(tsId, tselmId, Model.MEPEdgeTypes.REALIZED_BY, exprops);
                            _gdbClient.Relate(tselmId, modelId, Model.MEPEdgeTypes.IS_IN, edgeProps);
                        }
                        else
                        {
                            tsId = types[typeElm.UniqueId];
                        }
                        _gdbClient.Relate(atid, tsId, Model.MEPEdgeTypes.IS_OF, exprops);
                    }

                    //create level nodes
                    var lvl = elmdoc.GetElement(new Autodesk.Revit.DB.ElementId(mepNode.LevelId));
                    if (lvl != null)
                    {
                        var         edgeProps = MEPGraphUtils.GetEdgeProps(lvl);
                        PendingNode lvlId     = null;
                        if (!levels.ContainsKey(lvl.UniqueId))
                        {
                            var lvlNode = new Model.Level();
                            lvlNode.Name = lvl.Name;
                            var lvlprops = MEPGraphUtils.GetNodePropsWithElementProps(lvlNode, lvl, schema, clientMapping, true);
                            lvlId = _gdbClient.Push(lvlNode.Label, lvlprops);
                            levels.Add(lvl.UniqueId, lvlId);
                            _gdbClient.Relate(lvlId, modelId, Model.MEPEdgeTypes.IS_IN, edgeProps);
                        }
                        else
                        {
                            lvlId = levels[lvl.UniqueId];
                        }

                        _gdbClient.Relate(atid, lvlId, Model.MEPEdgeTypes.IS_ON, exprops);
                    }
                }
                else
                {
                    var modelId = _gdbClient.Push(npNode.Label, elmAbParams);
                    track.Add(mepNode, modelId);
                }
            }

            //now add the adjacencies
            foreach (var mepEdge in mepGraph.Edges)
            {
                if (!track.ContainsKey(mepEdge.ThisNode))
                {
                    continue;
                }

                if (!track.ContainsKey(mepEdge.NextNode))
                {
                    continue;
                }

                var nid1 = track[mepEdge.ThisNode];
                var nid2 = track[mepEdge.NextNode];

                var edPArams = new Dictionary <string, object>();
                foreach (var wkvp in mepEdge.Weights)
                {
                    edPArams.Add(wkvp.Key, wkvp.Value);
                }


                _gdbClient.Relate(nid1, nid2, mepEdge.AsNodeEdge.EdgeType, edPArams);
            }


            //add systems and connections
            foreach (var system in mepGraph.Systems)
            {
                var sysNode = new Model.System();

                var syselm    = rootDoc.GetElement(new Autodesk.Revit.DB.ElementId(system));
                var srops     = MEPGraphUtils.GetNodePropsWithElementProps(sysNode, syselm, schema, clientMapping, true);
                var sysNodeId = _gdbClient.Push(sysNode.Label, srops);

                var tselmNode = new Model.ModelElement();
                tselmNode.ExtendedProperties.Add("UniqueId", syselm.UniqueId);

                var emprops = MEPGraphUtils.GetNodePropsWithElementProps(tselmNode, syselm, schema, clientMapping, true);
                var tselmId = _gdbClient.Push(tselmNode.Label, emprops);
                _gdbClient.Relate(sysNodeId, tselmId, Model.MEPEdgeTypes.REALIZED_BY, null);
                var edgeProps = MEPGraphUtils.GetEdgeProps(syselm);
                _gdbClient.Relate(tselmId, seid, Model.MEPEdgeTypes.IS_IN, edgeProps);


                var stypeId = syselm.GetTypeId();
                var typeElm = rootDoc.GetElement(stypeId);
                if (typeElm != null)
                {
                    PendingNode tsId = null;
                    if (!types.ContainsKey(typeElm.UniqueId))
                    {
                        var stypeedgeProps = MEPGraphUtils.GetEdgeProps(typeElm);
                        var tsNode         = new Model.ElementType();
                        tsNode.Name = typeElm.Name;
                        var tsprops1 = MEPGraphUtils.GetNodePropsWithElementProps(tsNode, typeElm, schema, clientMapping, true);

                        tsId = _gdbClient.Push(tsNode.Label, tsprops1);
                        types.Add(typeElm.UniqueId, tsId);

                        var sysTypeelmNode = new Model.ModelElement();
                        var tsprops2       = MEPGraphUtils.GetNodePropsWithElementProps(tsNode, typeElm, schema, clientMapping, true);
                        var sysTypeelmId   = _gdbClient.Push(sysTypeelmNode.Label, tsprops2);

                        _gdbClient.Relate(tsId, sysTypeelmId, Model.MEPEdgeTypes.REALIZED_BY, null);
                        _gdbClient.Relate(tselmId, seid, Model.MEPEdgeTypes.IS_IN, stypeedgeProps);
                    }
                    else
                    {
                        tsId = types[typeElm.UniqueId];
                    }

                    _gdbClient.Relate(sysNodeId, tsId, Model.MEPEdgeTypes.IS_OF, null);
                }

                var snodes = mepGraph.GetAllNodesForSystem(system);
                foreach (var snd in snodes)
                {
                    if (!track.ContainsKey(snd))
                    {
                        continue;
                    }

                    var rid = track[snd];
                    _gdbClient.Relate(rid, sysNodeId, Model.MEPEdgeTypes.ABSTRACTED_BY, null);
                }
            }

            _gdbClient.Commit();
        }
Exemplo n.º 6
0
        public void ElecticalService_AddSocketsToSpaces()
        {
            var client   = new BuildingGraphClient(@"https://*****:*****@"query ($projectName:String, $buidingName: String, $rootDbName: String) {
  Space(filter: {BaseLevel: {Building: {Name: $buidingName, Projects_some: {Name: $projectName}}}}) {
    Id
    Name    
    Number
    Number_of_230V_Single_Sockets_Non_Essential
    Number_of_230V_Twin_Sockets_Non_Essential
    ElectricalOutlets{
      Name
      Is_Essential
      Number_Of_Outlets
    }
    BaseLevel{
      Id
      Abbreviation
    }
    DBPanelElements{
      Name
      Id
      OutgoingCircuits{
        Name
        Id
      }
    }
  }
  rootPanel : DBPanel (Name:$rootDbName){
    Id
    OutgoingCircuits
    {
      Id
      Name
      Number
      levelPanels : Panels{
        Id
        Name
        Level{
          Id
          Name
          Abbreviation
        }
        OutgoingCircuits{
          Id
          Name
          Number
          spacePanels : Panels{
            Id
            Name
            Number_of_Ways
            OutgoingCircuits{
              Id
              Name
              Number
            }
            Space{
              Id
              Name
              Number
            }
          }
        }
      }
    }
  }
}

";

            Dictionary <string, object> vars = new Dictionary <string, object>();

            vars.Add("projectName", project);
            vars.Add("buidingName", building);
            vars.Add("rootDbName", "DB-CORE1");
            var result = client.ExecuteQuery(eleQuery, vars);

            //if (result is Exception) return result;
            //if (result == null) return "Error querying API";
            //if (result.Space == null) return "No spaces found";

            //find root db and build connection tree
            var rootPanelId = string.Empty;
            var levelPanels = new Dictionary <string, PendingNode>();

            if (result.rootPanel != null && result.rootPanel.Count > 0)
            {
                var rootPanel = result.rootPanel[0];
                rootPanelId = rootPanel.Id.Value;
                foreach (var levelCircuit in rootPanel.OutgoingCircuits)
                {
                    //assum each circuit from root to level goes to only one level
                    var    levelPanel = levelCircuit.levelPanels[0];
                    string levelId    = levelPanel.Level.Id.Value;
                    levelPanels.Add(levelId, new PendingNode("Level", levelId));
                }
            }

            PendingNode rootDbNode = null;

            if (string.IsNullOrEmpty(rootPanelId))
            {
                var rootDbVars = new Dictionary <string, object>();
                rootDbVars.Add("Name", "DB-CORE1");
                rootDbNode = client.Push("DBPanel", rootDbVars);
                client.Commit();
            }
            else
            {
                rootDbNode = new PendingNode("DBPanel", rootPanelId);
            }

            foreach (var space in result.Space)
            {
                var no_230SingleNonEssReq   = space.Number_of_230V_Single_Sockets_Non_Essential.Value;
                var no_230TwinNonEssReg     = space.Number_of_230V_Twin_Sockets_Non_Essential.Value;
                var no_230SingleNonEssCount = 0;
                var no_230TwinNonEssCount   = 0;


                if (space.ElectricalOutlets != null)
                {
                    foreach (var elecLoad in space.ElectricalOutlets)
                    {
                        if (elecLoad.Is_Essential == null || !elecLoad.Is_Essential.Value)
                        {
                            if (elecLoad.Number_Of_Outlets != null && elecLoad.Number_Of_Outlets.Value == 1)
                            {
                                no_230SingleNonEssCount = ++no_230SingleNonEssCount;
                            }
                            else if (elecLoad.Number_Of_Outlets != null && elecLoad.Number_Of_Outlets.Value == 2)
                            {
                                no_230TwinNonEssCount = ++no_230TwinNonEssCount;
                            }
                        }
                    }
                }
                var no_230SingleNonEssDelta = no_230SingleNonEssReq - no_230SingleNonEssCount;
                var no_230TwinNonEssDelta   = no_230TwinNonEssReg - no_230TwinNonEssCount;

                var newNodesCirc1 = new List <PendingNode>();
                var newNodesCirc2 = new List <PendingNode>();
                if (no_230SingleNonEssDelta > 0)
                {
                    for (int skc = 0; skc < no_230SingleNonEssDelta; skc++)
                    {
                        var sckTwinVars = new Dictionary <string, object>();
                        sckTwinVars.Add("Name", "Single Non-Essential Socket");
                        sckTwinVars.Add("Is_Essential", false);
                        sckTwinVars.Add("Number_Of_Outlets", 1);
                        sckTwinVars.Add("Apparent_Load", 5);
                        sckTwinVars.Add("Diversity", 0.1);
                        newNodesCirc1.Add(client.Push("ElectricalOutlet", sckTwinVars));
                    }

                    for (int skc = 0; skc < no_230TwinNonEssReg; skc++)
                    {
                        var sckTwinVars = new Dictionary <string, object>();
                        sckTwinVars.Add("Name", "Twin Non-Essential Socket");
                        sckTwinVars.Add("Is_Essential", false);
                        sckTwinVars.Add("Number_Of_Outlets", 2);
                        sckTwinVars.Add("Apparent_Load", 10);
                        sckTwinVars.Add("Diversity", 0.1);
                        newNodesCirc2.Add(client.Push("ElectricalOutlet", sckTwinVars));
                    }
                }

                client.Commit();


                if (newNodesCirc2.Count <= 0 && newNodesCirc2.Count <= 0)
                {
                    return;
                }

                var         spaceNode      = new PendingNode("Space", space.Id.Value);
                PendingNode spacePanelNode = null;
                PendingNode twinCircNode   = null;
                PendingNode singleCircNode = null;
                if (space.DBPanelElements != null && space.DBPanelElements.Count > 1)
                {
                    var spacePanel = space.DBPanelElements[0];
                    spacePanelNode = new PendingNode("DBPanel", spacePanel.Id.Value);

                    foreach (var circ in spacePanel.OutgoingCircuits)
                    {
                        if (circ.Name.Value == "Twin")
                        {
                            twinCircNode = new PendingNode("Circuit", circ.Id.Value);
                        }
                        if (circ.Name.Value == "Single")
                        {
                            singleCircNode = new PendingNode("Circuit", circ.Id.Value);
                        }
                    }
                }
                else
                {
                    var spaceDbVars = new Dictionary <string, object>();
                    spaceDbVars.Add("Name", "DB-" + space.Number.Value);
                    spacePanelNode = client.Push("DBPanel", spaceDbVars);
                    client.Commit();
                    client.Relate(spacePanelNode, spaceNode, Model.MEPEdgeTypes.IS_IN_SPACE, null);
                    client.Commit();
                }

                if (twinCircNode == null)
                {
                    var circVars = new Dictionary <string, object>();
                    circVars.Add("Name", "Twin");
                    circVars.Add("Voltage", 230);
                    twinCircNode = client.Push("Circuit", circVars);
                    client.Commit();
                    client.Relate(spacePanelNode, twinCircNode, Model.MEPEdgeTypes.ELECTRICAL_FLOW_TO, null);
                    client.Commit();
                }

                if (singleCircNode == null)
                {
                    var circVars = new Dictionary <string, object>();
                    circVars.Add("Name", "Single");
                    circVars.Add("Voltage", 230);
                    singleCircNode = client.Push("Circuit", circVars);
                    client.Commit();
                    client.Relate(spacePanelNode, singleCircNode, Model.MEPEdgeTypes.ELECTRICAL_FLOW_TO, null);
                    client.Commit();
                }



                foreach (var outletNode in newNodesCirc1)
                {
                    client.Relate(outletNode, spaceNode, Model.MEPEdgeTypes.IS_IN_SPACE, null);
                    client.Relate(singleCircNode, outletNode, Model.MEPEdgeTypes.ELECTRICAL_FLOW_TO, null);
                }


                foreach (var outletNode in newNodesCirc2)
                {
                    client.Relate(outletNode, spaceNode, Model.MEPEdgeTypes.IS_IN_SPACE, null);
                    client.Relate(twinCircNode, outletNode, Model.MEPEdgeTypes.ELECTRICAL_FLOW_TO, null);
                }

                client.Commit();
                //create db panel for level
                var         levelId     = space.BaseLevel.Id.Value;
                PendingNode levelDbNode = null;
                if (levelPanels.ContainsKey(levelId))
                {
                    levelDbNode = levelPanels[levelId];


                    var spaceCircVars = new Dictionary <string, object>();
                    spaceCircVars.Add("Name", space.Number);
                    var spaceCirc = client.Push("Circuit", spaceCircVars);
                    client.Relate(spaceCirc, spacePanelNode, Model.MEPEdgeTypes.ELECTRICAL_FLOW_TO, null);
                    client.Relate(levelDbNode, spaceCirc, Model.MEPEdgeTypes.ELECTRICAL_FLOW_TO, null);
                    client.Commit();
                }
                else
                {
                    var levelDbVars = new Dictionary <string, object>();
                    levelDbVars.Add("Name", "DB-" + space.BaseLevel.Abbreviation.Value);
                    levelDbNode = client.Push("DBPanel", levelDbVars);
                    client.Relate(levelDbNode, new PendingNode("Level", levelId), Model.MEPEdgeTypes.IS_ON, null);


                    var levelCircVars = new Dictionary <string, object>();
                    levelCircVars.Add("Name", space.BaseLevel.Abbreviation.Value);
                    levelCircVars.Add("Voltage", 230);
                    var levelCirc = client.Push("Circuit", levelCircVars);
                    client.Relate(levelCirc, levelDbNode, Model.MEPEdgeTypes.ELECTRICAL_FLOW_TO, null);
                    client.Relate(rootDbNode, levelCirc, Model.MEPEdgeTypes.ELECTRICAL_FLOW_TO, null);

                    levelPanels.Add(levelId, levelDbNode);
                    client.Commit();

                    var spaceCircVars = new Dictionary <string, object>();
                    spaceCircVars.Add("Name", space.Number);
                    spaceCircVars.Add("Voltage", 230);
                    var spaceCirc = client.Push("Circuit", spaceCircVars);
                    client.Relate(spaceCirc, spacePanelNode, Model.MEPEdgeTypes.ELECTRICAL_FLOW_TO, null);
                    client.Relate(levelDbNode, spaceCirc, Model.MEPEdgeTypes.ELECTRICAL_FLOW_TO, null);
                    client.Commit();
                }
            }

            client.Commit();
        }