Ejemplo n.º 1
0
        public QLMepSystemResolve(MEPSystem _mepSystem)
        {
            id   = _mepSystem.Id.ToString();
            name = _mepSystem.Name;

            mepDomain = GetMepDomain(_mepSystem).ToString();


            //https://thebuildingcoder.typepad.com/blog/2016/06/traversing-and-exporting-all-mep-system-graphs.html
            // to travers mep system from the root
            FamilyInstance root = _mepSystem.BaseEquipment;

            if (root != null && (_mepSystem.GetType() == typeof(MechanicalSystem)))
            {
                // Traverse the system and dump the
                // traversal graph into an XML file

                TraversalTree tree = new TraversalTree(_mepSystem);

                if (tree.Traverse())
                {
                    qlTammTreeNode = new QLTammTreeNodeResolve(JsonSerializer.Deserialize <JsonElement>(tree.DumpToJsonTopDown()));
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Implement this method as an external command for Revit.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application 
        /// which contains data related to the command, 
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application 
        /// which will be displayed if a failure or cancellation is returned by 
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application 
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command. 
        /// A result of Succeeded means that the API external method functioned as expected. 
        /// Cancelled can be used to signify that the user cancelled the external operation 
        /// at some point. Failure should be returned if the application is unable to proceed with 
        /// the operation.</returns>
        public virtual Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData
            , ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                // Verify if the active document is null
                UIDocument activeDoc = commandData.Application.ActiveUIDocument;
                if (activeDoc == null)
                {
                    MessageBox.Show("There's no active document in Revit.", "No Active Document",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return Autodesk.Revit.UI.Result.Failed;
                }

                // Verify the number of selected elements
                SelElementSet selElements = activeDoc.Selection.Elements;
                if (selElements.Size != 1)
                {
                    message = "Please select ONLY one element from current project.";
                    return Autodesk.Revit.UI.Result.Failed;
                }

                // Get the selected element
                Element selectedElement = null;
                foreach (Element element in selElements)
                {
                    selectedElement = element;
                    break;
                }

                // Get the expected mechanical or piping system from selected element
                // Some elements in a non-well-connected system may get lost when traversing
                //the system in the direction of flow; and
                // flow direction of elements in a non-well-connected system may not be right,
                // therefore the sample will only support well-connected system.
                MEPSystem system = ExtractMechanicalOrPipingSystem(selectedElement);
                if (system == null)
                {
                    message = "The selected element does not belong to any well-connected mechanical or piping system. " +
                        "The sample will not support well-connected systems for the following reasons: " +
                        Environment.NewLine +
                        "- Some elements in a non-well-connected system may get lost when traversing the system in the " +
                        "direction of flow" + Environment.NewLine +
                        "- Flow direction of elements in a non-well-connected system may not be right";
                    return Autodesk.Revit.UI.Result.Failed;
                }

                // Traverse the system and dump the traversal into an XML file
                TraversalTree tree = new TraversalTree(activeDoc.Document, system);
                tree.Traverse();
                String fileName;
                fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "traversal.xml");
                tree.DumpIntoXML(fileName);

                return Autodesk.Revit.UI.Result.Succeeded;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Autodesk.Revit.UI.Result.Failed;
            }
        }