/// <summary> /// Remove an element from selected circuit /// </summary> public void RemoveElementFromCircuit() { // Clear selection before selecting the panel m_selection.GetElementIds().Clear(); // Interact with UI to select a panel if (m_revitDoc.Selection.PickObject(ObjectType.Element) == null) { return; } // Get the selected element Element selectedElement = null; foreach (ElementId elementId in m_revitDoc.Selection.GetElementIds()) { Element element = m_revitDoc.Document.GetElement(elementId); 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; } // Check whether the selected element belongs to the circuit if (!IsElementBelongsToCircuit(mepModel, m_selectedElectricalSystem)) { ShowErrorMessage("ElementNotInCircuit"); return; } try { // Remove the selected element from circuit ElementSet es = new ElementSet(); foreach (ElementId elementId in m_revitDoc.Selection.GetElementIds()) { es.Insert(m_revitDoc.Document.GetElement(elementId)); } m_selectedElectricalSystem.RemoveFromCircuit(es); } catch (Exception) { ShowErrorMessage("FailedToRemoveElement"); } }
private void AddElementToCircuit() { if (!CanExcuteOperation()) { return; } try { // Remove the selected element from circuit ElementSet es = new ElementSet(); foreach (ElementId elementId in uiDocument.Selection.GetElementIds()) { es.Insert(uiDocument.Document.GetElement(elementId)); } m_selectedElectricalSystem.RemoveFromCircuit(es); } catch (Exception) { ShowErrorMessage("FailedToRemoveElement"); } }