コード例 #1
0
        private void RemoveElementFromCircuit()
        {
            if (!CanExcuteOperation())
            {
                return;
            }

            try
            {
                ElementSet es = new ElementSet();
                foreach (ElementId elementId in selection.GetElementIds())
                {
                    es.Insert(uiDocument.Document.GetElement(elementId));
                }
                if (!m_selectedElectricalSystem.AddToCircuit(es))
                {
                    ShowErrorMessage("FailedToAddElement");
                    return;
                }
            }
            catch (Exception)
            {
                ShowErrorMessage("FailedToAddElement");
            }
        }
コード例 #2
0
        /// <summary>
        /// Add an element to circuit
        /// </summary>
        public void AddElementToCircuit()
        {
            // Clear selection before selecting the panel
            m_selection.Elements.Clear();
            // Interact with UI to select a panel
            if (m_revitDoc.Selection.PickObject(ObjectType.Element) == null)
            {
                return;
            }

            //
            // Verify if the selected element can be added to the circuit
            //

            // Get selected element
            Element selectedElement = null;

            foreach (Element element in m_selection.Elements)
            {
                selectedElement = element;
            }

            // Get the MEP model of selected element
            MEPModel       mepModel = null;
            FamilyInstance fi       = selectedElement as FamilyInstance;

            if (null == fi || null == (mepModel = fi.MEPModel))
            {
                ShowErrorMessage("SelectElectricalComponent");
                return;
            }

            // Verify if the element has usable connector
            if (!VerifyUnusedConnectors(fi))
            {
                ShowErrorMessage("NoUsableConnector");
                return;
            }

            if (IsElementBelongsToCircuit(mepModel, m_selectedElectricalSystem))
            {
                ShowErrorMessage("ElementInCircuit");
                return;
            }

            try
            {
                if (!m_selectedElectricalSystem.AddToCircuit(m_selection.Elements))
                {
                    ShowErrorMessage("FailedToAddElement");
                    return;
                }
            }
            catch (Exception)
            {
                ShowErrorMessage("FailedToAddElement");
            }
        }