Exemplo n.º 1
0
 private void EventCommandFinished(object sender, DocumentChangedEventArgs e)
 {
     try
     {
         if (!_purgeStarted)
         {
             return;
         }
         var deletedIds = e.GetDeletedElementIds().ToList();
         if (deletedIds.Count > 0)
         {
             var doc = e.GetDocument();
             if (!doc.IsFamilyDocument)
             {
                 var docPath = GetCentralPath(doc);
                 if (_purgeSettingsDictionary.ContainsKey(docPath))
                 {
                     var eventSettings = _purgeSettingsDictionary[docPath];
                     eventSettings.SizeEnd = eventSettings.GetFileSize();
                     eventSettings.EndTime = DateTime.Now;
                     WriteRecord(eventSettings, "PURGE-UNUSED");
                 }
             }
         }
         _purgeStarted = false;
     }
     catch (Exception ex)
     {
         Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
     }
 }
Exemplo n.º 2
0
        private void documentChangedEventFillingListOfElements(object sender, DocumentChangedEventArgs e)
        {
            //Null if the window is not open
            if (MainForm._changedElements == null)
            {
                return;
            }

            ElementClassFilter FamilyInstanceFilter = new ElementClassFilter(typeof(View), true);
            var addedElements    = e.GetAddedElementIds(FamilyInstanceFilter);
            var deletedElements  = e.GetDeletedElementIds();
            var modifiedElements = e.GetModifiedElementIds(FamilyInstanceFilter);

            if (RevitManagement.changedElements == null)
            {
                RevitManagement.changedElements = new List <ElementId>();
            }

            RevitManagement.changedElements.AddRange(addedElements);
            RevitManagement.changedElements.AddRange(modifiedElements);
            RevitManagement.deletedElements = deletedElements.ToList();
            RevitManagement.changedElements = RevitManagement.changedElements.Distinct().ToList();

            foreach (var item in RevitManagement.changedElements)
            {
                if (!MainForm._changedElements.Contains(item))
                {
                    MainForm.AddChangedItem(item);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///   DocumentChanged Handler
        /// </summary>
        /// <remarks>
        ///   It monitors changes to the element that is being analyzed.
        ///   If the element was changed, we ask it to restart the analysis.
        ///   If the element was deleted, we ask the analyzer to stop.
        /// </remarks>
        ///
        public void DocChangedHandler(object sender, DocumentChangedEventArgs args)
        {
            if (m_analyzer != null)
            {
                // first we check if the element was deleted

                ICollection <ElementId> elems = args.GetDeletedElementIds();
                if (elems.Contains(m_analyzer.AnalyzedElementId))
                {
                    m_analyzer.StopCalculation();
                    m_analyzer = null;

                    // if we've stopped, we do not need events anymore
                    UnsubscribeFromIdling(sender as UIApplication);
                    UnsubscribeFromChanges(sender as UIApplication);
                }
                else   // not deleted? what about changed?
                {
                    elems = args.GetModifiedElementIds();
                    if (elems.Contains(m_analyzer.AnalyzedElementId))
                    {
                        m_analyzer.RestartCalculation();
                    }
                }
            }
            else   // no analyzer => no need for the events anymore
            {
                UnsubscribeFromIdling(sender as UIApplication);
                UnsubscribeFromChanges(sender as UIApplication);
            }
        }
Exemplo n.º 4
0
        private void ControlledApplicationOnDocumentChanged(object sender, DocumentChangedEventArgs documentChangedEventArgs)
        {
            var doc = documentChangedEventArgs.GetDocument();

            this.HandleDeletedElements(doc, documentChangedEventArgs.GetDeletedElementIds());
            this.HandleChangedElements(doc, documentChangedEventArgs.GetModifiedElementIds());
        }
Exemplo n.º 5
0
        void ApplicationDocumentChanged(object sender, DocumentChangedEventArgs args)
        {
            var doc      = args.GetDocument();
            var addedIds = args.GetAddedElementIds();
            var modified = args.GetModifiedElementIds();
            var deleted  = args.GetDeletedElementIds();

            ProcessUpdates(doc, modified, deleted, addedIds, args.GetTransactionNames());
        }
Exemplo n.º 6
0
        void ApplicationDocumentChanged(object sender, DocumentChangedEventArgs args)
        {
            var doc      = args.GetDocument();
            var added    = args.GetAddedElementIds().Select(x => doc.GetElement(x).UniqueId);
            var addedIds = args.GetAddedElementIds();
            var modified = args.GetModifiedElementIds().Select(x => doc.GetElement(x).UniqueId).ToList();
            var deleted  = args.GetDeletedElementIds();

            ProcessUpdates(doc, modified, deleted, added, addedIds);
        }
Exemplo n.º 7
0
 void Application_DocumentChanged(object sender, DocumentChangedEventArgs args)
 {
     if (args.GetDocument().Equals(dynRevitSettings.Doc.Document))
     {
         processUpdates(
             args.GetModifiedElementIds(),
             args.GetDeletedElementIds(),
             args.GetAddedElementIds());
     }
 }
Exemplo n.º 8
0
        public void RevitDocumentChanged(object sender, DocumentChangedEventArgs args)
        {
            if (!IsShowEvent)
            {
                return;
            }

            // You can get the list of ids of element added/changed/modified.
            Document doc = args.GetDocument();

            ICollection <ElementId> idsAdded    = args.GetAddedElementIds();
            ICollection <ElementId> idsDeleted  = args.GetDeletedElementIds();
            ICollection <ElementId> idsModified = args.GetModifiedElementIds();

            //Add to parameter comment
            Element elem;

            // Put it in a string to show to the user.
            string msg = "Added: ";

            foreach (ElementId id in idsAdded)
            {
                elem = doc.GetElement(id);
                Parameter param = elem.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
                param.Set(DateTime.Today.ToString());
                msg += id.IntegerValue.ToString() + " ";
            }

            msg += "\nDeleted: ";
            foreach (ElementId id in idsDeleted)
            {
                msg += id.IntegerValue.ToString() + " ";
            }

            msg += "\nModified: ";
            foreach (ElementId id in idsModified)
            {
                msg += id.IntegerValue.ToString() + " ";
            }

            // Show a message to a user.
            TaskDialogResult res = default(TaskDialogResult);

            res = TaskDialog.Show("Revit UI Labs - Event", msg, TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel);

            // If the user chooses to cancel, show no more event.
            if (res == TaskDialogResult.Cancel)
            {
                IsShowEvent = false;
            }
        }
Exemplo n.º 9
0
        private void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            try{
                setInfos(e);

                // get deleted elements ID
                if (e.Operation == UndoOperation.TransactionCommitted)
                {
                    if (e.GetTransactionNames()[0] == "”далить выбранные" || e.GetTransactionNames()[0] == "Delete selection")
                    {
                        foreach (var item in e.GetDeletedElementIds())
                        {
                            if (!addedList.Contains(item))
                            {
                                deletedList.Add(new DeletedElement(item.IntegerValue.ToString(), documentName, username));
                            }
                        }
                    }
                    else if (e.GetTransactionNames()[0] != "ќбновление рабочих наборов до последней версии из хранилища" && e.GetAddedElementIds().Count > 0)
                    {
                        addedList.AddRange(e.GetAddedElementIds().AsEnumerable());
                    }
                }
                // remove deleted elements if the transaction is rolled back
                else if (e.Operation == UndoOperation.TransactionUndone)
                {
                    if (e.GetTransactionNames()[0] == "”далить выбранные" || e.GetTransactionNames()[0] == "Delete selection" && deletedList.Count > 0)
                    {
                        foreach (var item in e.GetAddedElementIds())
                        {
                            try
                            {
                                var removeItem = deletedList.Where(x => x.Id == item.IntegerValue.ToString()).First();
                                deletedList.Remove(removeItem);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
            catch {
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// This is our event handler. Simply report the list of element ids which have been changed.
        /// </summary>
        public void UILabs_DocumentChanged(object sender, DocumentChangedEventArgs args)
        {
            if (!m_showEvent)
            {
                return;
            }

            // You can get the list of ids of element added/changed/modified.
            Document rvtdDoc = args.GetDocument();

            ICollection <ElementId> idsAdded    = args.GetAddedElementIds();
            ICollection <ElementId> idsDeleted  = args.GetDeletedElementIds();
            ICollection <ElementId> idsModified = args.GetModifiedElementIds();

            // Put it in a string to show to the user.
            string msg = "Added: ";

            foreach (ElementId id in idsAdded)
            {
                msg += id.IntegerValue.ToString() + " ";
            }

            msg += "\nDeleted: ";
            foreach (ElementId id in idsDeleted)
            {
                msg += id.IntegerValue.ToString() + " ";
            }

            msg += "\nModified: ";
            foreach (ElementId id in idsModified)
            {
                msg += id.IntegerValue.ToString() + " ";
            }

            // Show a message to a user.
            TaskDialogResult res = default(TaskDialogResult);

            res = TaskDialog.Show("Revit UI Labs - Event", msg, TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel);

            // If the user chooses to cancel, show no more event.
            if (res == TaskDialogResult.Cancel)
            {
                m_showEvent = false;
            }
        }
        private void ElementDeleted(object sender, DocumentChangedEventArgs e)
        {
            string deletedElementsIds = "";

            ICollection <ElementId> deletedElements = e.GetDeletedElementIds();

            foreach (ElementId eid in deletedElements)
            {
                string value = "not in dictionary";

                dictionaryDB.TryGetValue(eid.IntegerValue, out value);

                dictionaryDB.Remove(eid.IntegerValue);

                deletedElementsIds += String.Format("{0} : {1}\n", eid.IntegerValue, value);
            }

            m_MyDock.txtBoxDeleted.Text = String.Format("{0} element(s) deleted: \n{1}", deletedElements.Count, deletedElementsIds);
        }
        /// <summary>
        /// Perform updates on in-canvas controls.
        /// In this example, the In-Canvas controls will be deleted, or have their positions changed, depending on the changes to related elements.
        /// </summary>
        /// <param name="data">Data about changes in the document.</param>
        public static void Execute(DocumentChangedEventArgs data)
        {
            Document doc = data.GetDocument();
            TemporaryGraphicsManager temporaryGraphicsManager = TemporaryGraphicsManager.GetTemporaryGraphicsManager(doc);
            IssueMarkerTracking      tracking = IssueMarkerTrackingManager.GetInstance().GetTracking(doc);

            foreach (ElementId deleted in data.GetDeletedElementIds())
            {
                if (tracking.GetMarkerByElementId(deleted) is IssueMarker marker)
                {
                    // This is how to delete control
                    temporaryGraphicsManager.RemoveControl(marker.ControlIndex);

                    // Don't forget to clean up your own data
                    tracking.RemoveMarkerByElement(deleted);
                }
            }

            foreach (ElementId updated in data.GetModifiedElementIds())
            {
                if (tracking.GetMarkerByElementId(updated) is IssueMarker marker)
                {
                    Element element = doc.GetElement(updated);

                    // Since we keep a copy of InCanvasControlData, we can avoid creating a new one. It already has image and position set - and we can just change the position
                    InCanvasControlData controlData = marker.InCanvasControlData;
                    if (element.Location is LocationPoint pointLoc)
                    {
                        controlData.Position = pointLoc.Point;
                    }
                    else if (element.Location is LocationCurve curveLoc)
                    {
                        controlData.Position = curveLoc.Curve.GetEndPoint(0);
                    }

                    marker.InCanvasControlData = controlData;

                    // This is how to set updated data to a control
                    temporaryGraphicsManager.UpdateControl(marker.ControlIndex, marker.InCanvasControlData);
                }
            }
        }
        private void Application_DocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            if (MainWindow != null)
            {
                _currentDocument = e.GetDocument();
                var hasImports = false;
                var added      = e.GetAddedElementIds();
                var removed    = e.GetDeletedElementIds();
                if (added != null && added.Any())
                {
                    foreach (var elementId in added)
                    {
                        if (_currentDocument.GetElement(elementId) is CADLinkType)
                        {
                            hasImports = true;
                            break;
                        }
                    }
                }

                if (removed != null && removed.Any() && _dwgImportManagerVm.DwgImportsItems.Any())
                {
                    foreach (var elementId in removed)
                    {
                        foreach (var dwgImportsItem in _dwgImportManagerVm.DwgImportsItems)
                        {
                            if (dwgImportsItem.Id.Equals(elementId))
                            {
                                hasImports = true;
                                break;
                            }
                        }
                    }
                }

                if (hasImports)
                {
                    SearchImportsAndBind(true);
                }
            }
        }
Exemplo n.º 14
0
        public void AppEvent_DocChangedEventHandler(object sender, DocumentChangedEventArgs args)
        {
            // this.uiApp.Idling -= Main.ActiveModelessForm.UIAppEvent_IdlingEventHandler;
            this.haltIdlingHandler = true;

            // Retrieve the addedElement Ids and deletedElement Ids
            ICollection <ElementId> addedElements   = args.GetAddedElementIds();
            ICollection <ElementId> deletedElements = args.GetDeletedElementIds();

            // Update the dataController's cached elements
            this.dataController.AddToAllElements(addedElements.ToList());
            this.dataController.RemoveFromAllElements(deletedElements.ToList());

            this.dataController.SetMode(requestHandler.FilterBy, true);

            // Put up a request to update the TreeView
            requestHandler.AddRequest(Request.UpdateTreeView);

            this.haltIdlingHandler = false;
            // this.uiApp.Idling += Main.ActiveModelessForm.UIAppEvent_IdlingEventHandler;

            return;
        }
Exemplo n.º 15
0
    /// <summary>
    /// This is our event handler. Simply report the list of element ids which have been changed. 
    /// </summary>
    public void UILabs_DocumentChanged(object sender, DocumentChangedEventArgs args)
    {
      if (!m_showEvent) return;

      // You can get the list of ids of element added/changed/modified. 
      Document rvtdDoc = args.GetDocument();

      ICollection<ElementId> idsAdded = args.GetAddedElementIds();
      ICollection<ElementId> idsDeleted = args.GetDeletedElementIds();
      ICollection<ElementId> idsModified = args.GetModifiedElementIds();

      // Put it in a string to show to the user. 
      string msg = "Added: ";
      foreach (ElementId id in idsAdded)
      {
        msg += id.IntegerValue.ToString() + " ";
      }

      msg += "\nDeleted: ";
      foreach (ElementId id in idsDeleted)
      {
        msg += id.IntegerValue.ToString() + " ";
      }

      msg += "\nModified: ";
      foreach (ElementId id in idsModified)
      {
        msg += id.IntegerValue.ToString() + " ";
      }

      // Show a message to a user. 
      TaskDialogResult res = default(TaskDialogResult);
      res = TaskDialog.Show("Revit UI Labs - Event", msg, TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel);

      // If the user chooses to cancel, show no more event. 
      if (res == TaskDialogResult.Cancel)
      {
        m_showEvent = false;
      }
    }
Exemplo n.º 16
0
        void ApplicationDocumentChanged(object sender, DocumentChangedEventArgs args)
        {
            var doc = args.GetDocument();
            var added = args.GetAddedElementIds().Select(x => doc.GetElement(x).UniqueId);
            var addedIds = args.GetAddedElementIds();
            var modified = args.GetModifiedElementIds().Select(x => doc.GetElement(x).UniqueId).ToList();
            var deleted = args.GetDeletedElementIds();

            ProcessUpdates(doc, modified, deleted, added, addedIds);
        }
Exemplo n.º 17
0
 private void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
 {
     Messenger.Default.Send(new DocumentChanged(e.GetDeletedElementIds(), e.GetAddedElementIds(), e.GetDocument()));
 }
Exemplo n.º 18
0
        private void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            if (Committing)
            {
                return;
            }

            var document = e.GetDocument();

            if (!document.Equals(ActiveDBDocument))
            {
                return;
            }

            CancelReadActions();

            var added    = e.GetAddedElementIds();
            var deleted  = e.GetDeletedElementIds();
            var modified = e.GetModifiedElementIds();

            if (added.Count > 0 || deleted.Count > 0 || modified.Count > 0)
            {
                var materialsChanged = modified.Select((x) => document.GetElement(x)).OfType <Material>().Any();

                foreach (GH_Document definition in Grasshopper.Instances.DocumentServer)
                {
                    foreach (var obj in definition.Objects)
                    {
                        if (obj is IGH_Param param)
                        {
                            if (param.SourceCount > 0)
                            {
                                continue;
                            }

                            if (param.Phase == GH_SolutionPhase.Blank)
                            {
                                continue;
                            }

                            if (obj is GH.Parameters.IGH_PersistentGeometryParam persistent)
                            {
                                if (persistent.NeedsToBeExpired(document, added, deleted, modified))
                                {
                                    param.ExpireSolution(false);
                                }
                            }
                        }
                        else if (obj is IGH_Component component)
                        {
                            if (component is GH.Components.DocumentElements)
                            {
                                component.ExpireSolution(false);
                            }
                            else
                            {
                                bool needsToBeExpired = false;
                                foreach (var inputParam in component.Params.Input)
                                {
                                    if (inputParam.SourceCount > 0)
                                    {
                                        continue;
                                    }

                                    if (inputParam.Phase == GH_SolutionPhase.Blank)
                                    {
                                        continue;
                                    }

                                    if (inputParam is GH.Parameters.IGH_PersistentGeometryParam persistent)
                                    {
                                        if (persistent.NeedsToBeExpired(document, added, deleted, modified))
                                        {
                                            needsToBeExpired = true;
                                            break;
                                        }
                                    }
                                }

                                if (needsToBeExpired)
                                {
                                    component.ExpireSolution(true);
                                }
                                else
                                {
                                    foreach (var outParam in component.Params.Output)
                                    {
                                        if (outParam is GH.Parameters.IGH_PersistentGeometryParam persistent)
                                        {
                                            if (persistent.NeedsToBeExpired(document, added, deleted, modified))
                                            {
                                                foreach (var r in outParam.Recipients)
                                                {
                                                    r.ExpireSolution(false);
                                                }
                                            }
                                            else if (materialsChanged)
                                            {
                                                foreach (var goo in outParam.VolatileData.AllData(true))
                                                {
                                                    if (goo is IGH_PreviewMeshData previewMeshData)
                                                    {
                                                        previewMeshData.DestroyPreviewMeshes();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (definition.Enabled)
                    {
                        definition.NewSolution(false);
                    }
                }
            }
        }
Exemplo n.º 19
0
 void Application_DocumentChanged(object sender, DocumentChangedEventArgs args)
 {
     if (args.GetDocument().Equals(DocumentManager.Instance.CurrentUIDocument.Document))
     {
         processUpdates(
            args.GetModifiedElementIds(),
            args.GetDeletedElementIds(),
            args.GetAddedElementIds());
     }
 }
Exemplo n.º 20
0
        void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            var document = e.GetDocument();
            var added    = e.GetAddedElementIds();
            var deleted  = e.GetDeletedElementIds();
            var modified = e.GetModifiedElementIds();

            if (added.Count > 0 || deleted.Count > 0 || modified.Count > 0)
            {
                foreach (GH_Document definition in Instances.DocumentServer)
                {
                    bool expireNow =
                        (e.Operation == UndoOperation.TransactionCommitted || e.Operation == UndoOperation.TransactionUndone || e.Operation == UndoOperation.TransactionRedone) &&
                        GH_Document.EnableSolutions &&
                        Instances.ActiveCanvas.Document == definition &&
                        definition.Enabled &&
                        definition.SolutionState != GH_ProcessStep.Process;

                    var change = new DocumentChangedEvent()
                    {
                        Operation  = e.Operation,
                        Document   = document,
                        Definition = definition
                    };

                    foreach (var obj in definition.Objects)
                    {
                        if (obj is Parameters.IGH_ElementIdParam persistentParam)
                        {
                            if (persistentParam.DataType == GH_ParamData.remote)
                            {
                                continue;
                            }

                            if (persistentParam.Phase == GH_SolutionPhase.Blank)
                            {
                                continue;
                            }

                            if (persistentParam.NeedsToBeExpired(document, added, deleted, modified))
                            {
                                if (expireNow)
                                {
                                    persistentParam.ExpireSolution(false);
                                }
                                else
                                {
                                    change.ExpiredObjects.Add(persistentParam);
                                }
                            }
                        }
                        else if (obj is Components.IGH_ElementIdComponent persistentComponent)
                        {
                            if (persistentComponent.NeedsToBeExpired(e))
                            {
                                if (expireNow)
                                {
                                    persistentComponent.ExpireSolution(false);
                                }
                                else
                                {
                                    change.ExpiredObjects.Add(persistentComponent);
                                }
                            }
                        }
                    }

                    if (definition.SolutionState != GH_ProcessStep.Process)
                    {
                        changeQuque.Enqueue(change);
                    }
                    else if (definition == Instances.ActiveCanvas.Document)
                    {
                        if (change.ExpiredObjects.Count > 0)
                        {
                            foreach (var obj in change.ExpiredObjects)
                            {
                                obj.ClearData();
                                obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"This object was expired because it contained obsolete Revit elements.");
                            }

                            Instances.DocumentEditor.SetStatusBarEvent
                            (
                                new GH_RuntimeMessage
                                (
                                    change.ExpiredObjects.Count == 1 ?
                                    $"An object was expired because it contained obsolete Revit elements." :
                                    $"{change.ExpiredObjects.Count} objects were expired because them contained obsolete Revit elements.",
                                    GH_RuntimeMessageLevel.Remark,
                                    "Document"
                                )
                            );
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
        static void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            var document = e.GetDocument();
            var added    = e.GetAddedElementIds();
            var deleted  = e.GetDeletedElementIds();
            var modified = e.GetModifiedElementIds();

            if (added.Count > 0 || deleted.Count > 0 || modified.Count > 0)
            {
                var materialsChanged = modified.Select((x) => document.GetElement(x)).OfType <Material>().Any();

                foreach (GH_Document definition in Instances.DocumentServer)
                {
                    bool expireNow = definition.SolutionState == GH_ProcessStep.PreProcess &&
                                     Instances.ActiveCanvas.Document == definition;

                    foreach (var obj in definition.Objects)
                    {
                        if (obj is IGH_Param param)
                        {
                            if (param.SourceCount > 0)
                            {
                                continue;
                            }

                            if (param.Phase == GH_SolutionPhase.Blank)
                            {
                                continue;
                            }

                            if (obj is Parameters.IGH_PersistentGeometryParam persistent)
                            {
                                if (persistent.NeedsToBeExpired(document, added, deleted, modified))
                                {
                                    if (expireNow)
                                    {
                                        param.ExpireSolution(false);
                                    }
                                    else
                                    {
                                        param.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "This parameter contains expired elements.");
                                    }
                                }
                            }
                        }
                        else if (obj is IGH_Component component)
                        {
                            if (component is Components.DocumentElements)
                            {
                                if (expireNow)
                                {
                                    component.ExpireSolution(false);
                                }
                                else
                                {
                                    component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Document has been changed since the last solution.");
                                }
                            }
                            else
                            {
                                bool needsToBeExpired = false;
                                foreach (var inputParam in component.Params.Input)
                                {
                                    if (inputParam.SourceCount > 0)
                                    {
                                        continue;
                                    }

                                    if (inputParam.Phase == GH_SolutionPhase.Blank)
                                    {
                                        continue;
                                    }

                                    if (inputParam is Parameters.IGH_PersistentGeometryParam persistent)
                                    {
                                        if (persistent.NeedsToBeExpired(document, added, deleted, modified))
                                        {
                                            needsToBeExpired = true;
                                            break;
                                        }
                                    }
                                }

                                if (needsToBeExpired)
                                {
                                    if (expireNow)
                                    {
                                        component.ExpireSolution(false);
                                    }
                                    else
                                    {
                                        component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Some input parameter contains expired elements.");
                                    }
                                }
                            }
                        }
                    }

                    if (expireNow && definition.Enabled)
                    {
                        definition.NewSolution(false);
                    }
                }
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// DocumentChanged事件,并针对不同的绘制情况而进行不同的处理
        /// </summary>
        /// <param name="sender">Application对象</param>
        /// <param name="e"></param>
        private void app_DocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            if (e.Operation == UndoOperation.TransactionCommitted ||
                e.Operation == UndoOperation.TransactionUndone ||
                e.Operation == UndoOperation.TransactionRedone)
            {
                doc = e.GetDocument();
                bool blnContinueDraw = false; // 在检查连续性后是否要继续绘制
                try
                {
                    // 先考察添加的对象:如果添加了新对象,则要么是 DrawNewLines ,要么是 DrawOtherObjects
                    int     addedCount   = 0;
                    Element addedElement = default(Element);

                    foreach (ElementId eid in e.GetAddedElementIds())
                    {
                        addedElement = doc.GetElement(eid);
                        if (addedElement is ModelCurve)
                        {
                            AddedModelCurvesId.Add(eid);
                            addedCount++;
                        }
                    }

                    if (addedCount > 0) // 说明绘制了新的模型线
                    {
                        // 检测当前集合中的曲线是否符合指定的连续性要求
                        if (this.CheckInTime)
                        {
                            CurvesState cs = ValidateCurves(AddedModelCurvesId, out blnContinueDraw);
                            RefreshUiAfterValidation(cs, blnContinueDraw);
                        }
                        else // 说明不进行实时检测,而直接继续绘制
                        {
                        }
                        //
                        return;
                    }

                    //
                    // 再考察删除对象的情况
                    List <ElementId> deleted = e.GetDeletedElementIds().ToList();
                    if (deleted.Count > 0)
                    {
                        // 先将被删除的曲线从曲线链集合中剔除掉
                        int id_Chain   = 0;                                                      // 曲线链中的元素下标
                        int id_deleted = 0;                                                      // 删除的模型线集合中的元素下标
                        for (id_Chain = AddedModelCurvesId.Count - 1; id_Chain >= 0; id_Chain--) // 曲线链中的元素下标
                        {
                            //
                            id_deleted = deleted.IndexOf(AddedModelCurvesId[id_Chain]); // 找到对应的项
                            //
                            if (id_deleted >= 0)
                            {
                                deleted.RemoveAt(id_deleted);
                                AddedModelCurvesId.RemoveAt(id_Chain);
                            }
                        }

                        // 检测剔除后的集合中的曲线是否符合指定的连续性要求
                        if (this.CheckInTime)
                        {
                            if (this.CheckInTime)
                            {
                                CurvesState cs = ValidateCurves(AddedModelCurvesId, out blnContinueDraw);
                                RefreshUiAfterValidation(cs, blnContinueDraw);
                            }
                            else // 说明不进行实时检测,而直接继续绘制
                            {
                            }
                        }
                        else // 说明不进行实时检测,而直接继续绘制
                        {
                        }
                        //
                        return;
                    }

                    // 再考察修改对象的情况(因为在添加对象或者删除对象时,都有可能伴随有修改对象):在没有添加新对象,只作了修改的情况下,要么是对
                    int     modifiedCount        = 0;
                    Element modifiedCountElement = default(Element);
                    foreach (ElementId eid in e.GetModifiedElementIds())
                    {
                        modifiedCountElement = doc.GetElement(eid);
                        if (modifiedCountElement is ModelCurve)
                        {
                            modifiedCount++;
                        }
                    }
                    if (modifiedCount > 0)
                    {
                        // 检测剔除后的集合中的曲线是否符合指定的连续性要求
                        if (this.CheckInTime)
                        {
                            CurvesState cs = ValidateCurves(AddedModelCurvesId, out blnContinueDraw);
                            RefreshUiAfterValidation(cs, blnContinueDraw);
                        }
                        else // 说明不进行实时检测,而直接继续绘制
                        {
                        }
                        //
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("在绘制模型线及连续性判断时出问题啦~~~" + "\r\n" +
                                    ex.Message + ex.GetType().FullName + "\r\n" +
                                    ex.StackTrace);
                    // 结束绘制
                    this.FinishOnce(false, false);
                }
            }
        }
Exemplo n.º 23
0
 void Application_DocumentChanged(object sender, DocumentChangedEventArgs args)
 {
     var doc = args.GetDocument();
     ProcessUpdates(
         args.GetModifiedElementIds().Select(x => doc.GetElement(x).UniqueId).ToList(),
         args.GetDeletedElementIds().Select(x => doc.GetElement(x).UniqueId).ToList(),
         args.GetAddedElementIds().Select(x => doc.GetElement(x).UniqueId).ToList());
 }
Exemplo n.º 24
0
 void Application_DocumentChanged(object sender, DocumentChangedEventArgs args)
 {
     if (args.GetDocument().Equals(dynRevitSettings.Doc.Document))
     {
         this.processUpdates(
            args.GetModifiedElementIds(),
            args.GetDeletedElementIds(),
            args.GetAddedElementIds()
         );
     }
 }
Exemplo n.º 25
0
        /// <summary>
        /// The OnDocumentChanged: Update list revit element in model
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/></param>
        /// <param name="args">The args<see cref="DocumentChangedEventArgs"/></param>
        private void OnDocumentChanged(object sender, DocumentChangedEventArgs args)
        {
            Document doc = args.GetDocument();

            if (ModelProvider.Instance.CurrentModel == null ||
                ModelProvider.Instance.DicRevitElements == null)
            {
                return;
            }

            if (doc.Title == ModelProvider.Instance.CurrentModel.Title)
            {
                List <ElementId> elementIds = new List <ElementId>();

                foreach (ElementId id in args.GetAddedElementIds())
                {
                    Element e = doc.GetElement(id);
                    if (null != e.Category &&
                        0 < e.Parameters.Size &&
                        (e.Category.HasMaterialQuantities))
                    {
                        RevitElement revitElement = new RevitElement(e);

                        if (ModelProvider.Instance.DicRevitElements.ContainsKey(e.UniqueId))
                        {
                            ModelProvider.Instance.DicRevitElements.Remove(e.UniqueId);
                            ModelProvider.Instance.DicRevitElements.Add(e.UniqueId, revitElement);
                        }
                        else
                        {
                            ModelProvider.Instance.DicRevitElements.Add(e.UniqueId, revitElement);
                        }
                    }
                }
                foreach (ElementId id in args.GetDeletedElementIds())
                {
                    foreach (RevitElement item in ModelProvider.Instance.DicRevitElements.Values)
                    {
                        if (item.elementId == id.ToString())
                        {
                            ModelProvider.Instance.DicRevitElements.Remove(item.guid);
                            break;
                        }
                    }
                }
                foreach (ElementId id in args.GetModifiedElementIds())
                {
                    Element e = doc.GetElement(id);
                    if (null != e.Category &&
                        0 < e.Parameters.Size &&
                        (e.Category.HasMaterialQuantities))
                    {
                        RevitElement revitElement = new RevitElement(e);

                        if (ModelProvider.Instance.DicRevitElements.ContainsKey(e.UniqueId))
                        {
                            ModelProvider.Instance.DicRevitElements.Remove(e.UniqueId);
                            ModelProvider.Instance.DicRevitElements.Add(e.UniqueId, revitElement);
                        }
                    }
                }
            }
        }
Exemplo n.º 26
0
        public void GetElementDelete(object sender, DocumentChangedEventArgs args)
        {
            ICollection <ElementId> elementIds = args.GetDeletedElementIds();

            TaskDialog.Show("so luong element duoc add them", elementIds.Count.ToString());
        }