示例#1
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;
                    }
                }
            }
        }
示例#2
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;
                    }
                }
            }
        }