private void doTheRenumberingOrLettering(Document doc, IList <GridInfo> targetListOfGrids, IList <ElementId> allMultiGridsIDs, bool isNumber) { Grid prevGrid = null; bool prevGridIsSub = false; int counter = 0; int subCounter = 1; char letter = 'A'; char subLetter = 'a'; WholeName = "A"; double currentGridLength = 0; double prevGridLength = 0; IList <ElementId> allMultiGridSubGridsIDs = new List <ElementId>(); foreach (ElementId currentMultiGridId in allMultiGridsIDs) { allMultiGridSubGridsIDs = allMultiGridSubGridsIDs.Union((uidoc.Document.GetElement(currentMultiGridId) as MultiSegmentGrid).GetGridIds()).ToList(); } foreach (GridInfo currentGridInfo in targetListOfGrids) { Grid currentGrid = null; currentGrid = uidoc.Document.GetElement(new ElementId(currentGridInfo.Id)) as Grid; if (allMultiGridSubGridsIDs.Contains(new ElementId(currentGridInfo.Id))) { MultiSegmentGrid currentMultiSegGrid = doc.GetElement(MultiSegmentGrid.GetMultiSegementGridId(currentGrid)) as MultiSegmentGrid; currentGridLength = getMultiGridLengthSameOrientationMainGrid(doc, currentMultiSegGrid, currentGrid); } else { currentGridLength = getTheoricalLengthOfTheGrid(currentGrid); } if (prevGrid != null) { if (allMultiGridsIDs.Contains(MultiSegmentGrid.GetMultiSegementGridId(prevGrid))) { MultiSegmentGrid PrevMultiSegGrid = doc.GetElement(MultiSegmentGrid.GetMultiSegementGridId(prevGrid)) as MultiSegmentGrid; prevGridLength = getMultiGridLengthSameOrientationMainGrid(doc, PrevMultiSegGrid, prevGrid); } else { prevGridLength = getTheoricalLengthOfTheGrid(prevGrid); } GridInfo prevGridInfo = targetListOfGrids.Where(g => g.Id == prevGrid.Id.IntegerValue).FirstOrDefault(); if (canUseSubNumering) { if (CompareGridLength(prevGridLength, currentGridLength) == GridLength.Equal) { if (prevGridIsSub == false) { if (isNumber) { currentGridInfo.newName = increaseWholeNumber(doc, currentGridInfo, ref counter, ref subCounter, ref prevGridIsSub); } else { currentGridInfo.newName = increaseWholeLetter(doc, currentGridInfo, ref letter, ref subLetter, ref prevGridIsSub); } } if (prevGridIsSub == true) { if (isNumber) { currentGridInfo.newName = increaseSubNumber(doc, currentGridInfo, ref prevGridInfo, ref subCounter, ref prevGridIsSub); } else { currentGridInfo.newName = increaseSubLetter(doc, currentGridInfo, ref prevGridInfo, ref subLetter, ref prevGridIsSub); } } } if (CompareGridLength(prevGridLength, currentGridLength) == GridLength.Bigger) { if (isNumber) { currentGridInfo.newName = increaseSubNumber(doc, currentGridInfo, ref prevGridInfo, ref subCounter, ref prevGridIsSub); } else { currentGridInfo.newName = increaseSubLetter(doc, currentGridInfo, ref prevGridInfo, ref subLetter, ref prevGridIsSub); } } if (CompareGridLength(prevGridLength, currentGridLength) == GridLength.Smaller) { if (isNumber) { currentGridInfo.newName = increaseWholeNumber(doc, currentGridInfo, ref counter, ref subCounter, ref prevGridIsSub); } else { currentGridInfo.newName = increaseWholeLetter(doc, currentGridInfo, ref letter, ref subLetter, ref prevGridIsSub); } } } else { if (isNumber) { currentGridInfo.newName = increaseWholeNumber(doc, currentGridInfo, ref counter, ref subCounter, ref prevGridIsSub); } else { currentGridInfo.newName = increaseWholeLetter(doc, currentGridInfo, ref letter, ref subLetter, ref prevGridIsSub); } } } else { if (isNumber) { currentGridInfo.newName = increaseWholeNumber(doc, currentGridInfo, ref counter, ref subCounter, ref prevGridIsSub); } else { currentGridInfo.newName = increaseWholeLetter(doc, currentGridInfo, ref letter, ref subLetter, ref prevGridIsSub); } } prevGrid = currentGrid; } }