/// <summary>
        /// List an electrical equipment instance and insert its data into
        /// the dictionary mapping panel + system name to equipment instances.
        /// </summary>
        static void ListEquipment(
            FamilyInstance elecEqip,
            IDictionary <string, List <Element> > mapPanelAndSystemToEquipment)
        {
            MEPModel            mepModel = elecEqip.MEPModel;
            ElectricalSystemSet systems  = mepModel.ElectricalSystems;
            string s = string.Empty;

            if (null == systems)
            {
                s = Unassigned + ":" + elecEqip.Name;
            }
            else
            {
                Debug.Assert(1 == systems.Size, "expected equipment to belong to one single panel and system");
                foreach (ElectricalSystem system in systems)
                {
                    if (0 < s.Length)
                    {
                        s += ", ";
                    }
                    s += system.PanelName + ":" + system.Name;
                }
            }
            Debug.WriteLine("  " + elecEqip.Name + ": " + s);
            Debug.Assert(!mapPanelAndSystemToEquipment.ContainsKey(s), "expected each panel and system to occur in one equipment element only");
            if (!mapPanelAndSystemToEquipment.ContainsKey(s))
            {
                mapPanelAndSystemToEquipment.Add(s, new List <Element>());
            }
            mapPanelAndSystemToEquipment[s].Add(elecEqip);
        }
Пример #2
0
        private bool IsElementBelongsToCircuit(MEPModel mepModel, ElectricalSystem selectedElectricalSystem)
        {
            ElectricalSystemSet ess = mepModel.ElectricalSystems;

            if (null == ess || !ess.Contains(selectedElectricalSystem))
            {
                return(false);
            }

            return(true);
        }
Пример #3
0
        public CircuitOperationData(ExternalCommandData commandData)
        {
            this.uiDocument = commandData.Application.ActiveUIDocument;
            this.selection  = uiDocument.Selection;

            m_electricalSystemSet   = new ElectricalSystemSet();
            m_electricalSystemItems = new List <ElectricalSystemItem>();

            CollectConnectorInfo();
            CollectCircuitInfo();
        }
Пример #4
0
        /// <summary>
        /// Получения отсортированного списка цепей щита
        /// </summary>
        public static IEnumerable <ElectricalSystem> GetSortedCircuits2(FamilyInstance board, out int circuitNaming)
        {
            int    names_circuits   = board.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_NAMING).AsInteger();
            string nameCircuitSplit = null; //Разделитель обозначения цепей

            switch (names_circuits)
            {
            case 2:
                string namePanel       = board.get_Parameter(BuiltInParameter.RBS_ELEC_PANEL_NAME).AsString();
                string separatorPrefix = board.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_PREFIX_SEPARATOR).AsString();
                nameCircuitSplit = namePanel + separatorPrefix;
                break;

            case 0:
                string prefixCircuits = board.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_PREFIX).AsString();
                separatorPrefix  = board.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_PREFIX_SEPARATOR).AsString();
                nameCircuitSplit = prefixCircuits + separatorPrefix;
                break;

            default:
                TaskDialog.Show("Debug", "Не удалось получить наименование цепей");
                break;
            }
            int lenName = nameCircuitSplit.Length;
            ElectricalSystemSet fullCircuits            = board.MEPModel.ElectricalSystems; //Получение всех цепей щита
            SortedList <int, ElectricalSystem> sortCirc = new SortedList <int, ElectricalSystem>();

            foreach (ElectricalSystem circ in fullCircuits)
            {
                string nameCirc = circ.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_NUMBER).AsString();
                bool   b        = nameCirc.Contains(nameCircuitSplit);
                //info.AppendFormat("\n{0}, {1}", b, circ.Name);
                if (nameCirc.Contains(nameCircuitSplit))
                {
                    string _numStr = nameCirc.Remove(0, lenName);
                    int    index   = _numStr.IndexOf(","); // если группа трёхфазная, то возратится значение > 0
                    string numStr  = (index < 0) ? _numStr : _numStr.Remove(index);

                    int  numCirc;
                    bool success = Int32.TryParse(numStr, out numCirc);
                    if (success)
                    {
                        sortCirc.Add(numCirc, circ);
                    }
                    else
                    {
                        TaskDialog.Show("Debug", $"{circ.Name}");
                    }
                }
            }
            circuitNaming = names_circuits;
            return(sortCirc.Values); //отсортированные цепи
        }
Пример #5
0
        public static IEnumerable <ElectricalSystem> GetSortedCircuits(FamilyInstance board)
        {
            ElectricalSystemSet      fullCircuits = board.MEPModel.ElectricalSystems; //Получение всех цепей щита
            IList <ElectricalSystem> sortCircuit  = new List <ElectricalSystem>();
            string boardName = board.Name;

            foreach (ElectricalSystem circ in fullCircuits)
            {
                string s = circ.PanelName;
                if (s == boardName)
                {
                    sortCircuit.Add(circ);
                }
            }
            return(sortCircuit.OrderBy(x => x.StartSlot));
        }
Пример #6
0
        public static IEnumerable <ElectricalSystem> GetCircuits(FamilyInstance board)
        {
            ElectricalSystemSet fullCircuits = board.MEPModel.ElectricalSystems; //Получение всех цепей щита

            return(fullCircuits.Cast <ElectricalSystem>());
        }
Пример #7
0
        public Result Execute(
            ExternalCommandData commandData,
            ref String message,
            ElementSet elements)
        {
            try
            {
                //
                // dictionary defining tree view info displayed in modeless
                // dialogue mapping parent node to all its circuit elements:
                // null --> root panels
                // panel  --> systems
                // system --> circuit elements, panels, ...
                //
                MapParentToChildren mapParentToChildren           = new MapParentToChildren();
                ElementId           electricalEquipmentCategoryId = ElementId.InvalidElementId;
                List <Element>      equipment;
                {
                    //
                    // run the analysis in its own scope, so the wait cursor
                    // disappears before we display the modeless dialogue:
                    //
                    WaitCursor    waitCursor = new WaitCursor();
                    UIApplication app        = commandData.Application;
                    Document      doc        = app.ActiveUIDocument.Document;
                    ElementId     nullId     = ElementId.InvalidElementId;
                    //
                    // retrieve electrical equipment instances:
                    //
                    equipment = Util.GetElectricalEquipment(doc);
                    int n = equipment.Count;
                    Debug.WriteLine(string.Format("Retrieved {0} electrical equipment instance{1}{2}",
                                                  n, Util.PluralSuffix(n), Util.DotOrColon(n)));
                    Dictionary <string, FamilyInstance> mapPanel = new Dictionary <string, FamilyInstance>();
                    foreach (FamilyInstance e in equipment)
                    {
                        //
                        // ensure that every panel shows up in the list,
                        // even if it does not have children:
                        //
                        mapParentToChildren.Add(e.Id, null);
                        mapPanel[e.Name] = e;
                        MEPModel            mepModel = e.MEPModel;
                        ElectricalSystemSet systems2 = mepModel.ElectricalSystems;
                        string panelAndSystem        = string.Empty;
                        if (null == systems2)
                        {
                            panelAndSystem = CmdElectricalSystemBrowser.Unassigned; // this is a root node
                        }
                        else
                        {
                            Debug.Assert(1 == systems2.Size, "expected equipment to belong to one single panel and system");
                            foreach (ElectricalSystem system in systems2)
                            {
                                if (0 < panelAndSystem.Length)
                                {
                                    panelAndSystem += ", ";
                                }
                                panelAndSystem += system.PanelName + ":" + system.Name + ":" + system.Id.IntegerValue.ToString();
                            }
                        }
                        Debug.WriteLine("  " + Util.ElementDescriptionAndId(e) + " " + panelAndSystem);
                    }
                    //
                    // retrieve electrical systems:
                    // these are also returned by Util.GetCircuitElements(), by the way,
                    // since they have the parameters RBS_ELEC_CIRCUIT_PANEL_PARAM and
                    // RBS_ELEC_CIRCUIT_NUMBER that we use to identify those.
                    //
                    FilteredElementCollector c       = new FilteredElementCollector(doc);
                    IList <Element>          systems = c.OfClass(typeof(ElectricalSystem)).ToElements();
                    n = systems.Count;
                    Debug.WriteLine(string.Format("Retrieved {0} electrical system{1}{2}",
                                                  n, Util.PluralSuffix(n), Util.DotOrColon(n)));
                    foreach (ElectricalSystem system in systems)
                    {
                        string panelName = system.PanelName;
                        if (0 == panelName.Length)
                        {
                            panelName = CmdElectricalSystemBrowser.Unassigned; // will not appear in tree
                        }
                        else
                        {
                            //
                            // todo: is there a more direct way to identify
                            // what panel a system belongs to? this seems error
                            // prone ... what if a panel name occurs multiple times?
                            // how do we identify which one to use?
                            //
                            FamilyInstance panel = mapPanel[panelName];
                            mapParentToChildren.Add(panel.Id, system);
                        }
                        string panelAndSystem = panelName + ":" + system.Name + ":" + system.Id.IntegerValue.ToString();
                        Debug.WriteLine("  " + Util.ElementDescriptionAndId(system) + " " + panelAndSystem);
                        Debug.Assert(system.ConnectorManager.Owner.Id.Equals(system.Id), "expected electrical system's connector manager owner to be system itself");
                    }
                    //
                    // now we have the equipment and systems,
                    // we can build the non-leaf levels of the tree:
                    //
                    foreach (FamilyInstance e in equipment)
                    {
                        MEPModel            mepModel = e.MEPModel;
                        ElectricalSystemSet systems2 = mepModel.ElectricalSystems;
                        if (null == systems2)
                        {
                            mapParentToChildren.Add(nullId, e); // root node
                        }
                        else
                        {
                            Debug.Assert(1 == systems2.Size, "expected equipment to belong to one single panel and system");
                            foreach (ElectricalSystem system in systems2)
                            {
                                mapParentToChildren.Add(system.Id, e);
                            }
                        }
                    }
                    //
                    // list all circuit elements:
                    //
                    BuiltInParameter bipPanel        = BuiltInParameter.RBS_ELEC_CIRCUIT_PANEL_PARAM;
                    BuiltInParameter bipCircuit      = BuiltInParameter.RBS_ELEC_CIRCUIT_NUMBER;
                    IList <Element>  circuitElements = Util.GetCircuitElements(doc);
                    n = circuitElements.Count;
                    Debug.WriteLine(string.Format("Retrieved {0} circuit element{1}...",
                                                  n, Util.PluralSuffix(n)));
                    n = 0;
                    foreach (Element e in circuitElements)
                    {
                        if (e is ElectricalSystem)
                        {
                            ++n;
                        }
                        else
                        {
                            string         circuitName    = e.get_Parameter(bipCircuit).AsString();
                            string         panelName      = e.get_Parameter(bipPanel).AsString();
                            string         key            = panelName + ":" + circuitName;
                            string         panelAndSystem = string.Empty;
                            FamilyInstance inst           = e as FamilyInstance;
                            Debug.Assert(null != inst, "expected all circuit elements to be family instances");
                            MEPModel            mepModel = inst.MEPModel;
                            ElectricalSystemSet systems2 = mepModel.ElectricalSystems;
                            Debug.Assert(null != systems2, "expected circuit element to belong to an electrical system");

                            // this fails in "2341_MEP - 2009 Central.rvt", says martin:
                            //
                            // a circuit element can belong to several systems ... imagine
                            // a piece of telephone equipment which hooks up to a phone line
                            // and also requires power ... so i removed this assertion:
                            //
                            //Debug.Assert( 1 == systems2.Size, "expected circuit element to belong to one single system" );

                            foreach (ElectricalSystem system in systems2)
                            {
                                if (0 < panelAndSystem.Length)
                                {
                                    panelAndSystem += ", ";
                                }
                                panelAndSystem += system.PanelName + ":" + system.Name + ":" + system.Id.IntegerValue.ToString();
                                Debug.Assert(system.PanelName == panelName, "expected same panel name in parameter and electrical system");
                                // this fails in "2341_MEP - 2009 Central.rvt", says martin:
                                //Debug.Assert( system.Name == circuitName, "expected same name in circuit parameter and system" );
                                mapParentToChildren.Add(system.Id, e);
                            }
                            Debug.WriteLine(string.Format("  {0} panel:circuit {1}", Util.ElementDescriptionAndId(e), panelAndSystem));
                        }
                    }
                    Debug.WriteLine(string.Format("{0} circuit element{1} were the electrical systems.",
                                                  n, Util.PluralSuffix(n)));
                    //
                    // get the electrical equipment category id:
                    //
                    Categories categories = doc.Settings.Categories;
                    electricalEquipmentCategoryId = categories.get_Item(BuiltInCategory.OST_ElectricalEquipment).Id;
                }
                //
                // we have assembled the entire required tree view structure, so let us display it:
                //
                CmdInspectElectricalForm2 dialog = new CmdInspectElectricalForm2(mapParentToChildren, electricalEquipmentCategoryId, equipment);
                dialog.Show();
                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
Пример #8
0
        private void CollectCircuitInfo()
        {
            bool bInitilzedElectricalSystemSet = false;

            ElectricalSystem tempElectricalSystem = null;

            foreach (ElementId elementId in selection.GetElementIds())
            {
                Element        element = uiDocument.Document.GetElement(elementId);
                FamilyInstance fi      = element as FamilyInstance;

                MEPModel            mepModel;
                ElectricalSystemSet ess;

                if (fi != null && (mepModel = fi.MEPModel) != null)
                {
                    // Get all electrical systems
                    ess = mepModel.ElectricalSystems;
                    if (null == ess)
                    {
                        m_hasCircuit = false;
                        m_hasPanel   = false;
                        return;
                    }

                    // Remove systems which are not power circuits
                    foreach (ElectricalSystem es in ess)
                    {
                        if (es.SystemType != ElectricalSystemType.PowerCircuit)
                        {
                            ess.Erase(es);
                        }
                    }

                    if (ess.IsEmpty)
                    {
                        m_hasCircuit = false;
                        m_hasPanel   = false;
                        return;
                    }

                    if (!bInitilzedElectricalSystemSet)
                    {
                        m_electricalSystemSet         = ess;
                        bInitilzedElectricalSystemSet = true;
                        continue;
                    }
                    else
                    {
                        foreach (ElectricalSystem es in m_electricalSystemSet)
                        {
                            if (!ess.Contains(es))
                            {
                                m_electricalSystemSet.Erase(es);
                            }
                        }

                        if (m_electricalSystemSet.IsEmpty)
                        {
                            m_hasCircuit = false;
                            m_hasPanel   = false;
                            return;
                        }
                    }
                }

                else if ((tempElectricalSystem = element as ElectricalSystem) != null)
                {
                    if (tempElectricalSystem.SystemType != ElectricalSystemType.PowerCircuit)
                    {
                        m_hasCircuit = false;
                        m_hasPanel   = false;
                        return;
                    }

                    if (!bInitilzedElectricalSystemSet)
                    {
                        m_electricalSystemSet.Insert(tempElectricalSystem);
                        bInitilzedElectricalSystemSet = true;
                        continue;
                    }

                    if (!m_electricalSystemSet.Contains(tempElectricalSystem))
                    {
                        m_hasCircuit = false;
                        m_hasPanel   = false;
                        return;
                    }

                    m_electricalSystemSet.Clear();
                    m_electricalSystemSet.Insert(tempElectricalSystem);
                }

                else
                {
                    m_hasCircuit = false;
                    m_hasPanel   = false;
                    return;
                }
            }

            if (!m_electricalSystemSet.IsEmpty)
            {
                m_hasCircuit = true;
                if (m_electricalSystemSet.Size == 1)
                {
                    foreach (ElectricalSystem es in m_electricalSystemSet)
                    {
                        m_selectedElectricalSystem = es;
                        break;
                    }
                }

                foreach (ElectricalSystem es in m_electricalSystemSet)
                {
                    if (!String.IsNullOrEmpty(es.PanelName))
                    {
                        m_hasPanel = true;
                        break;
                    }
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Get common circuits contain all selected elements
        /// </summary>
        private void CollectCircuitInfo()
        {
            //bool isElectricalSystem = false;

            bool bInitilzedElectricalSystemSet = false;

            //
            // Get common circuits of selected elements
            //
            ElectricalSystem tempElectricalSystem = null;

            foreach (Element element in m_selection.Elements)
            {
                FamilyInstance      fi = element as FamilyInstance;
                MEPModel            mepModel;
                ElectricalSystemSet ess;

                if (fi != null && (mepModel = fi.MEPModel) != null)
                {
                    //
                    // If the element is a family instance and its MEP model is not null,
                    // retrieve its circuits
                    // Then compare the circuits with circuits of other selected elements
                    // to get the common ones
                    //

                    // Get all electrical systems
                    ess = mepModel.ElectricalSystems;
                    if (null == ess)
                    {
                        m_hasCircuit = false;
                        m_hasPanel   = false;
                        return;
                    }

                    // Remove systems which are not power circuits
                    foreach (ElectricalSystem es in ess)
                    {
                        if (es.SystemType != ElectricalSystemType.PowerCircuit)
                        {
                            ess.Erase(es);
                        }
                    }

                    if (ess.IsEmpty)
                    {
                        m_hasCircuit = false;
                        m_hasPanel   = false;
                        return;
                    }

                    // If m_electricalSystemSet is not set before, set it
                    // otherwise compare the circuits with circuits of other selected elements
                    // to get the common ones
                    if (!bInitilzedElectricalSystemSet)
                    {
                        m_electricalSystemSet         = ess;
                        bInitilzedElectricalSystemSet = true;
                        continue;
                    }
                    else
                    {
                        foreach (ElectricalSystem es in m_electricalSystemSet)
                        {
                            if (!ess.Contains(es))
                            {
                                m_electricalSystemSet.Erase(es);
                            }
                        }

                        if (m_electricalSystemSet.IsEmpty)
                        {
                            m_hasCircuit = false;
                            m_hasPanel   = false;
                            return;
                        }
                    }
                }
                else if ((tempElectricalSystem = element as ElectricalSystem) != null)
                {
                    //
                    // If the element is an electrical system, verify if it is a power circuit
                    // If not, compare with circuits of other selected elements
                    // to get the common ones
                    //
                    //verify if it is a power circuit
                    if (tempElectricalSystem.SystemType != ElectricalSystemType.PowerCircuit)
                    {
                        m_hasCircuit = false;
                        m_hasPanel   = false;
                        return;
                    }

                    // If m_electricalSystemSet is not set before, set it
                    // otherwise compare with circuits of other selected elements
                    // to get the common ones
                    if (!bInitilzedElectricalSystemSet)
                    {
                        m_electricalSystemSet.Insert(tempElectricalSystem);
                        bInitilzedElectricalSystemSet = true;
                        continue;
                    }

                    if (!m_electricalSystemSet.Contains(tempElectricalSystem))
                    {
                        m_hasCircuit = false;
                        m_hasPanel   = false;
                        return;
                    }

                    m_electricalSystemSet.Clear();
                    m_electricalSystemSet.Insert(tempElectricalSystem);
                }
                else
                {
                    m_hasCircuit = false;
                    m_hasPanel   = false;
                    return;
                }
            }

            // Verify if there is any common power circuit
            if (!m_electricalSystemSet.IsEmpty)
            {
                m_hasCircuit = true;
                if (m_electricalSystemSet.Size == 1)
                {
                    foreach (ElectricalSystem es in m_electricalSystemSet)
                    {
                        m_selectedElectricalSystem = es;
                        break;
                    }
                }

                foreach (ElectricalSystem es in m_electricalSystemSet)
                {
                    if (!String.IsNullOrEmpty(es.PanelName))
                    {
                        m_hasPanel = true;
                        break;
                    }
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Get common circuits contain all selected elements
        /// </summary>
        private void CollectCircuitInfo()
        {
            //bool isElectricalSystem = false;

            bool bInitilzedElectricalSystemSet = false;

            //
            // Get common circuits of selected elements
            //
            ElectricalSystem tempElectricalSystem = null;
            foreach (Element element in m_selection.Elements)
            {
                FamilyInstance fi = element as FamilyInstance;
                MEPModel mepModel;
                ElectricalSystemSet ess;

                if (fi != null && (mepModel = fi.MEPModel) != null)
                {
                    //
                    // If the element is a family instance and its MEP model is not null,
                    // retrieve its circuits
                    // Then compare the circuits with circuits of other selected elements
                    // to get the common ones
                    //

                    // Get all electrical systems
                    ess = mepModel.ElectricalSystems;
                    if (null == ess)
                    {
                        m_hasCircuit = false;
                        m_hasPanel = false;
                        return;
                    }

                    // Remove systems which are not power circuits
                    foreach (ElectricalSystem es in ess)
                    {
                        if (es.SystemType != ElectricalSystemType.PowerCircuit)
                        {
                            ess.Erase(es);
                        }
                    }

                    if (ess.IsEmpty)
                    {
                        m_hasCircuit = false;
                        m_hasPanel = false;
                        return;
                    }

                    // If m_electricalSystemSet is not set before, set it
                    // otherwise compare the circuits with circuits of other selected elements
                    // to get the common ones
                    if (!bInitilzedElectricalSystemSet)
                    {
                        m_electricalSystemSet = ess;
                        bInitilzedElectricalSystemSet = true;
                        continue;
                    }
                    else
                    {
                        foreach (ElectricalSystem es in m_electricalSystemSet)
                        {
                            if (!ess.Contains(es))
                            {
                                m_electricalSystemSet.Erase(es);
                            }
                        }

                        if (m_electricalSystemSet.IsEmpty)
                        {
                            m_hasCircuit = false;
                            m_hasPanel = false;
                            return;
                        }
                    }
                }
                else if ((tempElectricalSystem = element as ElectricalSystem) != null)
                {
                    //
                    // If the element is an electrical system, verify if it is a power circuit
                    // If not, compare with circuits of other selected elements
                    // to get the common ones
                    //
                    //verify if it is a power circuit
                    if (tempElectricalSystem.SystemType != ElectricalSystemType.PowerCircuit)
                    {
                        m_hasCircuit = false;
                        m_hasPanel = false;
                        return;
                    }

                    // If m_electricalSystemSet is not set before, set it
                    // otherwise compare with circuits of other selected elements
                    // to get the common ones
                    if (!bInitilzedElectricalSystemSet)
                    {
                        m_electricalSystemSet.Insert(tempElectricalSystem);
                        bInitilzedElectricalSystemSet = true;
                        continue;
                    }

                    if (!m_electricalSystemSet.Contains(tempElectricalSystem))
                    {
                        m_hasCircuit = false;
                        m_hasPanel = false;
                        return;
                    }

                    m_electricalSystemSet.Clear();
                    m_electricalSystemSet.Insert(tempElectricalSystem);
                }
                else
                {
                    m_hasCircuit = false;
                    m_hasPanel = false;
                    return;
                }
            }

            // Verify if there is any common power circuit
            if (!m_electricalSystemSet.IsEmpty)
            {
                m_hasCircuit = true;
                if (m_electricalSystemSet.Size == 1)
                {
                    foreach (ElectricalSystem es in m_electricalSystemSet)
                    {
                        m_selectedElectricalSystem = es;
                        break;
                    }
                }

                foreach (ElectricalSystem es in m_electricalSystemSet)
                {
                    if (!String.IsNullOrEmpty(es.PanelName))
                    {
                        m_hasPanel = true;
                        break;
                    }
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="commandData">Revit's external commandData</param>
        public CircuitOperationData(ExternalCommandData commandData)
        {
            m_revitDoc = commandData.Application.ActiveUIDocument;
            m_selection = m_revitDoc.Selection;

            m_electricalSystemSet = new ElectricalSystemSet();
            m_electricalSystemItems = new List<ElectricalSystemItem>();

            CollectConnectorInfo();
            CollectCircuitInfo();
        }