Bonjour à tous,
Ce script ne fonctionne plus avec REVIT 2022.
Avez vous une idée ?
Daniel
import clr
import time
clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
from Microsoft.Office.Interop import Excel
#time.sleep(3)
dirfichier = "D:\_F3DF\01_Formations\1-07_FORMATION-Dynamo\DBC_Ex00\DBC_Ex00\DBC_Ex00-2_Lance-Macro-VBA.xlsm"
#time.sleep(5)
dirmacro = dirfichier + "!Dynamo"
#time.sleep(5)
ex = Excel.ApplicationClass()
ex.Visible = True
ex.DisplayAlerts = False
wb = ex.Workbooks.Open(dirfichier)
ws = wb.Worksheets[2]
#time.sleep(3)
ex.Application.Run (dirmacro)
wb.SaveAs(dirfichier)
ex.Application.Quit()
OUT = "Dynamo Ok !"
Bonjour Daniel,
J’ai eu beaucoup de problèmes sur Interop.Excel par rapport à Office 365 qui avec ces mise à jour intempestives foirait la clé de registre.
Mes problèmes étaient essentiellement en C# avec Visual Studio donc je sais pas si le problème vient exactement de là pour Dynamo et Python mais la solution pour moi a été de désinstaller tout Office pour le réinstaller 
Bonne journée
Bonjour @Dolives
Quel moteur Python (CPython3 ou IronPython2) et quelle version d’Excel utilises-tu?
Peux-tu également nous montrer le message d’erreur ?
Bonjour Cyril,
Je suis en : IrobPython 2 / Office 365 / Windows 11
Et le texte du message d’erreur:
Avertissement:IronPythonEvaluator.EvaluateIronPythonScript l’opération a échoué.
Traceback (most recent call last):
File « », line 16, in
EnvironmentError: System.Runtime.InteropServices.COMException (0x800A03EC): Désolé… Nous ne trouvons pas C:\TPS\Classeur1.xlsm. Peut-être l’avez-vous déplacé, renommé ou supprimé ?
à Microsoft.Scripting.ComInterop.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
à CallSite.Target(Closure , CallSite , Object , Object )
à System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
à Microsoft.Scripting.Interpreter.DynamicInstruction3.Run(InterpretedFrame frame) à Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) à Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3) à System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2) à Microsoft.Scripting.Interpreter.DynamicInstruction
4.Run(InterpretedFrame frame)
à Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
à Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
à IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
à Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
à DSIronPython.IronPythonEvaluator.EvaluateIronPythonScript(String code, IList bindingNames, IList bindingValues)
visiblement un probleme d’acces, le chemin est correct ? C:\TPS\Classeur1.xlsm
essai ce code (avec un raw string)
import clr
import time
clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
from Microsoft.Office.Interop import Excel
from System.Runtime.InteropServices import Marshal
#time.sleep(3)
dirfichier = r'C:\TPS\Classeur1.xlsm'
ex = Excel.ApplicationClass()
ex.Visible = True
ex.DisplayAlerts = False
wb = ex.Workbooks.Open(dirfichier)
ws = wb.Worksheets[1]
#time.sleep(3)
# run macro named 'Dynamo'
ex.Application.Run("Dynamo")
wb.SaveAs(dirfichier)
ex.Workbooks.Close()
ex.Quit()
if wb is not None:
Marshal.ReleaseComObject(wb)
if ex is not None:
Marshal.ReleaseComObject(ex)
wb = None
ex = None
OUT = "Dynamo Ok !"
1 « J'aime »
Bonjour, merci pour ton aide cela fonctionne correctement après avoir bien activé les macro sous excel et bien utilisé un fichier xlsm, avec ton script python
Daniel
1 « J'aime »