Documentation Home Page HYPERSIM Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

Here’s a basic example that shows how to start HYPERSIM®, load a network and interact with HYPERSIM® using the API.

C:\OPAL-RT\HYPERSIM\hypersim-version\Windows\HyApi\C\py\test_Windows_Api.py

Basic example
import sys
sys.path.append(r'C:\OPAL-RT\HYPERSIM\hypersim-version\Windows\HyApi\C\py')

import HyWorksApi
import time

HyWorksApi.startAndConnectHypersim()
designPath = r'C:\demo\HVAC_38BUS_735KV.ecf'
HyWorksApi.openDesign(designPath)

HyWorksApi.setPreference('simulation.calculationStep', '50e-6')
calcStep = HyWorksApi.getPreference('simulation.calculationStep')

print('calcStep = ' + calcStep)
print('code directory : ' + HyWorksApi.getPreference('simulation.codeDirectory'))
print('mode : ' + HyWorksApi.getPreference('simulation.architecture'))

HyWorksApi.mapTask()
HyWorksApi.genCode()
HyWorksApi.startLoadFlow()
HyWorksApi.startSim()


time.sleep(10)
print('startSim done')

volt = HyWorksApi.getComponentParameter('Ge7', 'baseVolt')
print('baseVolt = ' + volt[0] + volt[1])

HyWorksApi.setComponentParameter('Ge7', 'baseVolt', str(float(volt[0]) + 2.75))


volt2 = HyWorksApi.getComponentParameter('Ge7', 'baseVolt')

print('baseVolt = ' + volt2[0] + volt2[1])

if( abs( float(volt2[0]) - float(volt[0]) - 2.75) > 0.0001 ):
	print('SET_COMP ERROR')
else:
	print('SET_COMP SUCCESS')

time.sleep(10)
HyWorksApi.stopSim()
HyWorksApi.closeDesign(designPath)
HyWorksApi.closeHyperWorks() 


Another example using the API to control ScopeView can be found here:

C:\OPAL-RT\HYPERSIM\hypersim-version\Windows\ScopeView\lib\ScopeViewApi\example.py

This example starts ScopeView, loads a template and data source, starts an acquisition, saves graphs as a pdf file and saves data to a text file. The output from ScopeView can be read from the stdout.txt and stderr.txt files generated in the same directory as the example.

To run this script, you must have an "exampleFiles" folder that contains the files template.xml, datasource.cfg and datasource.dat


ScopeView example
import os
import sys
import time

#Modify this line to set-up your HYPERSIM version folder
#Example : hypersim_dir = "C:\\OPAL-RT\\HYPERSIM\\hypersim_2020.3.0.o97"
hypersim_dir =  " "

python_path = os.path.join(hypersim_dir, 'Windows', 'HyApi', 'C', 'py')
sys.path.insert(1, python_path)
import HyWorksApi
import ScopeViewApi

currentPath = os.path.abspath(os.path.dirname( file ))
exportPath = os.path.join(currentPath, 'ExportData')

scopeViewProcess = ScopeViewApi.openScopeView()
ScopeViewApi.loadTemplate(os.path.join(currentPath, 'exampleFiles', 'template.xml'))
ScopeViewApi.replaceDataSource("COM1", "{file=" + os.path.abspath(os.path.join(currentPath, 'exampleFiles', 'datasource.cfg')) + "}")
ScopeViewApi.startAcquisition()

ScopeViewApi.exportToPDF(os.path.join(currentPath, 'exportPDF.pdf'))
ScopeViewApi.exportToFile(os.path.join(currentPath, 'exportTXT.txt'))

ScopeViewApi.close()



  • No labels