/***************************************************/ /**** Protected methods ****/ /***************************************************/ protected override int Delete(IRequest request, ActionConfig actionConfig = null) { if (request == null) { BH.Engine.Reflection.Compute.RecordError("BHoM objects could not be read because provided IRequest is null."); return(0); } UIDocument uiDocument = this.UIDocument; Document document = this.Document; RevitRemoveConfig removeConfig = actionConfig as RevitRemoveConfig; IEnumerable <ElementId> worksetPrefilter = null; if (!removeConfig.IncludeClosedWorksets) { worksetPrefilter = document.ElementIdsByWorksets(document.OpenWorksetIds().Union(document.SystemWorksetIds()).ToList()); } IEnumerable <ElementId> elementIds = request.IElementIds(uiDocument, worksetPrefilter).RemoveGridSegmentIds(document); List <ElementId> deletedIds = Delete(elementIds, document, removeConfig.RemovePinned); if (deletedIds == null) { return(0); } else { return(deletedIds.Count); } }
/***************************************************/ /**** Revit side of Revit_Adapter Remove ****/ /***************************************************/ public override int Remove(IRequest request, ActionConfig actionConfig = null) { // Check the document UIDocument uiDocument = this.UIDocument; Document document = this.Document; if (document == null) { BH.Engine.Reflection.Compute.RecordError("BHoM objects could not be removed because Revit Document is null (possibly there is no open documents in Revit)."); return(0); } if (document.IsReadOnly) { BH.Engine.Reflection.Compute.RecordError("BHoM objects could not be removed because Revit Document is read only."); return(0); } if (document.IsModifiable) { BH.Engine.Reflection.Compute.RecordError("BHoM objects could not be removed because another transaction is open in Revit."); return(0); } // Set config RevitRemoveConfig removeConfig = actionConfig as RevitRemoveConfig; if (removeConfig == null) { BH.Engine.Reflection.Compute.RecordNote("Revit Remove Config has not been specified. Default Revit Remove Config is used."); removeConfig = new RevitRemoveConfig(); } // Suppress warnings if (UIControlledApplication != null && removeConfig.SuppressFailureMessages) { UIControlledApplication.ControlledApplication.FailuresProcessing += ControlledApplication_FailuresProcessing; } // Remove the objects based on the request int result = 0; using (Transaction transaction = new Transaction(document, "BHoM Remove")) { transaction.Start(); result = Delete(request, removeConfig); transaction.Commit(); } // Switch of warning suppression if (UIControlledApplication != null) { UIControlledApplication.ControlledApplication.FailuresProcessing -= ControlledApplication_FailuresProcessing; } return(result); }
/***************************************************/ /**** Protected methods ****/ /***************************************************/ protected override int Delete(IRequest request, ActionConfig actionConfig = null) { if (request == null) { BH.Engine.Reflection.Compute.RecordError("Deletion could not be executed because provided IRequest is null."); return(0); } if (request.AllRequestsOfType(typeof(FilterByLink)).Count != 0) { BH.Engine.Reflection.Compute.RecordError($"It is not allowed to remove objects from Revit links - please remove the requests of type {nameof(FilterByLink)} from the request."); return(0); } Document document = this.Document; RevitRemoveConfig removeConfig = actionConfig as RevitRemoveConfig; IEnumerable <ElementId> worksetPrefilter = null; if (!removeConfig.IncludeClosedWorksets) { worksetPrefilter = document.ElementIdsByWorksets(document.OpenWorksetIds().Union(document.SystemWorksetIds()).ToList()); } IEnumerable <ElementId> elementIds = request.IElementIds(document, worksetPrefilter).RemoveGridSegmentIds(document); List <ElementId> deletedIds = Delete(elementIds, document, removeConfig.RemovePinned); if (deletedIds == null) { return(0); } else { return(deletedIds.Count); } }
/***************************************************/ /**** BHoM side of Revit_Adapter Remove ****/ /***************************************************/ public override int Remove(IRequest request, ActionConfig actionConfig = null) { //Check if request is not null or empty if (request == null) { BH.Engine.Reflection.Compute.RecordError("BHoM objects could not be read because provided IRequest is null or empty."); return(0); } else if (request is FilterRequest) { FilterRequest filterRequest = (FilterRequest)request; if (filterRequest.Type == null && String.IsNullOrWhiteSpace(filterRequest.Tag) && (filterRequest.Equalities == null || filterRequest.Equalities.Count == 0)) { BH.Engine.Reflection.Compute.RecordError("BHoM objects could not be read because provided IRequest is null or empty."); return(0); } } //Initialize Revit config RevitRemoveConfig removeConfig = actionConfig as RevitRemoveConfig; //If internal adapter is loaded call it directly if (InternalAdapter != null) { InternalAdapter.RevitSettings = RevitSettings; return(InternalAdapter.Remove(request, removeConfig)); } if (!this.IsValid()) { BH.Engine.Reflection.Compute.RecordError("Revit Adapter is not valid. Please check if it has been set up correctly and activated."); return(0); } //Reset the wait event m_WaitEvent.Reset(); if (!CheckConnection()) { return(0); } //Send data through the socket link m_LinkIn.SendData(new List <object>() { PackageType.Remove, request, removeConfig, RevitSettings }); //Wait until the return message has been recieved if (!m_WaitEvent.WaitOne(TimeSpan.FromMinutes(m_WaitTime))) { BH.Engine.Reflection.Compute.RecordError("The connection with Revit timed out. If working on a big model, try to increase the max wait time"); } //Grab the return count from the latest package List <object> returnObjs = new List <object>(m_ReturnPackage); //Clear the return list m_ReturnPackage.Clear(); //Raise returned events RaiseEvents(); //Check if the return package contains error message if (returnObjs.Count == 1 && returnObjs[0] is string) { Engine.Reflection.Compute.RecordError(returnObjs[0] as string); return(0); } //Return the package return((int)returnObjs[0]); }