2023 Method
Changes 0
M

Revision.CombineWithNext

Description:
Combines the specified Revision with the next Revision.
Remarks:
All RevisionClouds and tags associated with the specified Revision will be reassigned to the next Revision in the model and the specified Revision will be deleted from the model. The operation can only be performed if both the specified Revision and the next one are unissued.
public static ISet<ElementId> CombineWithNext(
	Document document,
	ElementId revisionId
)
Return Value ISet<ElementId> The ids of all RevisionClouds that were reassigned to the next Revision.
private bool CombineRevision(Document document, Revision revision)
{
    bool combined = false;
    // Can only combine two revisions if neither have been issued
    if (revision.Issued == false)
    {
        ElementId revisionId = revision.Id;
        Revision nextRevsion = GetNextRevision(document, revisionId);
        if (nextRevsion != null && nextRevsion.Issued == false)
        {
            ISet<ElementId> revisionCloudIds = Revision.CombineWithNext(document, revisionId);
            combined = true;
            int movedClouds = revisionCloudIds.Count;
            if (movedClouds > 0)
            {
                RevisionCloud cloud = document.GetElement(revisionCloudIds.ElementAt(0)) as RevisionCloud;
                if (cloud != null)
                {
                    string msg = string.Format("Revision {0} deleted and {1} revision clouds were added to Revsion {2}",
                        revisionId.ToString(), movedClouds, cloud.RevisionId.ToString());
                    TaskDialog.Show("Revision Combined", msg);
                }
            }
        }
    }

    return combined;
}

private Revision GetNextRevision(Document document, ElementId currentRevisionId)
{
    Revision nextRevision = null;
    IList<ElementId> revisionIds = Revision.GetAllRevisionIds(document);
    int currentRevisionIndex = -1;
    for (int n = 0; n < revisionIds.Count; n++)
    {
        if (revisionIds[n] == currentRevisionId)
        {
            currentRevisionIndex = n;
            break;
        }
    }

    // if the current revision id was found and is not the last index
    if (currentRevisionIndex >= 0 && currentRevisionIndex < revisionIds.Count - 1)
    {
        ElementId nextRevisionId = revisionIds[currentRevisionIndex + 1];
        nextRevision = document.GetElement(nextRevisionId) as Revision;
    }

    return nextRevision;
}