Is there a way to check if a particular extension is already loaded (in 2023 R2)?
I have tried to do a try: except
catch with Extensions.LoadExtensions
but that isn't working for some reason:
try:
Extensions.LoadExtension(
Id="04a2fd24-d76b-45c8-8553-be985906c975",
Version="232.12",
Format="Scripted"
)
except Exception as exc:
if "Unable to find extension" in str(exc):
raise RuntimeError("CloudConnect not installed.")
# Message when extension is already loaded
if "An error occurred during loading the EDRMedeso CloudConnect extension" in str(exc):
pass
I tried using different exceptions as well
System.Exception
Ansys.Core.Scripting.ScriptingException
This is the error im getting from Workbench
System.Exception: The extension EDRMedeso CloudConnect is already loaded.
at Ansys.ACT.WorkBench.NativeManager.LoadExtension(IExtensionDefinition definition)
--- System.Exception: An error occurred during loading the EDRMedeso CloudConnect extension.
at Ansys.ACT.WorkBench.NativeManager.LoadExtension(IExtensionDefinition definition)
at Ansys.ACT.WorkBench.Commands.LoadExtensionCommand.Execute(IFullContext context)
at Ansys.Core.Commands.Concurrency.CommandWorkUnit.executeInContext(CommandContext subContext, IExecutionEngineCallback tracer)
at Ansys.Core.Commands.Concurrency.BaseWorkUnit.doExecute(IExecutionEngineCallback executionEngine, CommandContext subContext)
at Ansys.Core.Commands.Concurrency.BaseWorkUnit.Execute(IExecutionEngineCallback executionEngine, Boolean dontCatchExceptions)
--- Ansys.Core.Commands.CommandFailedException: An error occurred during loading the EDRMedeso CloudConnect extension.
CommandName: Extensions.LoadExtension(Id="04a2fd24-d76b-45c8-8553-be985906c975", Version="232.12", Format="Scripted")
at Microsoft.Scripting.Runtime.LightExceptions.ThrowException(LightException lightEx)
at Microsoft.Scripting.Runtime.LightExceptions.CheckAndThrow(Object value)
at __call__$684(Closure , PythonFunction , Object , Object , Object )
at Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
at Microsoft.Scripting.Interpreter.DynamicInstruction`7.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at Microsoft.Scripting.Interpreter.DynamicInstruction`6.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
at Microsoft.Scripting.Interpreter.DynamicInstruction`6.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at Microsoft.Scripting.Hosting.CompiledCode.Execute[T](ScriptScope scope)
at Ansys.PythonScriptingEngine.PythonScriptingEngine.ExecuteFile(String fileName)
--- Ansys.Core.Scripting.ScriptingException: CommandFailedException: An error occurred during loading the EDRMedeso CloudConnect extension.
In file "D:\test.wbjn", line 4
Traceback (most recent call last):
File "D:\test.wbjn", line 4, in <module>
File "C:\Program Files\ANSYS Inc\v232\Addins\PythonScriptingEngine\PythonFiles\CommandBindings.py", line 54, in __call__
Exception: An error occurred during loading the EDRMedeso CloudConnect extension.
at Microsoft.Scripting.Runtime.LightExceptions.ThrowException(LightException lightEx)
at Microsoft.Scripting.Runtime.LightExceptions.CheckAndThrow(Object value)
at __call__$684(Closure , PythonFunction , Object , Object , Object )
at Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
at Microsoft.Scripting.Interpreter.DynamicInstruction`7.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at Microsoft.Scripting.Interpreter.DynamicInstruction`6.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
at Microsoft.Scripting.Interpreter.DynamicInstruction`6.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at Microsoft.Scripting.Hosting.CompiledCode.Execute[T](ScriptScope scope)
at Ansys.PythonScriptingEngine.PythonScriptingEngine.ExecuteFile(String fileName)
--- Ansys.Core.Commands.CommandFailedException: CommandFailedException: An error occurred during loading the EDRMedeso CloudConnect extension.
In file "D:\test.wbjn", line 4
CommandName: RunScript(FilePath="D:/test.wbjn")
at Ansys.Core.Commands.CommandAsyncResult.RethrowFailureException(Exception e)
at Ansys.Core.Commands.CommandAsyncResult.Wait(Int32 milliSecondsTimeout, Boolean exitContext)
at Ansys.Core.Commands.Standard.RunScriptCommand.InvokeAndWait(IProtectedContext context, String FilePath)
at Ansys.UI.Standard.RecentScriptFilesGui.Invoke(GuiOperationContext context, GuiOperationArgs args)
at Ansys.UI.GuiOperationContext.Invoke(GuiOperationMetaData operationData)
at Ansys.UI.UIManager.InvokeOperationCore(String pseudoname, OperationDelegate callback, Boolean allowOSMessages, Boolean coreTransaction, Boolean deferredRefreshOnly)