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

Landon Mitchell Kanner
Landon Mitchell Kanner Member, Employee Posts: 291
25 Answers 100 Comments 25 Likes First Anniversary
✭✭✭✭

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 )?

Tagged:

Best Answer

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 291
    25 Answers 100 Comments 25 Likes 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"'
      else:
        #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()
    
          value_string=value.decode("utf-8")
    
          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')
            else:
              #print('All of '+capability+' are in use.')
              availableLicenses = 0
          else:
            #print('No capability to run '+Capability+' available.')
            availableLicenses = 0
    
        else: 
          #print('Can\'t find license file')
          availableLicenses = 0
      else: 
        #print('Can\'t find license utility')
        availableLicenses = 0
    
      return availableLicenses