Ejemplo n.º 1
0
def ChkErr(ErrorCode):
    ErrorOccured = (ErrorCode != 0)
    if ErrorOccured:
        ErrorString = ctypes.create_string_buffer(St7API.kMaxStrLen)

        # Attempt to get API error string
        iErr = St7API.St7GetAPIErrorString(ErrorCode, ErrorString,
                                           St7API.kMaxStrLen)

        # If that failed, attempt to retrive a solver error string
        if iErr:
            iErr = St7API.St7GetSolverErrorString(ErrorCode, ErrorString,
                                                  St7API.kMaxStrLen)

        if not iErr:
            raise Exception('%s (%d)' % (ErrorString.value, ErrorCode))
        else:
            raise Exception('An unknown error occured (%d)' % ErrorCode)

    return ErrorOccured
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-

import os
import St7API
import St7Toolbox_JA as St7Tbx

import tkinter as tk
from tkinter import filedialog

St7API.St7Init()

###################
# SET YOUR PARAMETERS HERE

# Modify to your own model location
# If you are using relative path, set them with respect to your script
# Example of full path If you use the fullpath, you can add r in front of it
# it sets the string as a raw string, \0 will be considered as a string and
# not as a special character (for example as in url %20 means \ )
# modelname = r'O:/PSM3700/Eng/Tools/Model.st7'
root = tk.Tk()
root.withdraw()

# Make it almost invisible - no decorations, 0 size, top left corner.
root.overrideredirect(True)
root.geometry('0x0+0+0')

# Show window again and lift it to top so it can get focus,
# otherwise dialogs will end up behind the terminal.
root.deiconify()
root.lift()
Ejemplo n.º 3
0
        # If that failed, attempt to retrive a solver error string
        if iErr:
            iErr = St7API.St7GetSolverErrorString(ErrorCode, ErrorString,
                                                  St7API.kMaxStrLen)

        if not iErr:
            raise Exception('%s (%d)' % (ErrorString.value, ErrorCode))
        else:
            raise Exception('An unknown error occured (%d)' % ErrorCode)

    return ErrorOccured


# Main program code. Use try...finally syntax to ensure the API is released even in the case of an expection.
try:
    St7API.St7Init()

    # 'encode' function return bytes from string in Python 3.
    fileToOpen = inFunc('Enter file path: ').encode()
    ChkErr(St7API.St7OpenFile(1, fileToOpen, r'c:\temp'.encode()))

    # Display the model title and author
    modTitle, modAuth = ctypes.create_string_buffer(
        St7API.kMaxStrLen), ctypes.create_string_buffer(St7API.kMaxStrLen)
    ChkErr(
        St7API.St7GetTitle(1, St7API.TITLEModel, modTitle, St7API.kMaxStrLen))
    ChkErr(
        St7API.St7GetTitle(1, St7API.TITLEAuthor, modAuth, St7API.kMaxStrLen))
    print('Title:  ' + modTitle.value.decode())
    print('Author: ' + modAuth.value.decode())