Latest revision number on sheet

Hello :slight_smile:

Is there a way to get the latest revision of the drawing?

For example, if I have a list of revisions like [P01, P02, T01, C01, C02], how can I get the C02 string value?

At the moment, I am unable to see a solution :cry: I really want to avoid iterating over each drawing and getting the list of revision sequences, and then getting the sequential number with the prefix.

1 Like

@Gian_Claudio ,

i think you have index by -1.
so you have the last item

lis = ["A1","A2","A3","A4","A5"]
print(lis)

lastItem = lis[-1]

print(lastItem)

grafik

hello :slight_smile:

sorry I have not given more context

sheetInDoc = query.get_sheets()
rev=[]
for i in sheetInDoc:
    if query.get_current_sheet_revision(i) != None:
        latest =[query.get_current_sheet_revision(i)][0]
        rev.append([i.SheetNumber, latest,\
            latest.RevisionDate,\
            latest.Description,\
            latest.RevisionNumberingSequenceId             
                
                ])
print (rev)

from here how can I get the latest revision?

1 Like

@Gian_Claudio

query is from which module ?

the model is from pyrevit:

and I have imported like that :slight_smile:

from pyrevit.revit import query

1 Like

@Gian_Claudio

what do want to access ?

@Gian_Claudio

accessing by Number ?

you want the index!

yes, I want to get the index… I am not sure how to get this it looks like that I need to iterate over and get the index of each numbering type

@Gian_Claudio

tricky, i just can access the template but not the index itself

2024-06-05_17h24_24
2024-06-05_17h24_33

sheetInDoc = query.get_sheets()

rev = []
for i in sheetInDoc:
    if query.get_current_sheet_revision(i) != None:
        latest = [query.get_current_sheet_revision(i)][0]
        # rev.append([i.SheetNumber, latest,latest.RevisionDate,latest.Description,latest.RevisionNumberingSequenceId])
        rev.append(latest.RevisionNumberingSequenceId)

print(doc.GetElement(rev[0]).Name)

accessing the sequense

Assuming that the “latest” revision means the more recent one, you can just check wich element of the list has the max value at index 2:

latest_rev = max(rev, key=lambda x: x[2])

The key argument is used to extract the values to compare, and it defaults to identity (= the value itself);
The lambda lets you create an anonymous function on a single line.

Taking a step further, I would take advantage of generators and functional programming to skip the list

sheets_and_revs = (
    (s.SheetNumber, query.get_current_sheet_revision(s)) 
    for s in query.get_sheets()
)
sheets_with_revs = (sr for sr in sheets_and_revs if sr is not None)
latest = max(sheets_with_revs, key=lambda x: x[1].RevisionDate)
sheet_number, revision = latest

I don’t know if this is what you mean, but I hope it can help.

def GetRevisionSequences(sheets):
    revisionSequences = []
    for sheet in sheets:
        sub_lst = []
        revision_Ids = sheet.GetAllRevisionIds()
        # print (revisions)
        for Id in revision_Ids:
            sub_lst.append(doc.GetElement(Id).SequenceNumber)
        revisionSequences.append(sub_lst)
    return revisionSequences

def GetAllRevisionsOnSheet(sheets):
    revisions = []
    for sheet in sheets:
        sub_lst = []
        revision_Ids = sheet.GetAllRevisionIds()
        for Id in revision_Ids:
            sub_lst.append(doc.GetElement(Id))
        revisions.append(sub_lst)
    return revisions

selectedSheets = forms.select_sheets()
allRevisions = GetAllRevisionsOnSheet(selectedSheets)
revisionSequences = GetRevisionSequences(selectedSheets)
latestIndex = [len(revList)-1 for revList in revisionSequences]
latestRevision = []
for sublst,ind in zip(allRevisions,latestIndex):
    latestRevision.append(sublst[ind])


print ("All revision sequences on sheets: ")
print (revisionSequences)
print ("---------------------------------------------------------------------")
print ("The latest index: ")
print (latestIndex)
print ("---------------------------------------------------------------------")
print ("The latest revision: ")
print (latestRevision)

1 Like