Is there any way to block a particular license and release when needed through scripting?

Rajesh Meena
Rajesh Meena Moderator, Employee Posts: 42
10 Comments 5 Answers First Anniversary Solution Developer Community of Practice Member

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?



  • Chris Harrold
    Chris Harrold Member, Administrator, Employee Posts: 90
    10 Comments First Anniversary First Answer Ansys Employee

    @AKD-Scripting-Team might have someone who knows, Rajesh.

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 123
    25 Likes 5 Answers 10 Comments First Anniversary
    edited August 14

    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
    import Ansys.Core.Components
    import Ansys.UI.Toolkit
    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):
        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()
            node = doc.SelectSingleNode("FEATURES")
            if node.ChildNodes.Count > 0:
                mssg = "valid"
        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.

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 123
    25 Likes 5 Answers 10 Comments First Anniversary

    Here's the original file.

  • James Derrick
    James Derrick Administrator, Employee Posts: 229
    Ancient Membership 100 Comments 100 Likes 25 Answers

    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.