1

I am attempting to modify the extremely helpful open keynotes button script to create a 'reload keynotes' button.

Currently i am trying to use the Reload Method of the KeyBasedTreeEntryTable class.

kt = DB.KeynoteTable.GetKeynoteTable(revit.doc)
kt_ref = kt.GetExternalFileReference()
path = DB.ModelPathUtils.ConvertModelPathToUserVisiblePath(
    kt_ref.GetAbsolutePath()
    )

reloader = DB.KeyBasedTreeEntryTable.Reload()



if not path:
    forms.alert('No keynote file is assigned.')
else:
    reloader 

This is the error message that i am receiving.

TypeError: Reload() takes exactly 2 arguments (0 given)

Error Message Image

I am stuck here and appreciate any help.

PRMoureu
  • 12,817
  • 6
  • 38
  • 48
  • I am not sure what arguments the Reload method is looking for... – Andrew Beres Apr 06 '18 at 21:41
  • You will find some hints about the parameter [in this doc](http://www.revitapidocs.com/2015/a91169d7-4f71-c027-3a24-1d90473e7071.htm#parameters), but `Reload` is not a static method, you cannot call it directly from the class. the first parameter (implicit) should refer to the instance of the class `KeyBasedTreeEntryTable`. – PRMoureu Apr 08 '18 at 08:42

1 Answers1

2

You can use Revit API to reload the keynotes, the method KeyBasedTreeEntryTable.Reload just needs a parameter to store warnings thrown during operation, this parameter can be None to make it easy.

Also KeyBasedTreeEntryTable should be an instance, the reload method is not static.

The cool thing is that you don't need to find any KeyBasedTreeEntryTable instance, because the KeynoteTable class inherits from KeyBasedTreeEntryTable, so the Reload method is already available with the kt instance in your script.

(This operation needs a transaction context too, like in the following examples)

Simple way

kt = DB.KeynoteTable.GetKeynoteTable(revit.doc)

t = DB.Transaction(revit.doc)
t.Start('Keynote Reload')
try:
    result = kt.Reload(None)
    t.Commit()

except:
    t.RollBack()

forms.alert('Keynote Reloading : {}'.format(result))
# result can be 'Success', 'ResourceAlreadyCurrent' or 'Failure'

Complete way

kt = DB.KeynoteTable.GetKeynoteTable(revit.doc)

# create results object
res = DB.KeyBasedTreeEntriesLoadResults() 

t = DB.Transaction(revit.doc)
t.Start('Keynote Reload')
try:
    result = kt.Reload(res) # pass results object
    t.Commit()

except:
    t.RollBack()

# read results
failures = res.GetFailureMessages()
syntax_err =  res.GetFileSyntaxErrors()
entries_err = res.GetKeyBasedTreeEntryErrors()
# res.GetFileReadErrors() returns files errors, should be already in failures Messages

warnings = ''
warnings += '\n'.join([message.GetDescriptionText() for message in failures])

if syntax_err:
    warnings += '\n\nSyntax errors in the files :\n'
    warnings += '\n'.join(syntax_err)

if entries_err:
    warnings += '\nEntries with error :\n'
    warnings += '\n'.join([key.GetEntry().Key for key in entries_err])

forms.alert('Keynote Reloading : {}\n{}'.format(result, warnings))
PRMoureu
  • 12,817
  • 6
  • 38
  • 48