Is there any way to block a particular license and release when needed through scripting?
I have a mixed wizard but there are limited licenses. I would like to block a particular license and release it before launching an application.
Is there any way to do that via script or subprocess using license client executables?
Answers
-
@AKD-Scripting-Team might have someone who knows, Rajesh.
0 -
Here is a method to check for available licenses. I have used it to wait for a license to become available. I am not aware of a direct way to hold a license. But a workaround could be to open an instance of a product that pulls the license, and close it when needed.
import System import clr clr.AddReference("Ans.Core.Components") import Ansys.Core.Components clr.AddReference("Ans.UI.Toolkit") clr.AddReference("Ans.UI.Toolkit.Base") import Ansys.UI.Toolkit clr.AddReference("Ans.Utilities") import Ansys.Utilities def licenseCheck(args): ExtAPI.Log.WriteMessage('Custom License Toolbar Button Clicked') #this snippet shows license validation when inside the running product wbCapability = Ansys.Core.Components.Validation.Capability.ANSYSLI_CAP_ANS_ACT isLicensed = Ansys.Core.Components.Validation.Validator.Check(wbCapability) mssg = "invalid" if isLicensed: mssg = "valid" Ansys.UI.Toolkit.MessageBox.Show(System.String.Format("Validator: Capabiliy {0} is {1}!", str(wbCapability), mssg)) #this snippet shows license validation when outside the running product installDir = ExtAPI.ExtensionManager.CurrentExtension.InstallDir licFilePath = System.IO.Path.Combine(installDir, "licenseoutput.xml") if System.IO.File.Exists(licFilePath): System.IO.File.Delete(licFilePath) awpRoot = Ansys.Utilities.ApplicationConfiguration.DefaultConfiguration.AwpRootEnvironmentVariableValue ansysFolder = System.IO.Path.Combine(awpRoot, "..") sharedFolder = System.IO.Path.Combine(ansysFolder, "Shared Files") licFolder = System.IO.Path.Combine(sharedFolder, "Licensing") licPlatformFolder = System.IO.Path.Combine(licFolder, "winx64") licutilPath = System.IO.Path.Combine(licPlatformFolder, "ansysli_util.exe") ExtAPI.ProcessUtils.Start(licutilPath, "-cap", str(wbCapability), "-getcapdef", licFilePath) mssg = "invalid" if System.IO.File.Exists(licFilePath): doc = System.Xml.XmlDocument() doc.Load(licFilePath) node = doc.SelectSingleNode("FEATURES") if node.ChildNodes.Count > 0: mssg = "valid" System.IO.File.Delete(licFilePath) Ansys.UI.Toolkit.MessageBox.Show(System.String.Format("LIC UTIL: Capabiliy {0} is {1}!", str(wbCapability), mssg))
Whitespace was not properly maintained when I copy/pasted (from Notepad++) @James Derrick please investigate.
EDIT: I re-copy/pasted from VSCode per @James Derrick 's advice and it is now correct.
0 -
Here's the original file.
0 -
Regarding the code formatting, this seems to be a weakness of notepad and notepad++ as I do not see the same error with code copied from PyCharm or VS Code. I am not sure why exactly it is happening, although notepad++ is known for having issues when exporting code to other applications:
It looks like notepad++ would need some configuration before it will work as you want it to.
1