コード例 #1
0
        public void Write(MEPRevitGraph mepGraph, 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.Model();
            var rootModelIdent = DocUtils.GetDocumentIdent(rootDoc);

            rootModelNode.Name = rootDoc.PathName;
            rootModelNode.ExtendedProperties.Add("Identity", rootModelIdent);
            rootModelNode.ExtendedProperties.Add("DateTimeStamp", System.DateTime.Now.ToShortDateString());
            var rootparams = MEPGraphUtils.GetNodePropsWithElementProps(rootModelNode, rootDoc.ProjectInformation);
            var seid       = _gdbClient.Push(rootModelNode, rootparams);

            models.Add(rootModelIdent, seid);

            //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);
                        elmAbParams = MEPGraphUtils.GetNodePropsWithElementProps(npNode, elm);
                    }

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

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

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


                    PendingNode modelId = null;
                    //create up model nodes
                    if (models.ContainsKey(mepNode.OrginDocIdent))
                    {
                        modelId = models[mepNode.OrginDocIdent];
                    }
                    else
                    {
                        var modelNode = new Model.Model();
                        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);
                        }

                        modelId = _gdbClient.Push(modelNode, 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.ToString(), 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);

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

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

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

                    //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);
                            lvlId = _gdbClient.Push(lvlNode, lvlprops);
                            levels.Add(lvl.UniqueId, lvlId);
                            _gdbClient.Relate(lvlId, modelId, Model.MEPEdgeTypes.IS_IN.ToString(), edgeProps);
                        }
                        else
                        {
                            lvlId = levels[lvl.UniqueId];
                        }

                        _gdbClient.Relate(atid, lvlId, Model.MEPEdgeTypes.IS_ON.ToString(), null);
                    }
                }
                else
                {
                    var modelId = _gdbClient.Push(npNode, 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.ToString(), 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);
                var sysNodeId = _gdbClient.Push(sysNode, srops);

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

                var emprops = MEPGraphUtils.GetNodePropsWithElementProps(tselmNode, syselm);
                var tselmId = _gdbClient.Push(tselmNode, emprops);
                _gdbClient.Relate(sysNodeId, tselmId, Model.MEPEdgeTypes.REALIZED_BY.ToString(), null);
                var edgeProps = MEPGraphUtils.GetEdgeProps(syselm);
                _gdbClient.Relate(tselmId, seid, Model.MEPEdgeTypes.IS_IN.ToString(), 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);

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

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

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

                    _gdbClient.Relate(sysNodeId, tsId, Model.MEPEdgeTypes.IS_OF.ToString(), 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.ToString(), null);
                }
            }

            AsyncContext.Run(() => _gdbClient.CommitAsync());
            //var task = Task.Run(() => AsyncContext.Run(() => _gdbClient.CommitAsync()));
            //task.Wait();
        }
コード例 #2
0
        public MEPRevitNode(Element elm) : this(string.Empty)
        {
            if (elm == null)
            {
                return;
            }

            _ordId          = elm.Id.IntegerValue;
            OrginIsInLinked = elm.Document.IsLinked;
            OrginDocIdent   = DocUtils.GetDocumentIdent(elm.Document);

            _name = elm.Name;

            if (elm is FamilyInstance)
            {
                var fs = (elm as FamilyInstance);

                if (fs.MEPModel is MechanicalFitting)
                {
                    _name = (fs.MEPModel as MechanicalFitting).PartType.ToString();
                }
                else if (fs.Symbol != null)
                {
#if REVIT2015
                    if (_name != fs.Symbol.FamilyName)
                    {
                        _name = fs.Symbol.FamilyName + " : " + _name;
                    }
#else
                    _name = fs.Symbol.Name;
#endif
                }
            }
            else if (elm is Space)
            {
                var sp = (elm as Space);
                _name = sp.Number + " : " + sp.Name;
            }


            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_MechanicalEquipment)
            {
                _node = new gmdl.Equipment();                                                                              //_sectionType = MEPPathSectionType.Equipment;
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_MEPSpaces)
            {
                _node = new gmdl.Space();                                                                     //_sectionType = MEPPathSectionType.Space;
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctFitting)
            {
                _node = new gmdl.DuctTransition();                                                                       //_sectionType = MEPPathSectionType.Transition;
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_PipeFitting)
            {
                _node = new gmdl.PipeTransition();                                                                       //_sectionType = MEPPathSectionType.Transition;
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_CableTrayFitting)
            {
                _node = new gmdl.CableTrayTransition();
            }
            ;                                                                                                                       // _sectionType = MEPPathSectionType.Transition;

            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctAccessory)
            {
                _node = new gmdl.DuctAccessory();                                                                         //_sectionType = MEPPathSectionType.Accessory;
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_PipeAccessory)
            {
                _node = new gmdl.PipeAccessory();                                                                         //_sectionType = MEPPathSectionType.Accessory;
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_PlumbingFixtures)
            {
                _node = new gmdl.Fixture();
            }

            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctCurves)
            {
                _node = new gmdl.Duct();                                                                      //_sectionType = MEPPathSectionType.Section;
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_FlexDuctCurves)
            {
                _node = new gmdl.Duct();                                                                          // _sectionType = MEPPathSectionType.Section;
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_PipeCurves)
            {
                _node = new gmdl.Pipe();                                                                      // _sectionType = MEPPathSectionType.Section;
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_FlexPipeCurves)
            {
                _node = new gmdl.Pipe();                                                                          // _sectionType = MEPPathSectionType.Section;
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_CableTray)
            {
                _node = new gmdl.CableTray();                                                                     //_sectionType = MEPPathSectionType.Section;
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DuctTerminal)
            {
                _node = new gmdl.Terminal();                                                                        // _sectionType = MEPPathSectionType.Terminal;
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_ElectricalEquipment)
            {
                _node = new gmdl.DBPanel();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_ElectricalFixtures)
            {
                _node = new gmdl.ElectricalLoad();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_LightingDevices)
            {
                _node = new gmdl.Lighting();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_LightingFixtures)
            {
                _node = new gmdl.Lighting();
            }

            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_DataDevices)
            {
                var fi = elm as FamilyInstance;
                if (fi != null && fi.Symbol.FamilyName.StartsWith("HL_IoT_Sensor"))
                {
                    _node = new gmdl.Sensor();
                }
                else if (fi != null && fi.Symbol.FamilyName.StartsWith("HL_IoT_Control"))
                {
                    _node = new gmdl.Control();
                }
                else
                {
                    _node = new gmdl.Data();
                }
            }


            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_SecurityDevices)
            {
                _node = new gmdl.Security();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_NurseCallDevices)
            {
                _node = new gmdl.Safety();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Sprinklers)
            {
                _node = new gmdl.Sprinkler();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_FireAlarmDevices)
            {
                _node = new gmdl.FireAlarm();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_ElectricalCircuit)
            {
                _node = new gmdl.Circuit();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_CommunicationDevices)
            {
                _node = new gmdl.Communications();
            }

            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_CurtainWallPanels)
            {
                _node = new gmdl.Wall();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Walls)
            {
                _node = new gmdl.Wall();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Ceilings)
            {
                _node = new gmdl.Ceiling();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors)
            {
                _node = new gmdl.Door();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Floors)
            {
                _node = new gmdl.Floor();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows)
            {
                _node = new gmdl.Window();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Roofs)
            {
                _node = new gmdl.Roof();
            }
            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Columns)
            {
                _node = new gmdl.Column();
            }

            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Levels)
            {
                _node = new gmdl.Level();
            }

            if (elm.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Furniture)
            {
                _node = new gmdl.Furniture();
            }

            if (elm.Category != null)
            {
                OrginCategoryId   = elm.Category.Id.IntegerValue;
                OrginCategoryName = elm.Category.Name;
            }

            Level flevel = null;
            if (elm is FamilyInstance)
            {
                flevel = elm.Document.GetElement(elm.LevelId) as Level;
            }
            else if (elm is MEPCurve)
            {
                var mepc = elm as MEPCurve;
                flevel = mepc.ReferenceLevel;

                /*
                 * var mplc = mepc.Location as LocationCurve;
                 * var midPoint = (mplc.Curve.GetEndPoint(0) + mplc.Curve.GetEndPoint(1)) / 2;
                 * var levels = HLRevitUtilities.GetElements<Level>(elm.Document).OrderBy(lv => lv.ProjectElevation);
                 *
                 * flevel = levels.LastOrDefault(lv => lv.ProjectElevation < midPoint.Z);*/
            }

            if (flevel != null)
            {
                this.LevelId   = flevel.Id.IntegerValue;
                this.LevelName = flevel.Name;

                //var levels = HLRevitUtilities.GetElements<Level>(elm.Document).OrderBy(lv => lv.ProjectElevation).ToList();
                //var lev = levels.First(l => l.Id.IntegerValue == flevel.Id.IntegerValue);
                //LevelIndex = levels.IndexOf(lev);
            }


            AsElementNode.ExtendedProperties.Add("UniqueId", elm.UniqueId);
            AsElementNode.ExtendedProperties.Add("Name", Name);
            AsElementNode.Name  = this.Name;
            AsAbstractNode.Name = this.Name;
            AsAbstractNode.ExtendedProperties.Add("Category", this.OrginCategoryName);
        }
コード例 #3
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();
        }