Beispiel #1
0
def _runscript():

    try:
        # loading config
        iniFile = Path.ChangeExtension(sys.argv[0],".ini")
        configLines = File.ReadAllLines(iniFile)
        config = {}
        for line in configLines:
            kv = line.split("=")
            config[kv[0].upper()] = kv[1]

            print "construct"
            app = Application()
            print "set connection"
            app.SetConnection("Host=" + config["HOST"]+";Database="+config["DATABASE"]+";port="+config["PORT"]+";dbflavour="+ config["DBFLAVOUR"]);
            print "login"
            app.Login(config["USER"],config["PW"],config["WORKSPACE"]);
            print "startup"
            app.StartUp();
            print "ready"

            scriptPath = sys.argv[1]
            print "scriptPath=" + scriptPath

            scr = app.Modules.Get("Script Manager")
            script = scr.ScriptList.Fetch(scriptPath)
            print "Setting up parameters ... "
            dictParam = Dictionary[String, Object]()
            for i in range(2,len(sys.argv)):
                kv = sys.argv[i].split('=')
                k = kv[0].strip()
                v = kv[1].strip()
                if v.startswith('"') and v.endswith('"'): v = v[1:-1]
                print k,"=",v
                dictParam.Add(k,v)
                print "Running " + scr.ScriptList.GetEntityDescriptor(script)
                output =  clr.Reference[String]()
                # avoid conflicting overloaded versions of ExecuteScript by supplying arguments by name
                result = scr.ExecuteScript(script=script, arguments=dictParam, tag=None, output=output)
                print "result=",result
                print "output:"
                print output.Value

                print "done"
    except Exception as e:
        print "ERROR"
        print str(e)
# create dialog
wd = ZenWindow()
wd.Initialize('Convert CZMODEL to old format - Version: ' + str(scriptversion))
wd.AddDropDown('czmf', 'Select individual CZMODEL to be converted', czmodelfiles_short, 0)
result = wd.Show()

# check, if Cancel button was clicked
if result.HasCanceled:
    sys.exit('Macro aborted with Cancel!')

# get the full path of the selected czmodel file
czmodelfile = Path.Combine(basedir, result.GetValue('czmf'))
print('CZMODEL selected: ', czmodelfile)

# Unzip
tempdir = Path.ChangeExtension(czmodelfile, None) + '_v1'
with zipfile.ZipFile(czmodelfile, 'r') as zip_ref:
    zip_ref.extractall(tempdir)
print('Finished unzipping: ', czmodelfile)

# get the xmlfile inside the newly created directory and load it
modelxml = Directory.GetFiles(tempdir, '*.xml')[0]
print('Load XML File: ', modelxml)
xmldoc = System.Xml.XmlDocument()
xmldoc.Load(modelxml)

# check if conversion is possible for the feature extractor
feature_extractor = get_feature_extractor(modelxml)
if feature_extractor == 'DeepNeuralNetwork':
    # stop the script execution completely
    sys.exit('Conversion to older czmodel not possible for trained DNNs.')