I’m working with autodesk programs (Robot structural Analysis[RSA], Dynamo).
For the past i used RSA 2022 with Dynamo 2.11.0.
At the moment we are upgrading to RSA 2025 which is using Dynamo 3.0.4.
In the image below a simple preview of our workflow.
enter image description here
So every single excel file should be closed by the script.
Which worked pretty good in RSA2022 with the following script:
import sys
import clr
import System
clr.AddReference('Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
from Microsoft.Office.Interop import Excel
from System.Runtime.InteropServices import Marshal
def excel_close(lst_namefile):
xlApp = Excel.Application(Marshal.GetActiveObject("Excel.Application"))
print(xlApp)
allWorkbooks = Excel.Workbooks(xlApp.get_Workbooks())
print([x for x in allWorkbooks])
lst_WkbsName = [Excel.Workbook(x).get_Name() for x in allWorkbooks]
for namefile in lst_namefile:
if namefile in lst_WkbsName:
Tesluiten = Excel.Workbook(allWorkbooks.get_Item(namefile))
Tesluiten.Close()
xlApp.Quit()
toList = lambda x : x if isinstance(x, list) else [x]
OUT = excel_close(toList(IN[0]))
Now with the upgrade to RSA2025 i still need to use this script, but i get the following error.
Message
FileNotFoundException : Unable to find assembly ‘Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’. at Python.Runtime.CLRModule.AddReference(String name)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr) [’ File “
I already did some research and questioning, SEE other forum
But it seems related to the Net 8.
My question is: is there an other way to close the excel file with a python script?
Many thanks in advance
Gr edward
Edward is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.