Check License Status

Run the script inside ANSYS Mechanical to view license status.

Transparent

import os
import subprocess
import wbjn
import toolbar
cmd = 'returnValue(GetUserFilesDirectory())'
path = wbjn.ExecuteCommand(ExtAPI,cmd) + '\\licCheck.txt'
prefix = str("AWP_ROOT")
ansysdirs = []
for key, value in os.environ.items():
    if key[:len(prefix)] == prefix:
        ansysdirs.append(value)
ansysdir = ansysdirs[-1]
# Get specified license server
proc = subprocess.Popen([ansysdir + r"\licensingclient\winx64\ansysli_util.exe", "-getlicpath"], stdout=subprocess.PIPE)
output = proc.stdout
myout=[]
for line in output: myout.append(line.decode('UTF-8'))
port = myout[0].split("@")[0]
licserver = myout[0].split("@")[1].split(";")[0]
# LICENSE STATUS
proc2 = subprocess.Popen([ansysdir + r"\licensingclient\winx64\lmutil.exe", "lmstat", "-c", port + "@" + licserver, "-f"], stdout=subprocess.PIPE)
output2 = proc2.stdout
outputFile = list()
for line in output2: 
    print line
    outputFile.append(line)
f = open(path, "w")
for line in outputFile: f.write(line)
f.close()
toolbar.ToggleWorksheetVisibility(ExtAPI)
WorksheetPane = ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.Worksheet)
WorksheetPane.Caption = "License Status"
WorksheetPane.CloseButtonVisible = True
control = WorksheetPane.ControlUnknown
control.Navigate(path)