Пример #1
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);
        }
Пример #2
0
        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);
            }
        }
Пример #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);
        }