Is there an example of how to use ansysli_util.exe?

I want to get information about Ansys license usage, license availability, and/or the license server. How can I utilize the Ansys license utility (ansysli_util.exe )?


Best Answer

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 133
    100 Comments 25 Likes 5 Answers First Anniversary
    Answer ✓
    import shlex
    import subprocess
    import os
    def getCapabilityAvailability(Capability): 
      if 'ANSYSLIC_DIR' in os.environ:
        #Keep the unclosed quote
        lminstallfolder = '"'+os.environ['ANSYSLIC_DIR']+'\\winx64\\'
        licfile = '"'+os.environ['ANSYSLIC_DIR']+'\\license_files\\ansyslmd.lic"'
        #Keep the unclosed quote
        lminstallfolder = '"C:\\Program Files\\ANSYS Inc\\Shared Files\\Licensing\\winx64\\'
        licfile = '"C:\\Program Files\\ANSYS Inc\\Shared Files\\Licensing\\license_files\\ansyslmd.lic"' 
      #All license features with given capability  
      if os.path.isfile(os.path.normcase(lminstallfolder.replace('"',''))+'ansysli_util.exe'):
        if os.path.isfile(os.path.normcase(licfile.replace('"',''))):
          runstr = lminstallfolder+'ansysli_util.exe"'+' -capcount '+Capability
          args = shlex.split(runstr) 
          p = subprocess.Popen(args,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
          value, error = p.communicate()
          if value_string[0] != 'N' and value_string[0] != 'E':
            availableLicenses = int(value_string)
            if availableLicenses != 0 : 
              availableLicenses = int(value_string)
              #print(str(availableLicenses)+' licenses to run capability '+Capability+' available')
              #print('All of '+capability+' are in use.')
              availableLicenses = 0
            #print('No capability to run '+Capability+' available.')
            availableLicenses = 0
          #print('Can\'t find license file')
          availableLicenses = 0
        #print('Can\'t find license utility')
        availableLicenses = 0
      return availableLicenses