示例#1
0
        Enumerable(string label, IEnumerable val, Autodesk.Revit.DB.Document doc)
            : base(label)
        {
            m_val = val;

            // iterate over the collection and put them in an ArrayList so we can pass on
            // to our Form
            if (m_val != null)
            {
                IEnumerator iter = m_val.GetEnumerator();
                while (iter.MoveNext())
                {
                    var elementId = iter.Current as Autodesk.Revit.DB.ElementId;

                    if (elementId != null && doc != null)
                    {
                        m_objs.Add(doc.GetElement(elementId)); // it's more useful for user to view element rather than element id.
                    }
                    else
                    {
                        m_objs.Add(iter.Current);
                    }
                }
            }
        }
示例#2
0
        private bool retrieveAndRender()
        {
            try
            {
                List <Autodesk.Revit.DB.Document> docs = new List <Autodesk.Revit.DB.Document>();
                foreach (var doc in _docsToProcess)
                {
                    docs.Add(doc.Doc);
                }

                _controller = new Controller(docs, _currentDoc, cbParameter.SelectedItem.ToString(), _config);

                Autodesk.Revit.DB.Parameter p = _currentDoc.ActiveView.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.VIEW_PHASE);
                if (p == null)
                {
                    throw new ApplicationException("No view phase info?");
                }
                string phaseName = _currentDoc.GetElement(p.AsElementId()).Name;

                _rooms = _controller.RetrieveRooms(_currentDoc.ActiveView.GenLevel.Name, phaseName);

                // if this is only the current model, we can do more.

                if (docs[0].Title == _currentDoc.Title)
                {
                    int openCount = Controller.CountOpenSpots(_currentDoc, _currentDoc.ActiveView.GenLevel.Name, phaseName);
                    linkOpenSpots.Text    = "NOTE: There are " + openCount + " open areas in your room model that do not have Room elements. PLEASE REVIEW!";
                    linkOpenSpots.Visible = (openCount > 0);
                }
                else
                {
                    linkOpenSpots.Text    = "NOTE: please ensure that all possible rooms are created, including vertical penetration.";
                    linkOpenSpots.Visible = true;
                }


                IList <RoomObjectSummary> summaries = RoomObjectSummary.Summarize(_rooms, _config);
                dataGridView1.DataSource = null;
                dataGridView1.DataSource = summaries.ToArray();

                return(true);
            }
            catch (ApplicationException aex)
            {
                MessageBox.Show(aex.Message);
            }
            catch (Exception ex)
            {
                var td = new Autodesk.Revit.UI.TaskDialog("Unexpected issue");
                td.MainContent     = ex.GetType().Name + ": " + ex.Message;
                td.ExpandedContent = "Developer Info: " + Environment.NewLine + ex.StackTrace;
                td.Show();
            }
            return(false);
        }
示例#3
0
        internal int GetRoomIdContainingCentroid()
        {
            XYZ    centroid         = GetAptCentroid();
            double distToClosestPnt = 100;
            Room   outRoom          = null;

            foreach (int id in m_iRoomId)
            {
                Room rm = m_doc.GetElement(new ElementId(id)) as Room;
                Autodesk.Revit.DB.LocationPoint currRoomCnt =
                    rm.Location as Autodesk.Revit.DB.LocationPoint;

                if (centroid.DistanceTo(currRoomCnt.Point) < distToClosestPnt)
                {
                    distToClosestPnt = centroid.DistanceTo(currRoomCnt.Point);
                    outRoom          = rm;
                }
            }

            return(outRoom.Id.IntegerValue);
        }
示例#4
0
 ElementSet(string label, ICollection<Autodesk.Revit.DB.ElementId> val, Autodesk.Revit.DB.Document doc)
 : base(label)
 {
     m_val = new Autodesk.Revit.DB.ElementSet();
     foreach(Autodesk.Revit.DB.ElementId elemId in val)
     {
         if(Autodesk.Revit.DB.ElementId.InvalidElementId == elemId)
             continue;
         Autodesk.Revit.DB.Element elem = doc.GetElement(elemId);
         if(null != elem)
             m_val.Insert(elem);
     }
 }
示例#5
0
        static void SetBottomElev(FamilyInstance fi)
        {
            Document doc = fi.Document;

            if (fi.LookupParameter(SO_BTM_ELEV) == null)
            {
                throw new Exception(string.Format("{0} is null", nameof(SO_BTM_ELEV)));
            }
            double elev = ((Autodesk.Revit.DB.Level)doc
                           .GetElement(fi.LevelId)).Elevation + fi.get_Parameter
                              (BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).AsDouble();

            fi.LookupParameter(SO_BTM_ELEV)
            .Set(elev);
        }
示例#6
0
        /// <summary>
        /// This node will set the room tag to the same as the room location.
        /// </summary>
        /// <param name="roomTag">The room tag to set.</param>
        /// <returns name="roomTag">The room tag.</returns>
        /// <search>
        /// roomtag, rhythm
        /// </search>
        public static List <global::Revit.Elements.Element> CenterOnRoomLocation(List <global::Revit.Elements.Element> roomTag)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;

            foreach (var tag in roomTag)
            {
                Autodesk.Revit.DB.Architecture.RoomTag internalRoomTag =
                    (Autodesk.Revit.DB.Architecture.RoomTag)tag.InternalElement;
                Autodesk.DesignScript.Geometry.Point roomLocation =
                    (Autodesk.DesignScript.Geometry.Point)
                    doc.GetElement(internalRoomTag.TaggedLocalRoomId).ToDSType(true).GetLocation();
                TransactionManager.Instance.EnsureInTransaction(doc);
                tag.SetLocation(roomLocation);
                TransactionManager.Instance.TransactionTaskDone();
            }
            return(roomTag);
        }
示例#7
0
        private void SelectCurve_Click(object sender, EventArgs e)
        {
            try
            {
                Autodesk.Revit.DB.Reference  eleR  = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
                Autodesk.Revit.DB.Element    ele   = doc.GetElement(eleR);
                Autodesk.Revit.DB.ModelCurve curve = ele as Autodesk.Revit.DB.ModelCurve;
                crv          = curve.GeometryCurve;
                CurveID.Text = string.Format("Curve: {0}", curve.Id.ToString());
                this.BringToFront();
            }

            catch
            {
                TaskDialog.Show("Error", "Must select a model curve");
                this.BringToFront();
            }
        }
示例#8
0
        internal void HideZeroFieldsMaterialTakeOff(Document doc)
        {
            if (Subschedules.Count == 0 ||
                Subschedules[0].Id == ElementId.InvalidElementId)
            {
                return;
            }

            ViewSchedule       viewSchedule = doc.GetElement(Subschedules[0].Id) as ViewSchedule;
            ScheduleDefinition scheduleDef  = viewSchedule.Definition;
            TableData          tableData    = viewSchedule.GetTableData();
            TableSectionData   tableSecData = tableData
                                              .GetSectionData(Autodesk.Revit.DB.SectionType.Body);
            List <ScheduleField> visibleFields = scheduleDef
                                                 .GetFieldOrder()
                                                 .Select(id => scheduleDef.GetField(id))
                                                 .Where(f => !f.IsHidden)
                                                 .ToList();

            for (int i = tableSecData.FirstColumnNumber; i <= tableSecData.LastColumnNumber; ++i)
            {
                if (tableSecData.GetCellText(tableSecData.FirstRowNumber + 5, i) == "0")
                {
                    double total = 0;

                    for (int j = tableSecData.FirstRowNumber + 5; j <= tableSecData.LastRowNumber; ++j)
                    {
                        double tmp;
                        if (Double.TryParse(tableSecData.GetCellText(j, i), out tmp))
                        {
                            total += tmp;
                        }
                    }

                    if (total == 0)
                    {
                        visibleFields[i].IsHidden = true;
                    }
                }
            }
        }
示例#9
0
        private static void GetGlazingInfo(
            Autodesk.Revit.DB.Face face,
            Autodesk.Revit.DB.Document doc,
            Autodesk.Revit.DB.SpatialElementGeometryResults result,
            double tolerance,
            out List <List <Autodesk.Revit.DB.XYZ> > glazingPoints,
            out List <double> glazingAreas,
            out List <Element> walls)
        {
            glazingPoints = new List <List <Autodesk.Revit.DB.XYZ> >();
            glazingAreas  = new List <double>();
            walls         = new List <Element>();

            if (!(face is Autodesk.Revit.DB.PlanarFace))
            {
                return;
            }

            var boundaryFaces = result.GetBoundaryFaceInfo(face);

            foreach (var bFace in boundaryFaces)
            {
                var bElement = doc.GetElement(bFace.SpatialBoundaryElement.HostElementId);
                if (bElement is Autodesk.Revit.DB.Wall wall)
                {
                    walls.Add(bElement.ToDSType(true));

                    if (wall.WallType.Kind == Autodesk.Revit.DB.WallKind.Curtain)
                    {
                        GetGlazingFromCurtainWall(wall, face, tolerance, ref glazingPoints, ref glazingAreas);
                    }
                    else
                    {
                        GetGlazingFromWindows(wall, face, tolerance, ref glazingPoints, ref glazingAreas);
                    }
                }
            }
        }
        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();
        }
示例#11
0
        public static List <global::Revit.Elements.Element> DropBeamSystem(global::Revit.Elements.Element beamSystem)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //convert input beam system to internal version
            Autodesk.Revit.DB.BeamSystem beamSystemInternal = (Autodesk.Revit.DB.BeamSystem)beamSystem.InternalElement;
            //get beam ids from system
            var beamIdCollection = beamSystemInternal.GetBeamIds();
            //create list for the elements and add the beams to that list.
            List <global::Revit.Elements.Element> members = new List <global::Revit.Elements.Element>(beamIdCollection.Select(id => doc.GetElement(id).ToDSType(true)).ToArray());

            //drop da beam system
            Autodesk.Revit.DB.BeamSystem.DropBeamSystem(beamSystemInternal);

            return(members);
        }
示例#12
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();
        }
示例#13
0
        /// <summary>
        /// This node will retrieve the room that a tag is tagging.
        /// </summary>
        /// <param name="roomTag">The room tag to retrieve elements from.</param>
        /// <returns name="room">The room that is tagged.</returns>
        /// <search>
        /// roomtag, rhythm
        /// </search>
        public static List <global::Revit.Elements.Element> TaggedRoom(List <global::Revit.Elements.Element> roomTag)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //convert room tags to internal representations
            List <global::Autodesk.Revit.DB.Architecture.RoomTag> internalRoomTagList =
                new List <global::Autodesk.Revit.DB.Architecture.RoomTag>(roomTag.Select(tag => (Autodesk.Revit.DB.Architecture.RoomTag)tag.InternalElement));
            //get the tagged rooms
            List <global::Revit.Elements.Element> taggedRoomList =
                new List <global::Revit.Elements.Element>(internalRoomTagList.Select(tag => doc.GetElement(tag.TaggedLocalRoomId).ToDSType(true)));

            return(taggedRoomList);
        }
        public SettingsForm(List <Autodesk.Revit.DB.Category> lineStyles, Autodesk.Revit.DB.Document doc)
        {
            _lineStyles = lineStyles;
            _doc        = doc;
            InitializeComponent();

            // Get current elementIds
            int  hairlineInt      = Properties.Settings.Default.hairlineInt;
            int  thinInt          = Properties.Settings.Default.thinInt;
            int  mediumInt        = Properties.Settings.Default.mediumInt;
            int  thickInt         = Properties.Settings.Default.thickInt;
            bool reloadValuesOnly = Properties.Settings.Default.reloadValuesOnly;

            // Set the checkbox
            contentOnlyCheckBox.IsEnabled  = false;
            contentOnlyCheckBox.Visibility = Visibility.Hidden;
            //contentOnlyCheckBox.IsChecked = reloadValuesOnly;

            // Hairline combobox
            hairLineComboBox.ItemsSource       = _lineStyles;
            hairLineComboBox.DisplayMemberPath = "Name";
            try
            {
                if (hairlineInt != -1)
                {
                    Autodesk.Revit.DB.Element hairlineElem = _doc.GetElement(new Autodesk.Revit.DB.ElementId(hairlineInt));

                    for (int i = 0; i < lineStyles.Count; i++)
                    {
                        Autodesk.Revit.DB.Category cat = lineStyles[i];
                        if (cat.Name.Trim() == hairlineElem.Name.Trim())
                        {
                            hairLineComboBox.SelectedIndex = i;
                            break;
                        }
                    }
                }
                else
                {
                    hairLineComboBox.SelectedIndex = 0;
                }
            }
            catch
            {
                hairLineComboBox.SelectedIndex = 0;
            }

            // Thin Combobox
            thinComboBox.ItemsSource       = _lineStyles;
            thinComboBox.DisplayMemberPath = "Name";
            try
            {
                if (thinInt != -1)
                {
                    Autodesk.Revit.DB.Element thinElem = _doc.GetElement(new Autodesk.Revit.DB.ElementId(thinInt));
                    for (int i = 0; i < lineStyles.Count; i++)
                    {
                        Autodesk.Revit.DB.Category cat = lineStyles[i];
                        if (cat.Name.Trim() == thinElem.Name.Trim())
                        {
                            thinComboBox.SelectedIndex = i;
                            break;
                        }
                        else
                        {
                            thinComboBox.SelectedIndex = 0;
                        }
                    }
                }
                else
                {
                    thinComboBox.SelectedIndex = 0;
                }
            }
            catch
            {
                thinComboBox.SelectedIndex = 0;
            }

            mediumComboBox.ItemsSource       = _lineStyles;
            mediumComboBox.DisplayMemberPath = "Name";
            try
            {
                if (mediumInt != -1)
                {
                    Autodesk.Revit.DB.Element mediumElem = _doc.GetElement(new Autodesk.Revit.DB.ElementId(mediumInt));
                    for (int i = 0; i < lineStyles.Count; i++)
                    {
                        Autodesk.Revit.DB.Category cat = lineStyles[i];
                        if (cat.Name.Trim() == mediumElem.Name.Trim())
                        {
                            mediumComboBox.SelectedIndex = i;
                            break;
                        }
                        else
                        {
                            mediumComboBox.SelectedIndex = 0;
                        }
                    }
                }
                else
                {
                    mediumComboBox.SelectedIndex = 0;
                }
            }
            catch
            {
                mediumComboBox.SelectedIndex = 0;
            }

            thickComboBox.ItemsSource       = _lineStyles;
            thickComboBox.DisplayMemberPath = "Name";
            try
            {
                if (thickInt != -1)
                {
                    Autodesk.Revit.DB.Element thickElem = _doc.GetElement(new Autodesk.Revit.DB.ElementId(thickInt));
                    //Autodesk.Revit.UI.TaskDialog.Show("Test", "Thick ElementName: " + thickElem.Name);
                    for (int i = 0; i < lineStyles.Count; i++)
                    {
                        Autodesk.Revit.DB.Category cat = lineStyles[i];
                        if (cat.Name.Trim() == thickElem.Name.Trim())
                        {
                            thickComboBox.SelectedIndex = i;
                            break;
                        }
                        else
                        {
                            thickComboBox.SelectedIndex = 0;
                        }
                    }
                }
                else
                {
                    thickComboBox.SelectedIndex = 0;
                }
            }
            catch
            {
                thickComboBox.SelectedIndex = 0;
            }
        }
示例#15
0
        public static List <global::Revit.Elements.Element> UGrids(Autodesk.Revit.DB.CurtainGrid curtainGrid)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            //gets U Grid Ids
            ICollection <Autodesk.Revit.DB.ElementId> uGridIds = curtainGrid.GetUGridLineIds();
            //make new list for U grids
            List <global::Revit.Elements.Element> uGrids = new List <global::Revit.Elements.Element>(uGridIds.Select(id => doc.GetElement(id).ToDSType(true)).ToArray());

            return(uGrids);
        }
示例#16
0
        public static Dictionary <string, object> ByWallElement(global::Revit.Elements.Wall curtainWall)
        {
            Autodesk.Revit.DB.Document doc          = DocumentManager.Instance.CurrentDBDocument;
            Autodesk.Revit.DB.Wall     internalWall = (Autodesk.Revit.DB.Wall)curtainWall.InternalElement;
            //obtains internal curtain grid
            Autodesk.Revit.DB.CurtainGrid internalCurtainGrid = internalWall.CurtainGrid;
            //gets U Grid Ids
            ICollection <Autodesk.Revit.DB.ElementId> uGridIds = internalCurtainGrid.GetUGridLineIds();
            //make new list for U grids
            List <global::Revit.Elements.Element> uGrids = new List <global::Revit.Elements.Element>(uGridIds.Select(id => doc.GetElement(id).ToDSType(true)).ToArray());
            //gets V Grid Ids
            ICollection <Autodesk.Revit.DB.ElementId> vGridIds = internalCurtainGrid.GetVGridLineIds();
            //make new list for V grids
            List <global::Revit.Elements.Element> vGrids = new List <global::Revit.Elements.Element>(vGridIds.Select(id => doc.GetElement(id).ToDSType(true)).ToArray());
            //returns the outputs
            var outInfo = new Dictionary <string, object>
            {
                { "curtainGrid", internalCurtainGrid },
                { "uGrids", uGrids },
                { "vGrids", vGrids },
            };

            return(outInfo);
        }