private void RefreshSelectedSheet()
        {
            RevitSheet tempSheet = selectedSheet;

            this.SelectedSheet = null;
            this.SelectedSheet = tempSheet;
        }
        private static bool CompareSheetParameters(ViewSheet viewSheet, RevitSheet rvtSheet, RevitSheetData sheetData, out string tooltip)
        {
            bool modified = false;

            tooltip = "";
            try
            {
                if (viewSheet.SheetNumber != rvtSheet.Number || viewSheet.ViewName != rvtSheet.Name)
                {
                    modified = true;
                    tooltip  = "Sheet number or sheet name is different from the linked element.";
                }
                else
                {
                    foreach (SheetParameter sheetParam in sheetData.SheetParameters)
                    {
                        if (rvtSheet.SheetParameters.ContainsKey(sheetParam.ParameterId))
                        {
                            SheetParameterValue paramValue = rvtSheet.SheetParameters[sheetParam.ParameterId];
                            Parameter           param      = viewSheet.LookupParameter(sheetParam.ParameterName);
                            if (null != param)
                            {
                                string paramValueStr = "";
                                switch (param.StorageType)
                                {
                                case StorageType.Double:
                                    paramValueStr = param.AsDouble().ToString();
                                    break;

                                case StorageType.ElementId:
                                    paramValueStr = param.AsElementId().IntegerValue.ToString();
                                    break;

                                case StorageType.Integer:
                                    paramValueStr = param.AsInteger().ToString();
                                    break;

                                case StorageType.String:
                                    paramValueStr = param.AsString();
                                    break;
                                }

                                if (paramValueStr != paramValue.ParameterValue.ToString())
                                {
                                    modified = true;
                                    tooltip  = sheetParam.ParameterName + " values are different from the linked element.";
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(modified);
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ObservableCollection<RevitView> filteredViews = new ObservableCollection<RevitView>();
            if (values.Length == 2)
            {
                ObservableCollection<RevitView> views = values[0] as ObservableCollection<RevitView>;
                RevitSheet selectedSheet = values[1] as RevitSheet;

                if (null != views && null != selectedSheet)
                {
                    var selectedViews = from view in views where view.Sheet.Id == selectedSheet.Id select view;
                    filteredViews = new ObservableCollection<RevitView>(selectedViews.OrderBy(o => o.Name).ToList());
                }
            }
            return filteredViews;
        }
        public static object SetPropertyValue(object item, string propertyName, object value)
        {
            object updatedItem = item;

            try
            {
                if (updatedItem.GetType() == typeof(RevitSheet))
                {
                    switch (propertyName)
                    {
                    case "Sheet Number":
                        (updatedItem as RevitSheet).Number = value.ToString();
                        break;

                    case "Sheet Name":
                        (updatedItem as RevitSheet).Name = value.ToString();
                        break;

                    case "Discipline":
                        (updatedItem as RevitSheet).DisciplineObj = value as Discipline;
                        break;

                    default:
                        RevitSheet sheet        = updatedItem as RevitSheet;
                        var        paramIdFound = from paramVal in sheet.SheetParameters.Values where paramVal.Parameter.ParameterName == propertyName select paramVal.Parameter.ParameterId;
                        if (paramIdFound.Count() > 0)
                        {
                            Guid paramId = paramIdFound.First();
                            if ((updatedItem as RevitSheet).SheetParameters.ContainsKey(paramId))
                            {
                                (updatedItem as RevitSheet).SheetParameters[paramId].ParameterValue = value.ToString();
                            }
                        }
                        break;
                    }
                }
                else
                {
                    updatedItem.GetType().GetProperty(propertyName).SetValue(updatedItem, value);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(updatedItem);
        }
Example #5
0
        private bool DeleteSheet(ElementId sheetId)
        {
            bool deleted = false;

            try
            {
                if (idMaps.ContainsKey(sheetId))
                {
                    string      uniqueId    = idMaps[sheetId];
                    LinkedSheet linkedSheet = dataManager.GetLinkedSheet(uniqueId, linkedProjectId);
                    if (null != linkedSheet)
                    {
                        if (linkedSheet.IsSource)
                        {
                            MessageBoxResult msgResult = MessageBox.Show("Would you like to delete the sheet item in the linked database?", "Delete Sheet Source Item", MessageBoxButton.YesNo, MessageBoxImage.Question);
                            if (msgResult == MessageBoxResult.Yes)
                            {
                                RevitSheet rvtSheet = new RevitSheet()
                                {
                                    Id = linkedSheet.SheetId
                                };
                                bool sheetDeleted    = SheetDataWriter.ChangeSheetItem(rvtSheet, CommandType.DELETE);
                                bool paramDeleted    = SheetDataWriter.DeleteSheetParameterValue(rvtSheet.Id.ToString());
                                bool revisionDeleted = SheetDataWriter.DeleteRevisionOnSheet("RevisionsOnSheet_Sheet_Id", rvtSheet.Id.ToString());
                                bool linkDeleted     = SheetDataWriter.ChangeLinkedSheet(linkedSheet, CommandType.DELETE);
                                deleted = (sheetDeleted && paramDeleted && revisionDeleted && linkDeleted) ? true : false;
                            }
                            else
                            {
                                deleted = SheetDataWriter.ChangeLinkedSheet(linkedSheet, CommandType.DELETE);
                            }
                        }
                        else
                        {
                            deleted = SheetDataWriter.ChangeLinkedSheet(linkedSheet, CommandType.DELETE);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(deleted);
        }
        private static bool UpdateDatabaseItem(object item, string propertyName, object propertyValue)
        {
            bool databaseUpdated = false;

            try
            {
                if (item.GetType() == typeof(RevitSheet))
                {
                    RevitSheet sheet = item as RevitSheet;
                    switch (propertyName)
                    {
                    case "Sheet Number":
                        databaseUpdated = SheetDataWriter.ChangeSheetItem(sheet.Id.ToString(), propertyName, propertyValue.ToString());
                        break;

                    case "Sheet Name":
                        databaseUpdated = SheetDataWriter.ChangeSheetItem(sheet.Id.ToString(), propertyName, propertyValue.ToString());
                        break;

                    case "Discipline":
                        Discipline discipline = propertyValue as Discipline;
                        if (null != discipline)
                        {
                            databaseUpdated = SheetDataWriter.ChangeSheetItem(sheet.Id.ToString(), propertyName, discipline.Id.ToString());
                        }
                        break;

                    default:
                        var paramValueFound = from paramValue in sheet.SheetParameters.Values where paramValue.Parameter.ParameterName == propertyName select paramValue;
                        if (paramValueFound.Count() > 0)
                        {
                            SheetParameterValue paramValue = paramValueFound.First();
                            paramValue.ParameterValue = propertyValue.ToString();
                            databaseUpdated           = SheetDataWriter.ChangeSheetParameterValue(paramValue, HOK.SheetManager.Database.CommandType.UPDATE);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(databaseUpdated);
        }
        public static bool ChangeSheetItem(RevitSheet item, CommandType cmdType)
        {
            bool result = false;

            try
            {
                if (null != connection && null != command)
                {
                    switch (cmdType)
                    {
                    case CommandType.INSERT:
                        command.CommandText = @"INSERT INTO Sheets (Sheet_Id, Sheet_Number, Sheet_Name, Sheet_Discipline_Id)" +
                                              "VALUES ('" + item.Id.ToString() + "', '" + item.Number + "', '" + item.Name + "', '" + item.DisciplineObj.Id.ToString() + "')";
                        if (command.ExecuteNonQuery() > 0)
                        {
                            result = true;
                        }
                        break;

                    case CommandType.UPDATE:
                        command.CommandText = @"UPDATE Sheets SET Sheet_Number = '" + item.Number + "', Sheet_Name = '" + item.Name + "', Sheet_Discipline_Id ='" + item.DisciplineObj.Id.ToString() + "'" +
                                              " WHERE Sheet_Id = '" + item.Id.ToString() + "'";
                        if (command.ExecuteNonQuery() > 0)
                        {
                            result = true;
                        }
                        break;

                    case CommandType.DELETE:
                        command.CommandText = "DELETE FROM Sheets WHERE Sheet_Id = '" + item.Id.ToString() + "'";
                        if (command.ExecuteNonQuery() > 0)
                        {
                            result = true;
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(result);
        }
        public static object GetPropertyValue(object item, string propertyName)
        {
            object value = null;

            try
            {
                if (item.GetType() == typeof(RevitSheet))
                {
                    RevitSheet sheet = item as RevitSheet;
                    switch (propertyName)
                    {
                    case "Sheet Number":
                        value = sheet.Number;
                        break;

                    case "Sheet Name":
                        value = sheet.Name;
                        break;

                    case "Discipline":
                        value = sheet.DisciplineObj;
                        break;

                    default:
                        var paramValueFound = from paramVal in sheet.SheetParameters.Values where paramVal.Parameter.ParameterName == propertyName select paramVal;
                        if (paramValueFound.Count() > 0)
                        {
                            SheetParameterValue paramValue = paramValueFound.First();
                            value = paramValue.ParameterValue;
                        }
                        break;
                    }
                }
                else
                {
                    value = item.GetType().GetProperty(propertyName).GetValue(item, null);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(value);
        }
 private void dataGridSheet_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
 {
     try
     {
         if (dataGridSheet.SelectedCells.Count > 0)
         {
             DataGridCellInfo cellInfo      = dataGridSheet.SelectedCells.First();
             RevitSheet       selectedSheet = cellInfo.Item as RevitSheet;
             if (null != selectedSheet)
             {
                 dataGridLinks.ItemsSource = null;
                 dataGridLinks.ItemsSource = selectedSheet.LinkedSheets;
             }
         }
     }
     catch (Exception ex)
     {
         string message = ex.Message;
     }
 }
        private void SearchByText(string fieldName, string searchText)
        {
            try
            {
                ICollectionView cv = CollectionViewSource.GetDefaultView(dataGridSheet.ItemsSource);
                if (!string.IsNullOrEmpty(searchText))
                {
                    switch (fieldName)
                    {
                    case "Sheet Number":
                        cv.Filter = o => { RevitSheet sheet = o as RevitSheet; return(sheet.Number.ToUpper().Contains(searchText.ToUpper())); };
                        break;

                    case "Sheet Name":
                        cv.Filter = o => { RevitSheet sheet = o as RevitSheet; return(sheet.Name.ToUpper().Contains(searchText.ToUpper())); };
                        break;

                    case "Discipline":
                        cv.Filter = o => { RevitSheet sheet = o as RevitSheet; return(sheet.DisciplineObj.Name.ToUpper().Contains(searchText.ToUpper())); };
                        break;

                    default:
                        var paramFound = from param in rvtSheetData.SheetParameters where param.ParameterName == fieldName select param;
                        if (paramFound.Count() > 0)
                        {
                            SheetParameter sheetParam = paramFound.First();
                            cv.Filter = o => { RevitSheet sheet = o as RevitSheet; return(sheet.SheetParameters[sheetParam.ParameterId].ParameterValue.ToString().ToUpper().Contains(searchText.ToUpper())); };
                        }
                        break;
                    }
                }
                else
                {
                    cv.Filter = null;
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     ObservableCollection<LinkedSheet> linkedSheets = new ObservableCollection<LinkedSheet>();
     if (null != value)
     {
         IList<DataGridCellInfo> cellInfoList = value as IList<DataGridCellInfo>;
         if (null != cellInfoList)
         {
             if (cellInfoList.Count > 0)
             {
                 DataGridCellInfo cellInfo = cellInfoList.First();
                 RevitSheet selectedSheet = cellInfo.Item as RevitSheet;
                 if (null != selectedSheet)
                 {
                     linkedSheets = selectedSheet.LinkedSheets;
                 }
             }
         }
     }
     return linkedSheets;
 }
Example #12
0
        private RevisionOnSheet GetRevisionOnSheet(CheckBox checkBox)
        {
            RevisionOnSheet ros        = null;
            Guid            revisionId = Guid.Empty;

            try
            {
                Binding binding        = BindingOperations.GetBinding(checkBox, ToggleButton.IsCheckedProperty);
                string  sortMemberPath = binding.Path.Path;
                var     mg             = Regex.Match(sortMemberPath, @"\[(.*?)\]");
                if (mg.Success)
                {
                    string value = mg.Groups[1].Value;
                    revisionId = new Guid(value);
                }

                var parent = VisualTreeHelper.GetParent(checkBox);
                while (parent != null && parent.GetType() != typeof(DataGridRow))
                {
                    parent = VisualTreeHelper.GetParent(parent);
                }
                DataGridRow datarow = parent as DataGridRow;
                if (null != datarow)
                {
                    RevitSheet sheet = datarow.Item as RevitSheet;
                    if (null != sheet)
                    {
                        if (sheet.SheetRevisions.ContainsKey(revisionId))
                        {
                            ros = sheet.SheetRevisions[revisionId];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to checked Ids.\n" + ex.Message, "Get Checked Ids", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(ros);
        }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ObservableCollection <RevitRevision> filteredRevisions = new ObservableCollection <RevitRevision>();

            if (values.Length == 2)
            {
                ObservableCollection <RevitRevision> revisions = values[0] as ObservableCollection <RevitRevision>;
                RevitSheet selectedSheet = values[1] as RevitSheet;

                if (null != revisions && null != selectedSheet)
                {
                    var includeRevisionIds = from ros in selectedSheet.SheetRevisions.Values where ros.Include select ros.RvtRevision.Id;
                    if (includeRevisionIds.Count() > 0)
                    {
                        var revisionFound = from rev in revisions where includeRevisionIds.Contains(rev.Id) select rev;
                        if (revisionFound.Count() > 0)
                        {
                            filteredRevisions = new ObservableCollection <RevitRevision>(revisionFound.ToList());
                        }
                    }
                }
            }
            return(filteredRevisions);
        }
Example #14
0
        private bool InsertSheet(ViewSheet sheet)
        {
            bool sheetInserted = false;

            try
            {
                // insert into the database connected
                RevitSheet  rvtSheet    = new RevitSheet(Guid.NewGuid(), sheet.SheetNumber, sheet.ViewName);
                LinkedSheet linkedSheet = new LinkedSheet(Guid.NewGuid(), rvtSheet.Id, new LinkedProject(linkedProjectId), sheet.UniqueId, true);
                rvtSheet.LinkedSheets.Add(linkedSheet);
                bool sheetDBUpdated       = SheetDataWriter.ChangeSheetItem(rvtSheet, CommandType.INSERT);
                bool linkedSheetDBUpdated = SheetDataWriter.ChangeLinkedSheet(linkedSheet, CommandType.INSERT);

                List <SheetParameterValue> paramValues = new List <SheetParameterValue>();
                foreach (SheetParameter sheetParam in rvtSheetParameters)
                {
                    SheetParameterValue paramValue = new SheetParameterValue();
                    paramValue.ParameterValueId = Guid.NewGuid();
                    paramValue.Parameter        = sheetParam;
                    paramValue.SheetId          = rvtSheet.Id;

                    Parameter param = sheet.LookupParameter(sheetParam.ParameterName);
                    if (null != param)
                    {
                        switch (param.StorageType)
                        {
                        case StorageType.Double:
                            paramValue.ParameterValue = param.AsDouble().ToString();
                            break;

                        case StorageType.ElementId:
                            paramValue.ParameterValue = param.AsElementId().IntegerValue.ToString();
                            break;

                        case StorageType.Integer:
                            paramValue.ParameterValue = param.AsInteger().ToString();
                            break;

                        case StorageType.String:
                            paramValue.ParameterValue = param.AsString();
                            break;
                        }
                    }
                    paramValues.Add(paramValue);
                }
                bool sheetParamDBUpdated = SheetDataWriter.InsertMultipleParameterValue(paramValues);

                List <Guid>            revisionIds = dataManager.GetRevisionIds();
                List <RevisionOnSheet> rosList     = new List <RevisionOnSheet>();

                foreach (Guid revisionId in revisionIds)
                {
                    RevitRevision rvtRevision = new RevitRevision();
                    rvtRevision.Id = revisionId;
                    RevisionOnSheet ros = new RevisionOnSheet(Guid.NewGuid(), rvtSheet.Id, rvtRevision, false);
                    rvtSheet.SheetRevisions.Add(rvtRevision.Id, ros);
                    rosList.Add(ros);
                }
                bool rosDBUpdated = SheetDataWriter.InsertMultipleRevisionOnSheet(rosList);

                sheetInserted = (sheetDBUpdated && linkedSheetDBUpdated && rosDBUpdated) ? true : false;

                if (sheetInserted && !idMaps.ContainsKey(sheet.Id))
                {
                    idMaps.Add(sheet.Id, sheet.UniqueId);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(sheetInserted);
        }
        private static void ReadRevitSheets(ref RevitSheetData sheetData)
        {
            try
            {
                ObservableCollection <LinkedSheet> linkedSheets = new ObservableCollection <LinkedSheet>();
                using (SQLiteCommand cmd = new SQLiteCommand(connection))
                {
                    cmd.CommandText = "SELECT * FROM LinkedSheets";
                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            LinkedSheet lSheet = new LinkedSheet();
                            lSheet.Id      = reader.GetGuid(reader.GetOrdinal("LinkedSheet_Id"));
                            lSheet.SheetId = reader.GetGuid(reader.GetOrdinal("LinkedSheet_Sheet_Id"));
                            Guid projectId    = reader.GetGuid(reader.GetOrdinal("LinkedSheet_Project_Id"));
                            var  projectFound = from project in sheetData.LinkedProjects where project.Id == projectId select project;
                            if (projectFound.Count() > 0)
                            {
                                lSheet.LinkProject = projectFound.First();
                            }

                            lSheet.LinkedElementId = reader.GetString(reader.GetOrdinal("LinkedSheet_Element_Id"));
                            lSheet.IsSource        = reader.GetBoolean(reader.GetOrdinal("LinkedSheet_IsSource"));

                            linkedSheets.Add(lSheet);
                        }
                    }
                }

                ObservableCollection <SheetParameterValue> sheetParameterValues = new ObservableCollection <SheetParameterValue>();
                using (SQLiteCommand cmd = new SQLiteCommand(connection))
                {
                    cmd.CommandText = "SELECT * FROM SheetParameterValues";
                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            SheetParameterValue paramValue = new SheetParameterValue();
                            paramValue.ParameterValueId = reader.GetGuid(reader.GetOrdinal("ParameterValue_Id"));
                            paramValue.SheetId          = reader.GetGuid(reader.GetOrdinal("ParameterValue_Sheet_Id"));
                            Guid parameterId = reader.GetGuid(reader.GetOrdinal("ParameterValue_Parameter_Id"));
                            var  paramFound  = from param in sheetData.SheetParameters where param.ParameterId == parameterId select param;
                            if (paramFound.Count() > 0)
                            {
                                paramValue.Parameter = paramFound.First();
                            }
                            paramValue.ParameterValue = reader.GetString(reader.GetOrdinal("ParameterValue_Parameter_Value"));
                            sheetParameterValues.Add(paramValue);
                        }
                    }
                }

                ObservableCollection <RevisionOnSheet> revisionOnSheets = new ObservableCollection <RevisionOnSheet>();
                using (SQLiteCommand cmd = new SQLiteCommand(connection))
                {
                    cmd.CommandText = "SELECT * FROM RevisionsOnSheet";
                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            RevisionOnSheet ros = new RevisionOnSheet();
                            ros.MapId   = reader.GetGuid(reader.GetOrdinal("RevisionsOnSheet_Id"));
                            ros.SheetId = reader.GetGuid(reader.GetOrdinal("RevisionsOnSheet_Sheet_Id"));

                            Guid revisionId    = reader.GetGuid(reader.GetOrdinal("RevisionsOnSheet_Revision_Id"));
                            var  revisionFound = from rev in sheetData.Revisions where rev.Id == revisionId select rev;
                            if (revisionFound.Count() > 0)
                            {
                                ros.RvtRevision = revisionFound.First();
                            }
                            ros.Include = reader.GetBoolean(reader.GetOrdinal("RevisionsOnSheet_Include"));

                            revisionOnSheets.Add(ros);
                        }
                    }
                }


                sheetData.Sheets.Clear();
                using (SQLiteCommand cmd = new SQLiteCommand(connection))
                {
                    cmd.CommandText = "SELECT * FROM Sheets";
                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            RevitSheet sheet = new RevitSheet();
                            sheet.Id     = reader.GetGuid(reader.GetOrdinal("Sheet_Id"));
                            sheet.Number = reader.GetString(reader.GetOrdinal("Sheet_Number"));
                            sheet.Name   = reader.GetString(reader.GetOrdinal("Sheet_Name"));

                            Guid disciplineId    = reader.GetGuid(reader.GetOrdinal("Sheet_Discipline_Id"));
                            var  disciplineFound = from discipline in sheetData.Disciplines where discipline.Id == disciplineId select discipline;
                            if (disciplineFound.Count() > 0)
                            {
                                sheet.DisciplineObj = disciplineFound.First();
                            }

                            var linkedSheetFound = from linkedSheet in linkedSheets where linkedSheet.SheetId == sheet.Id select linkedSheet;
                            if (linkedSheetFound.Count() > 0)
                            {
                                sheet.LinkedSheets = new ObservableCollection <LinkedSheet>(linkedSheetFound.ToList());
                            }

                            foreach (SheetParameter param in sheetData.SheetParameters)
                            {
                                var parameterValueFound = from paramValue in sheetParameterValues where paramValue.SheetId == sheet.Id && paramValue.Parameter.ParameterId == param.ParameterId select paramValue;
                                if (parameterValueFound.Count() > 0)
                                {
                                    SheetParameterValue value = parameterValueFound.First();
                                    sheet.SheetParameters.Add(param.ParameterId, value);
                                }
                            }

                            var revisionOnSheetFound = from ros in revisionOnSheets where ros.SheetId == sheet.Id select ros;
                            if (revisionOnSheetFound.Count() > 0)
                            {
                                foreach (RevisionOnSheet ros in revisionOnSheetFound)
                                {
                                    if (!sheet.SheetRevisions.ContainsKey(ros.RvtRevision.Id))
                                    {
                                        sheet.SheetRevisions.Add(ros.RvtRevision.Id, ros);
                                    }
                                }
                            }

                            sheetData.Sheets.Add(sheet);
                        }
                    }
                }
                sheetData.Sheets = new ObservableCollection <RevitSheet>(sheetData.Sheets.OrderBy(o => o.Number));
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
        private void dataGridView_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            try
            {
                DataGridRow row = e.Row;
                if (null != row)
                {
                    RevitView oldView      = row.Item as RevitView;
                    string    propertyName = e.Column.Header.ToString();

                    switch (propertyName)
                    {
                    case "View Name":
                        TextBox textBoxName = e.EditingElement as TextBox;
                        if (null != textBoxName)
                        {
                            bool databaseUpdated = SheetDataWriter.ChangeViewItem(oldView.Id.ToString(), propertyName, textBoxName.Text);
                        }
                        break;

                    case "Sheet Number":
                        ComboBox comboBoxSheet = e.EditingElement as ComboBox;
                        if (null != comboBoxSheet)
                        {
                            RevitSheet selectedSheet = comboBoxSheet.SelectedItem as RevitSheet;
                            if (null != selectedSheet)
                            {
                                bool databaseUpdated = SheetDataWriter.ChangeViewItem(oldView.Id.ToString(), propertyName, selectedSheet.Id.ToString());
                            }
                        }
                        break;

                    case "View Type":
                        ComboBox comboBoxViewType = e.EditingElement as ComboBox;
                        if (null != comboBoxViewType)
                        {
                            RevitViewType selectedViewType = comboBoxViewType.SelectedItem as RevitViewType;
                            if (null != selectedViewType)
                            {
                                bool databaseUpdated = SheetDataWriter.ChangeViewItem(oldView.Id.ToString(), propertyName, selectedViewType.Id.ToString());
                            }
                        }
                        break;

                    case "U":
                        TextBox textBoxU = e.EditingElement as TextBox;
                        if (null != textBoxU)
                        {
                            double uValue;
                            if (double.TryParse(textBoxU.Text, out uValue))
                            {
                                bool databaseUpdated = SheetDataWriter.ChangeViewItem(oldView.Id.ToString(), propertyName, uValue);
                            }
                        }
                        break;

                    case "V":
                        TextBox textBoxV = e.EditingElement as TextBox;
                        if (null != textBoxV)
                        {
                            double vValue;
                            if (double.TryParse(textBoxV.Text, out vValue))
                            {
                                bool databaseUpdated = SheetDataWriter.ChangeViewItem(oldView.Id.ToString(), propertyName, vValue);
                            }
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
        private static void CheckSheetLinks(Document doc, Guid projectId, ref RevitSheetData sheetData)
        {
            try
            {
                Dictionary <Guid /*revisionId*/, int /*elementId*/> revDictionary = new Dictionary <Guid, int>();
                var linkedRevisions = from revision in sheetData.Revisions where revision.LinkStatus.IsLinked select revision;
                if (linkedRevisions.Count() > 0)
                {
                    revDictionary = linkedRevisions.ToDictionary(o => o.Id, o => o.LinkStatus.LinkedElementId);
                }

                for (int i = 0; i < sheetData.Sheets.Count; i++)
                {
                    RevitSheet rvtSheet = sheetData.Sheets[i];

                    var linkedSheetFound = from lsheet in sheetData.Sheets[i].LinkedSheets where lsheet.LinkProject.Id == projectId select lsheet;
                    if (linkedSheetFound.Count() > 0)
                    {
                        LinkedSheet linkedSheet = linkedSheetFound.First();
                        ViewSheet   viewSheet   = doc.GetElement(linkedSheet.LinkedElementId) as ViewSheet;
                        if (null != viewSheet)
                        {
                            sheetData.Sheets[i].LinkStatus.IsLinked        = true;
                            sheetData.Sheets[i].LinkStatus.CurrentLinkedId = linkedSheet.LinkedElementId;
                            sheetData.Sheets[i].LinkStatus.LinkedElementId = viewSheet.Id.IntegerValue;
                            sheetData.Sheets[i].LinkStatus.ToolTip         = "Linked Sheet ElementId: " + viewSheet.Id.IntegerValue;

                            //parameter check
                            string toolTip = "";
                            if (CompareSheetParameters(viewSheet, sheetData.Sheets[i], sheetData, out toolTip))
                            {
                                sheetData.Sheets[i].LinkStatus.Modified = true;
                                sheetData.Sheets[i].LinkStatus.ToolTip  = toolTip;
                            }
                            var viewRevisionIds = from elementId in viewSheet.GetAllRevisionIds() select elementId.IntegerValue;
                            //revision check
                            foreach (Guid revisionId in rvtSheet.SheetRevisions.Keys)
                            {
                                RevisionOnSheet ros = rvtSheet.SheetRevisions[revisionId];

                                var revisionFound = from revision in sheetData.Revisions where revision.Id == revisionId select revision;
                                if (revisionFound.Count() > 0)
                                {
                                    RevitRevision rvtRevision = revisionFound.First();
                                    sheetData.Sheets[i].SheetRevisions[revisionId].RvtRevision = rvtRevision;

                                    if (rvtRevision.LinkStatus.IsLinked)
                                    {
                                        if (ros.Include && viewRevisionIds.Contains(rvtRevision.LinkStatus.LinkedElementId))
                                        {
                                            sheetData.Sheets[i].SheetRevisions[revisionId].LinkStatus.IsLinked = true;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            //item deleted
                            sheetData.Sheets[i].LinkedSheets.Remove(linkedSheet);
                            bool linkedSheetDBUpdated = SheetDataWriter.ChangeLinkedSheet(linkedSheet, CommandType.DELETE);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to check link status of sheets.\n" + ex.Message, "Sheet Manager Updater - Check Sheet Links", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        public static bool InsertNewSheet(ViewSheet sheet, Guid projectId, ref RevitSheetData sheetData)
        {
            bool inserted = false;

            try
            {
                var sheetNumberExisting = from rvtSheet in sheetData.Sheets where rvtSheet.Number == sheet.SheetNumber select rvtSheet;
                if (sheetNumberExisting.Count() > 0)
                {
                    RevitSheet rvtSheet   = sheetNumberExisting.First();
                    int        sheetIndex = sheetData.Sheets.IndexOf(rvtSheet);

                    LinkedSheet linkedSheet = new LinkedSheet(Guid.NewGuid(), rvtSheet.Id, new LinkedProject(projectId), sheet.UniqueId, false);
                    sheetData.Sheets[sheetIndex].LinkedSheets.Add(linkedSheet);

                    bool linkedSheetDBUpdated = SheetDataWriter.ChangeLinkedSheet(linkedSheet, CommandType.INSERT);

                    RevitLinkStatus linkStatus = new RevitLinkStatus();
                    linkStatus.IsLinked        = true;
                    linkStatus.CurrentLinkedId = sheet.UniqueId;
                    linkStatus.LinkedElementId = sheet.Id.IntegerValue;
                    linkStatus.ToolTip         = "Linked Sheet ElementId: " + sheet.Id.IntegerValue;

                    string toolTip = "";
                    if (CompareSheetParameters(sheet, rvtSheet, sheetData, out toolTip))
                    {
                        linkStatus.Modified = true;
                        linkStatus.ToolTip  = toolTip;
                    }

                    sheetData.Sheets[sheetIndex].LinkStatus = linkStatus;
                    inserted = true;
                }
                else
                {
                    RevitSheet  rvtSheet    = new RevitSheet(Guid.NewGuid(), sheet.SheetNumber, sheet.ViewName);
                    LinkedSheet linkedSheet = new LinkedSheet(Guid.NewGuid(), rvtSheet.Id, new LinkedProject(projectId), sheet.UniqueId, true);
                    rvtSheet.LinkedSheets.Add(linkedSheet);
                    bool sheetDBUpdated       = SheetDataWriter.ChangeSheetItem(rvtSheet, CommandType.INSERT);
                    bool linkedSheetDBUpdated = SheetDataWriter.ChangeLinkedSheet(linkedSheet, CommandType.INSERT);

                    RevitLinkStatus linkStatus = new RevitLinkStatus();
                    linkStatus.IsLinked        = true;
                    linkStatus.CurrentLinkedId = sheet.UniqueId;
                    linkStatus.LinkedElementId = sheet.Id.IntegerValue;
                    linkStatus.ToolTip         = "Linked Sheet ElementId: " + sheet.Id.IntegerValue;

                    rvtSheet.LinkStatus = linkStatus;

                    foreach (SheetParameter sheetParam in sheetData.SheetParameters)
                    {
                        SheetParameterValue paramValue = new SheetParameterValue();
                        paramValue.ParameterValueId = Guid.NewGuid();
                        paramValue.Parameter        = sheetParam;
                        paramValue.SheetId          = rvtSheet.Id;

                        Parameter param = sheet.LookupParameter(sheetParam.ParameterName);
                        if (null != param)
                        {
                            switch (param.StorageType)
                            {
                            case StorageType.Double:
                                paramValue.ParameterValue = param.AsDouble().ToString();
                                break;

                            case StorageType.ElementId:
                                paramValue.ParameterValue = param.AsElementId().IntegerValue.ToString();
                                break;

                            case StorageType.Integer:
                                paramValue.ParameterValue = param.AsInteger().ToString();
                                break;

                            case StorageType.String:
                                paramValue.ParameterValue = param.AsString();
                                break;
                            }
                        }

                        rvtSheet.SheetParameters.Add(sheetParam.ParameterId, paramValue);
                    }
                    bool sheetParamDBUpdated = SheetDataWriter.InsertMultipleParameterValue(rvtSheet.SheetParameters.Values.ToList());

                    List <RevisionOnSheet> rosList = new List <RevisionOnSheet>();
                    foreach (RevitRevision revision in sheetData.Revisions)
                    {
                        RevisionOnSheet ros = new RevisionOnSheet(Guid.NewGuid(), rvtSheet.Id, revision, false);
                        rvtSheet.SheetRevisions.Add(revision.Id, ros);
                        rosList.Add(ros);
                    }
                    bool rosDBUpdated = SheetDataWriter.InsertMultipleRevisionOnSheet(rosList);
                    sheetData.Sheets.Add(rvtSheet);

                    inserted = (sheetDBUpdated && linkedSheetDBUpdated && rosDBUpdated) ? true : false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to add a new sheet element.\n" + ex.Message, "New Sheet", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(inserted);
        }
Example #19
0
 public MessageInfo(RevitSheet sheet, string messageStr)
 {
     dbId     = sheet.Id;
     itemName = sheet.Number + " " + sheet.Name;
     message  = messageStr;
 }
 public ItemWindow(AddItemType type, RevitSheet sheet)
 {
     itemType      = type;
     selectedSheet = sheet;
     InitializeComponent();
 }
        private void dataGridSheet_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            try
            {
                DataGridRow row = e.Row;
                if (null != row)
                {
                    RevitSheet oldSheet     = row.Item as RevitSheet;
                    string     propertyName = e.Column.Header.ToString();

                    switch (propertyName)
                    {
                    case "Sheet Number":
                        TextBox textBoxNumber = e.EditingElement as TextBox;
                        if (null != textBoxNumber)
                        {
                            string updatedNumber = textBoxNumber.Text;
                            var    numbers       = from sheet in rvtSheetData.Sheets select sheet.Number;
                            if (numbers.Contains(updatedNumber))
                            {
                                e.Cancel = true;
                                MessageBox.Show(updatedNumber + " already exists in the list of sheets.\nPlease enter a different sheet name", "Existing Sheet Number", MessageBoxButton.OK, MessageBoxImage.Information);
                                return;
                            }
                            else
                            {
                                bool databaseUpdated = SheetDataWriter.ChangeSheetItem(oldSheet.Id.ToString(), "Sheet_Number", textBoxNumber.Text);
                            }
                        }
                        break;

                    case "Sheet Name":
                        TextBox textBoxName = e.EditingElement as TextBox;
                        if (null != textBoxName)
                        {
                            bool databaseUpdated = SheetDataWriter.ChangeSheetItem(oldSheet.Id.ToString(), "Sheet_Name", textBoxName.Text);
                        }
                        break;

                    case "Discipline":
                        ComboBox comboBoxDiscipline = e.EditingElement as ComboBox;
                        if (null != comboBoxDiscipline)
                        {
                            Discipline selectedDiscipline = comboBoxDiscipline.SelectedItem as Discipline;
                            if (null != selectedDiscipline)
                            {
                                bool databaseUpdated = SheetDataWriter.ChangeSheetItem(oldSheet.Id.ToString(), "Sheet_Discipline_Id", selectedDiscipline.Id.ToString());
                            }
                        }
                        break;

                    default:
                        //sheetParameter changed
                        TextBox textBoxParam    = e.EditingElement as TextBox;
                        var     paramValueFound = from paramValue in oldSheet.SheetParameters.Values where paramValue.Parameter.ParameterName == propertyName select paramValue;
                        if (paramValueFound.Count() > 0 && null != textBoxParam)
                        {
                            SheetParameterValue paramValue = paramValueFound.First();
                            paramValue.ParameterValue = textBoxParam.Text;
                            bool databaseUpdated = SheetDataWriter.ChangeSheetParameterValue(paramValue, CommandType.UPDATE);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }