Working on testing our pyRevit scripts for Revit 2025 which updated to .NET 8 and I'm getting an error in a script that works in previous versions. Also worth nothing that I'm relatively new to coding.
Here is the code:
import Microsoft.Office.Interop.Word as Word
from pyrevit import DB, revit, script, forms, coreutils
# Word Test
missing = Missing
word_application = Word.ApplicationClass()
word_application.Visible = False
# Forms
wordDoc = forms.pick_file(file_ext="docx",init_dir="J:",
multi_file = False, title = "Pick a .docx word document.")
document = word_application.Documents.Open(wordDoc, missing, True)
This is the error.
IronPython Traceback:
Traceback (most recent call last):
File "L:\Revit\Development\PyRevit\DevTool\DevTool.extension\DevTools.tab\Development.Panel\SheetSpec.pushbutton\SheetSpec_script.py", line 69, in <module>
AttributeError: '__ComObject' object has no attribute 'Open'
I've tried printing the methods for Documents, and I'm getting a list that does not match the documentation. I feel like there is something I fundamentally do not understand about what changed with the .NET 8 update.
print(dir(word_application.Documents))
<System.__ComObject object at 0x00000000000009F3 [System.__ComObject]>
['Equals', 'GetHashCode', 'GetLifetimeService', 'GetType', 'InitializeLifetimeService', 'MemberwiseClone', 'ReferenceEquals', 'ToString', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
This is the documentation, .office.interop.word.documents?view=word-pia
When I run the same script in Revit 2023 and Revit 2024 it prints this:
['Add', 'AddBlogDocument', 'AddOld', 'Application', 'CanCheckOut', 'CheckOut', 'Close', 'Count', 'CreateObjRef', 'Creator', 'Equals', 'GetHashCode', 'GetLifetimeService', 'GetType', 'InitializeLifetimeService', 'Item', 'MemberwiseClone', 'Open', 'Open2000', 'Open2002', 'OpenNoRepairDialog', 'OpenOld', 'Parent', 'ReferenceEquals', 'Save', 'ToString', '_NewEnum', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']