Пример #1
0
        private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            try
            {
                if (e.NewItems != null && e.Action == NotifyCollectionChangedAction.Add)
                {
                    foreach (RevitSheet sheet in e.NewItems)
                    {
                        int  index   = rvtSheetData.Sheets.IndexOf(sheet);
                        Guid sheetId = Guid.NewGuid();
                        this.RvtSheetData.Sheets[index].Id = sheetId;
                        bool sheetDBUpdated = SheetDataWriter.ChangeSheetItem(rvtSheetData.Sheets[index], CommandType.INSERT);

                        foreach (SheetParameter sheetParam in rvtSheetData.SheetParameters)
                        {
                            SheetParameterValue paramValue = new SheetParameterValue();
                            paramValue.ParameterValueId = Guid.NewGuid();
                            paramValue.Parameter        = sheetParam;
                            paramValue.SheetId          = sheetId;

                            this.RvtSheetData.Sheets[index].SheetParameters.Add(sheetParam.ParameterId, paramValue);
                        }
                        bool sheetParamDBUpdated = SheetDataWriter.InsertMultipleParameterValue(RvtSheetData.Sheets[index].SheetParameters.Values.ToList());

                        foreach (RevitRevision revision in rvtSheetData.Revisions)
                        {
                            RevisionOnSheet ros = new RevisionOnSheet(Guid.NewGuid(), sheetId, revision, false);
                            this.RvtSheetData.Sheets[index].SheetRevisions.Add(revision.Id, ros);
                        }
                        bool rosDBUpdated = SheetDataWriter.InsertMultipleRevisionOnSheet(RvtSheetData.Sheets[index].SheetRevisions.Values.ToList());
                    }
                }
                if (e.OldItems != null && e.Action == NotifyCollectionChangedAction.Remove)
                {
                    foreach (RevitSheet sheet in e.OldItems)
                    {
                        bool sheetDBUpdated      = SheetDataWriter.ChangeSheetItem(sheet, CommandType.DELETE);
                        bool sheetParamDBUpdated = SheetDataWriter.DeleteSheetParameterValue(sheet.Id.ToString());
                        bool rosDBUpdated        = SheetDataWriter.DeleteRevisionOnSheet("RevisionsOnSheet_Sheet_Id", sheet.Id.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
Пример #2
0
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool          added      = false;
                List <string> paramNames = GetExistingParameters();

                for (int i = 1; i < 21; i++)
                {
                    string paramName = "New Parameter " + i;
                    if (!paramNames.Contains(paramName))
                    {
                        SheetParameter sheetParam = new SheetParameter(Guid.NewGuid(), paramName, "TEXT");
                        this.RvtSheetData.SheetParameters.Add(sheetParam);
                        bool databaseUpdated = SheetDataWriter.ChangeSheetParameter(sheetParam, CommandType.INSERT);

                        //update RevitSheet

                        List <SheetParameterValue> paramValues = new List <SheetParameterValue>();
                        for (int sheetIndex = 0; sheetIndex < rvtSheetData.Sheets.Count; sheetIndex++)
                        {
                            SheetParameterValue sheetParamValue = new SheetParameterValue(Guid.NewGuid(), rvtSheetData.Sheets[sheetIndex].Id, sheetParam, "");
                            this.RvtSheetData.Sheets[sheetIndex].SheetParameters.Add(sheetParam.ParameterId, sheetParamValue);
                            paramValues.Add(sheetParamValue);
                        }

                        databaseUpdated = SheetDataWriter.InsertMultipleParameterValue(paramValues);

                        added = true;
                        break;
                    }
                }
                if (!added)
                {
                    MessageBox.Show("Please rename existing parameters before you add more parameters.", "Rename Parameter", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
Пример #3
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);
        }
Пример #4
0
        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);
        }