示例#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);
     }
 }
示例#2
0
        private void ControlledApplicationOnDocumentChanged(object sender, DocumentChangedEventArgs documentChangedEventArgs)
        {
            var doc = documentChangedEventArgs.GetDocument();

            this.HandleDeletedElements(doc, documentChangedEventArgs.GetDeletedElementIds());
            this.HandleChangedElements(doc, documentChangedEventArgs.GetModifiedElementIds());
        }
        private void ElementCreated_AddToDictionary(object sender, DocumentChangedEventArgs e)
        {
            Document doc = e.GetDocument();

            ICollection <ElementId> createdElements = e.GetAddedElementIds();

            foreach (ElementId eid in createdElements)
            {
                Element ele = doc.GetElement(eid);

                try
                {
                    int elementIdKey = eid.IntegerValue;

                    if (ele.Category.Name != null)
                    {
                        string keyCategoryName = ele.Category.Name;
                        dictionaryDB.Add(elementIdKey, keyCategoryName);
                    }

                    //System.IO.File.AppendAllText(@"C:\Temp\RevitDB.txt", String.Format("{0} : {1}\n",elementIdKey, keyCategoryName));
                }
                catch
                {
                }
            }
        }
示例#4
0
        private void setInfos(DocumentChangedEventArgs e)
        {
            var doc = e.GetDocument();

            username     = doc.Application.Username;
            documentName = doc.Title;
        }
示例#5
0
        private void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            if (Committing)
            {
                return;
            }

            if (!ActiveDBDocument.Equals(e.GetDocument()))
            {
                return;
            }

            foreach (GH_Document definition in Grasshopper.Instances.DocumentServer)
            {
                foreach (var obj in definition.Objects)
                {
                    if (obj is RhinoInside.Revit.GH.Parameters.Element element)
                    {
                        if (element.SourceCount > 0)
                        {
                            continue;
                        }

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

                        element.ExpireSolution(false);
                    }
                    else if (obj is GH_Component component)
                    {
                        foreach (var param in component.Params.Output)
                        {
                            if (param is RhinoInside.Revit.GH.Parameters.Element outElement)
                            {
                                foreach (var goo in param.VolatileData.AllData(true))
                                {
                                    if (goo is IGH_PreviewMeshData previewMeshData)
                                    {
                                        previewMeshData.DestroyPreviewMeshes();
                                    }
                                }

                                foreach (var r in param.Recipients)
                                {
                                    r.ExpireSolution(false);
                                }
                            }
                        }
                    }
                }

                if (definition.Enabled)
                {
                    definition.NewSolution(false);
                }
            }
        }
示例#6
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());
        }
示例#7
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);
        }
示例#8
0
 void Application_DocumentChanged(object sender, DocumentChangedEventArgs args)
 {
     if (args.GetDocument().Equals(dynRevitSettings.Doc.Document))
     {
         processUpdates(
             args.GetModifiedElementIds(),
             args.GetDeletedElementIds(),
             args.GetAddedElementIds());
     }
 }
        internal void ControlledApplication_DocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            Document doc = e.GetDocument();


            ICollection <ElementId> modified = e.GetModifiedElementIds();

            foreach (ElementId id in modified)
            {
            }
        }
示例#10
0
        public void DocumentChangedForSomething(object sender, DocumentChangedEventArgs args)
        {
            Document  doc       = args.GetDocument();
            ModelPath modelPath = doc.GetWorksharingCentralModelPath();

            if (modelPath != null)                                                         //基于是否存在中心模型的文件位置,进行判断是否继续执行任务
            {
                aTimer.Interval  = 10000;                                                  //设置间隔时间为10000毫秒
                aTimer.AutoReset = true;                                                   //如果只执行一次(false)如果一直执行(true),使用bool值进行首尾控制
                aTimer.Enabled   = true;                                                   //timer可用
                aTimer.Elapsed  += new System.Timers.ElapsedEventHandler(NewSyncTimeSpan); //到达时间的时候执行指定方法
            }
        }
示例#11
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;
            }
        }
示例#12
0
        /// <summary>
        /// 监控新生成的tempFi
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            Document doc = e.GetDocument();

            foreach (ElementId id in e.GetAddedElementIds())
            {
                Element elem = doc.GetElement(id);
                if (elem is FamilyInstance &&
                    (elem as FamilyInstance).Symbol.FamilyName == "TempFi")
                {
                    tempFi2 = elem as FamilyInstance;
                }
            }
        }
示例#13
0
        public void OnChanged(object sender, DocumentChangedEventArgs e)
        {
            if (running)
            {
                return;
            }

            Document doc = e.GetDocument();

            if (docdict.ContainsKey(doc))
            {
                countdown  = 0;
                relinquish = false;
                sync       = false;
                close      = false;
            }
        }
        /// <summary>
        /// Обработка события DocumentChanged
        /// </summary>
        private void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            Document doc = e.GetDocument();

            View view = FindElevationView(
              doc, e.GetAddedElementIds());

            if (null != view)
            {
                string msg = string.Format(
                  "Вы только что создали новый вид Фасад "
                  + " '{0}'.",
                  view.Name);

                TaskDialog.Show("ElevationChecker", msg);
            }
        }
示例#15
0
        static void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            Document doc  = e.GetDocument();
            View     view = FindElevationView(doc, e.GetAddedElementIds());

            if (null != view)
            {
                string msg = string.Format("You just create an"
                                           + "elevation view '{0}'. Are you"
                                           + "sure you want to do that? "
                                           + "Elevations don't show hidden line"
                                           + "detail, which makes them unsuitable"
                                           + "for core wall elevations etc.",
                                           view.Name);
                TaskDialog.Show("ElevationChecker", msg);
            }
        }
示例#16
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;
            }
        }
示例#17
0
        private static void OnDocumentChanged(object sender, DocumentChangedEventArgs args)
        {
            if (isCommitting)
            {
                return;
            }

            var document = args.GetDocument();

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

            CancelReadActions();

            DocumentChanged?.Invoke(sender, args);
        }
        private void ElementCreated(object sender, DocumentChangedEventArgs e)
        {
            Document doc = e.GetDocument();

            string createdElementsIds = "";

            ICollection <ElementId> createdElements = e.GetAddedElementIds();

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

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

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

            m_MyDock.txtBoxCreated.Text = String.Format("{0} element(s) created: \n{1}", createdElements.Count, createdElementsIds);
        }
        /// <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 ViewCreated(object sender, DocumentChangedEventArgs e)
        {
            Document doc = e.GetDocument();

            ICollection <ElementId> createdElements = e.GetAddedElementIds();

            foreach (ElementId eid in createdElements)
            {
                Element ele = doc.GetElement(eid);
                if (ele.Category.Name == "Views")
                {
                    viewToOpen = ele as View;
                    m_MyDock.labelView.Text = String.Format("{0} {1}", ele.Name, eid.ToString());
                }
                else
                {
                    m_MyDock.labelView.Text = "-";
                }
            }
        }
        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);
                }
            }
        }
示例#22
0
        /// <summary>
        /// DocumentChanged event handler
        /// </summary>
        static void OnDocumentChanged(
            object sender,
            DocumentChangedEventArgs e)
        {
            Document doc = e.GetDocument();

            // To avoid reacting to family import,
            // ignore family documents:

            if (doc.IsFamilyDocument)
            {
                View view = FindElevationView(
                    doc, e.GetAddedElementIds());

                if (null != view)
                {
                    string msg = string.Format(
                        "You just created an "
                        + "elevation view '{0}'. Are you "
                        + "sure you want to do that? "
                        + "(Elevations don't show hidden line "
                        + "detail, which makes them unsuitable "
                        + "for core wall elevations etc.)",
                        view.Name);

                    TaskDialog.Show("ElevationChecker", msg);

                    // Make sure we see this warning once only
                    // Unsubscribing to the DocumentChanged event
                    // inside the DocumentChanged event handler
                    // causes a Revit message saying "Out of
                    // memory."

                    //doc.Application.DocumentChanged
                    //  -= new EventHandler<DocumentChangedEventArgs>(
                    //    OnDocumentChanged );
                }
            }
        }
示例#23
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);
                }
            }
        }
示例#24
0
 void Application_DocumentChanged(object sender, DocumentChangedEventArgs args)
 {
     if (args.GetDocument().Equals(DocumentManager.Instance.CurrentUIDocument.Document))
     {
         processUpdates(
            args.GetModifiedElementIds(),
            args.GetDeletedElementIds(),
            args.GetAddedElementIds());
     }
 }
示例#25
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);
                    }
                }
            }
        }
示例#26
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);
                        }
                    }
                }
            }
        }
示例#27
0
 private void OnDocChanged(object sender, DocumentChangedEventArgs e)
 {
     CreateImages(e.GetDocument());
     CollectFamilyData(e.GetDocument());
 }
示例#28
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"
                                )
                            );
                        }
                    }
                }
            }
        }
示例#29
0
 private void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
 {
     Messenger.Default.Send(new DocumentChanged(e.GetDeletedElementIds(), e.GetAddedElementIds(), e.GetDocument()));
 }
示例#30
0
 void Application_DocumentChanged(object sender, DocumentChangedEventArgs args)
 {
     if (args.GetDocument().Equals(dynRevitSettings.Doc.Document))
     {
         this.processUpdates(
            args.GetModifiedElementIds(),
            args.GetDeletedElementIds(),
            args.GetAddedElementIds()
         );
     }
 }
示例#31
0
 /// <summary>
 /// Raised when the document has changed
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 /// <param name="mainPage">Main Window</param>
 internal static void DocumentChanged(object sender, DocumentChangedEventArgs e, MainPage mainPage)
 {
     Document d = e.GetDocument();
 }
        /// <summary>
        /// DocumentChanged event handler
        /// </summary>
        static void OnDocumentChanged(
            object sender,
            DocumentChangedEventArgs e)
        {
            Document doc = e.GetDocument();

              // To avoid reacting to family import,
              // ignore family documents:

              if( doc.IsFamilyDocument )
              {
            View view = FindElevationView(
              doc, e.GetAddedElementIds() );

            if( null != view )
            {
              string msg = string.Format(
            "You just created an "
            + "elevation view '{0}'. Are you "
            + "sure you want to do that? "
            + "(Elevations don't show hidden line "
            + "detail, which makes them unsuitable "
            + "for core wall elevations etc.)",
            view.Name );

              TaskDialog.Show( "ElevationChecker", msg );

              // Make sure we see this warning once only
              // Unsubscribing to the DocumentChanged event
              // inside the DocumentChanged event handler
              // causes a Revit message saying "Out of
              // memory."

              //doc.Application.DocumentChanged
              //  -= new EventHandler<DocumentChangedEventArgs>(
              //    OnDocumentChanged );
            }
              }
        }
示例#33
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());
 }
示例#34
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;
      }
    }
示例#35
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);
                    }
                }
            }
        }
示例#36
0
        void OnDocumentChanged(object sender, DocumentChangedEventArgs args)
        {
            var elementDoc = args.GetDocument();

            var modifiedElementsId = args.GetModifiedElementIds();

            // Кэширование данных (маркеры изменения координат)
            ProjectLocation   projectLocation     = null;
            SiteLocation      siteLocation        = null;
            RevitLinkInstance rvtPositionProvider = null;
            ImportInstance    dwgPositionProvider = null;

            foreach (var elementId in modifiedElementsId)
            {
                var element = elementDoc.GetElement(elementId);

                // Пропускаем элементы, не относящиеся к данному файлу
                if (element.Document.Title != Globals.ActiveDocumentTitle)
                {
                    continue;
                }
                // Проверяем категорию изменённого элемента на принадлежность к маркерам изменения общих координат
                switch (element)
                {
                case ProjectLocation loc:
                    projectLocation = loc.Document.ActiveProjectLocation;
                    break;

                case RevitLinkInstance link:
                    rvtPositionProvider = link;
                    break;

                case ImportInstance link:
                    dwgPositionProvider = link;
                    break;

                case SiteLocation site:
                    siteLocation = site;
                    break;
                }
            }

            // Фильтруем события, не относящиеся к изменению площадок
            if (projectLocation == null)
            {
                return;
            }

            // ИВЕНТ ПРИНЯТИЯ КООРДИНАТ ИЗ СВЯЗИ
            if (siteLocation != null &&
                (rvtPositionProvider != null || dwgPositionProvider != null))
            {
                // не самый рабочий вариант, т.к. некрасивый и в случае с dwg - не предоставляет имя площадки провайдера
                var positionProviderName = dwgPositionProvider != null?dwgPositionProvider.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString() : rvtPositionProvider.Name;

                // Извлечение имени площадки файла-провайдера
                string extractedSiteName = null;
                var    providerSiteName  = positionProviderName.Split(':');
                if (providerSiteName.Count() > 1)
                {
                    var providerFileName = providerSiteName.Last().Trim();
                    var spaceIdx         = providerFileName.IndexOf(" ", StringComparison.Ordinal) + 1;

                    extractedSiteName = providerFileName.Substring(spaceIdx);
                }

                var logging = $"ProviderFileName: {positionProviderName}" +
                              $"SiteName: {projectLocation.Name}" +
                              $"ParentFile: {Globals.ActiveDocumentTitle}" +
                              $"ProviderSiteName: {extractedSiteName}";
            }

            // ИВЕНТ ИЗМЕНЕНИЯ КООРДИНАТ В ПРОЕКТЕ
            if (siteLocation == null)
            {
                var logging = $"ProviderFileName: {Globals.ActiveDocumentTitle}" +
                              $"SiteName: {projectLocation.Name}" +
                              $"ParentFile: {Globals.ActiveDocumentTitle}";
            }
        }
示例#37
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);
        }