예제 #1
0
        private void ListInfo(Element elem, Document doc)
        {
            var message = string.Empty;

            message += "Element Id: " + elem.Id;

            // The workset the element belongs to
            WorksetId worksetId = elem.WorksetId;

            message += "\nWorkset Id : " + worksetId.ToString();

            // Model Updates Status of the element
            ModelUpdatesStatus updateStatus = WorksharingUtils.GetModelUpdatesStatus(doc, elem.Id);

            message += "\nUpdate status : " + updateStatus.ToString();

            // Checkout Status of the element
            CheckoutStatus checkoutStatus = WorksharingUtils.GetCheckoutStatus(doc, elem.Id);

            message += "\nCheckout status : " + checkoutStatus.ToString();

            // Getting WorksharingTooltipInfo of a given element Id
            WorksharingTooltipInfo tooltipInfo = WorksharingUtils.GetWorksharingTooltipInfo(doc, elem.Id);

            message += "\nCreator : " + tooltipInfo.Creator;
            message += "\nCurrent Owner : " + tooltipInfo.Owner;
            message += "\nLast Changed by : " + tooltipInfo.LastChangedBy;

            SCaddinsApp.WindowManager.ShowMessageBox("Additional Element Information", message);
        }
예제 #2
0
        public void DocumentOpened(object sender, DocumentOpenedEventArgs e)
        {
            Document doc = e.Document;

            if (doc.IsFamilyDocument)
            {
                return;
            }

            Schema schema = Schema.Lookup(schemaGUID);

            if (schema == null || !schema.IsValidObject)
            {
                return;
            }

            // Check to see if there is out-dated data stored in ProjectInformation
            Entity entity = null;

            entity = doc.ProjectInformation.GetEntity(schema);
            if (entity != null && entity.IsValid())
            {
                // Need to transition the data to a datastorage object.
                // First make sure this isn't a workshared document with the ProjectInfo already checked out by another user
                // If it's checked out by another person, we'll just skip this since we can't fix it now.
                if (doc.IsWorkshared && WorksharingUtils.GetCheckoutStatus(doc, doc.ProjectInformation.Id) == CheckoutStatus.OwnedByOtherUser)
                {
                    return;
                }

                // Otherwise, lets transition the data from the old to the new.
                if (entity.Get <IList <ElementId> >("ScheduleId") != null)
                {
                    // Get the information from the ProjectInformation entity
                    var schedIds = entity.Get <IList <ElementId> >("ScheduleId").ToList();
                    var paths    = entity.Get <IList <string> >("ExcelFilePath").ToList();
                    var wsNames  = entity.Get <IList <string> >("WorksheetName").ToList();
                    var dts      = entity.Get <IList <string> >("DateTime").ToList();
                    var pTypes   = entity.Get <IList <int> >("PathType")?.ToList() ?? new List <int>();

                    // Purge the old Schema and Entity, then assign the data to a new Schema and DataStorage element
                    RebuildSchema(doc, schema, schedIds, paths, wsNames, dts, pTypes);
                }
            }

            // Find if a datstorage element exists now and update as needed.
            DataStorage ds = new FilteredElementCollector(doc).OfClass(typeof(DataStorage)).Where(x => x.Name.Equals(dsName)).Cast <DataStorage>().FirstOrDefault();

            // Get the ExcelScheduleEntity from the data storage and verify its valid
            ExcelScheduleEntity ent = ds?.GetEntity <ExcelScheduleEntity>();

            if (ent == null)
            {
                return;
            }

            // Check if any schedules need to be updated
            List <int>      modifyIndices = new List <int>();
            List <DateTime> modDateTimes  = new List <DateTime>();

            for (int i = 0; i < ent.ScheduleId.Count; i++)
            {
                string currentFilePath;
                string docPath;
                if (doc.IsWorkshared)
                {
                    docPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(doc.GetWorksharingCentralModelPath());
                }
                else
                {
                    docPath = doc.PathName;
                }

                if ((PathType)ent.PathType[i] == PathType.Absolute)
                {
                    currentFilePath = ent.ExcelFilePath[i];
                }
                else
                {
                    currentFilePath = PathExchange.GetFullPath(ent.ExcelFilePath[i], docPath);
                }

                // Get the file write time as UTC
                DateTime modTime    = new FileInfo(currentFilePath).LastWriteTimeUtc;
                DateTime storedTime = Convert.ToDateTime(ent.DateTime[i]);

                // Make sure the save time isn't more or less the same as stored.
                if ((modTime - storedTime).Seconds > 1)
                {
                    modifyIndices.Add(i);
                    modDateTimes.Add(modTime);
                }
            }

            if (modifyIndices.Count == modDateTimes.Count && modifyIndices.Count > 0)
            {
                IntPtr statusBar = FindWindowEx(RevitHandle, IntPtr.Zero, "msctls_statusbar32", "");
                foreach (int i in modifyIndices)
                {
                    if (statusBar != IntPtr.Zero)
                    {
                        SetWindowText(statusBar, string.Format("Updating Excel Schedule {0}.", ent.WorksheetName[modifyIndices[i]]));
                    }
                    Scheduler scheduler = new Scheduler();
                    scheduler.ModifySchedule(doc, ent.ScheduleId[modifyIndices[i]], ent.ExcelFilePath[modifyIndices[i]],
                                             ent.WorksheetName[modifyIndices[i]], "Update Excel Schedule", ent.PathType[modifyIndices[i]],
                                             Properties.Settings.Default.reloadValuesOnly);

                    ent.DateTime[modifyIndices[i]] = modDateTimes[i].ToString();
                }
                if (statusBar != IntPtr.Zero)
                {
                    SetWindowText(statusBar, "");
                }

                // change the dateTimes
                using (Transaction t = new Transaction(doc, "Update schedule date"))
                {
                    t.Start();
                    ds.SetEntity(ent);
                    t.Commit();
                }

                // Write to home
                RevitCommon.FileUtils.WriteToHome("Excel Import - Document Open Reload", doc.Application.VersionName, doc.Application.Username);
            }
        }
예제 #3
0
        /// <summary>
        /// Submits edits to a sheet.
        /// </summary>
        /// <param name="app"></param>
        private void UpdateSheet(UIApplication app)
        {
            var doc = app.ActiveUIDocument.Document;

            CentralPath = FileInfoUtil.GetCentralFilePath(doc);

            IsUpdatingSheet = true;
            app.Application.FailuresProcessing += FailureProcessing;

            var view = doc.GetElement(SheetItem.UniqueId) as ViewSheet;

            if (view != null)
            {
                if (WorksharingUtils.GetCheckoutStatus(doc, view.Id) == CheckoutStatus.OwnedByOtherUser)
                {
                    IsUpdatingSheet = false;
                    Messenger.Default.Send(new SheetTaskCompletedMessage
                    {
                        Completed   = false,
                        Message     = "Element owned by another user. Try reloading latest.",
                        CentralPath = CentralPath
                    });
                    return;
                }
                using (var trans = new Transaction(doc, "UpdateSheet"))
                {
                    trans.Start();
                    var action = "update";
                    try
                    {
                        if (SheetTask.IsDeleted)
                        {
                            action = "delete";
                            doc.Delete(view.Id);
                        }
                        else
                        {
                            view.get_Parameter(BuiltInParameter.SHEET_NUMBER)?.Set(SheetTask.Number);
                            view.get_Parameter(BuiltInParameter.SHEET_NAME)?.Set(SheetTask.Name);
                        }

                        trans.Commit();
                        IsUpdatingSheet = false;
                    }
                    catch (Exception e)
                    {
                        trans.RollBack();
                        IsUpdatingSheet = false;

                        Log.AppendLog(LogMessageType.EXCEPTION, "Failed to " + action + " sheet.");
                        Messenger.Default.Send(new SheetTaskCompletedMessage
                        {
                            Completed   = false,
                            Message     = e.Message,
                            CentralPath = CentralPath
                        });
                    }
                }
            }

            // (Konrad) We don't want Revit to keep triggering this even when we are not processing updates.
            app.Application.FailuresProcessing -= FailureProcessing;
        }
예제 #4
0
        public void SetParameters(IEnumerable <SetParameterRequest> setParameterRequests)
        {
            var document = GetDocument();

            using (var trans = new Transaction(document, "Set parameters"))
            {
                if (trans.Start() == TransactionStatus.Started)
                {
                    var groupedRequests = setParameterRequests.GroupBy(x => x.ElementId);

                    foreach (var group in groupedRequests)
                    {
                        var element = document.GetElement(group.First().ElementId);
                        var status  = WorksharingUtils.GetCheckoutStatus(element.Document, element.Id);
                        if (status != CheckoutStatus.OwnedByOtherUser)
                        {
                            foreach (var setParameterRequest in group)
                            {
                                Parameter parameter = null;
                                if (int.TryParse(setParameterRequest.ParameterId, out int intValue))
                                {
                                    foreach (Parameter param in element.Parameters)
                                    {
                                        if (param.Id.IntegerValue == intValue)
                                        {
                                            parameter = param;
                                        }
                                    }
                                }

                                if (Guid.TryParse(setParameterRequest.ParameterId, out Guid guid))
                                {
                                    foreach (Parameter param in element.Parameters)
                                    {
                                        if (param.GUID == guid)
                                        {
                                            parameter = param;
                                        }
                                    }
                                }

                                if (parameter == null)
                                {
                                    if (Enum.TryParse(setParameterRequest.ParameterId, out BuiltInParameter bip) && Enum.IsDefined(typeof(BuiltInParameter), bip))
                                    {
                                        parameter = element.get_Parameter(bip);
                                    }
                                    else
                                    {
                                        parameter = element.GetParameters(setParameterRequest.ParameterId).FirstOrDefault();
                                    }
                                }

                                if (parameter != null)
                                {
                                    SetParameter(parameter, setParameterRequest.Value);
                                }
                            }
                        }
                        else
                        {
                            // Could not write parameter
                        }
                    }
                }
                trans.Commit();
            }
        }