To set up your HyperX scripting environment, you can either use the recommended hyperx Python Package Wrapper, or you can point your Script directly to the C# assemblies using Python or C#.
Tip
Your installation directory corresponds to the parent folder of your HyperX executable. For many people, this is something like: "C:\Users\<USER.NAME>\AppData\Local\Programs\HyperX"
To use the hyperx Python Package wrapper, install the package, import the module, and write your Script.
Using the provided Open utility method will take care of referencing HyperX.Scripting.dll, initializing the HyperX environment, and instantiating the Application object. It will return a wrapped Application object.
import hyperx as hx databasePath = r”my\Database\Path.hdb3” application = hx.Open(databasePath)
The main class through which users interact with the HyperX Scripting API is the Application. When using the Script Runner or hyperx Python package, instantiation of this class happens automatically, and the below example is not necessary. Otherwise, the enumerated steps and following example script are required.
-
Add a reference to
HyperX.Scripting.dll.Tip
For Python, we recommend a package called Python.NET version 3.0.1 or greater (from a command prompt, run py -m pip install pythonnet).
-
Initialize the HyperX environment by calling
HyperX.Scripting.Environment.Initialize(). -
Instantiate the
Applicationobject.
import winreg
import os
import errno
from pathlib import Path
installFolder = 'PATH/TO/HYPERX/INSTALL/FOLDER'
libFolder = Path(installFolder) / 'Executable'
scriptingDll = libFolder / 'HyperX.Scripting.dll'
typesDll = libFolder / 'HyperX.Types.dll'
runtimeConfig = libFolder / 'HyperX.Scripting.runtimeconfig.json'
if not scriptingDll.exists():
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), scriptingDll)
if not typesDll.exists():
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), typesDll)
if not runtimeConfig.exists():
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), runtimeConfig)
from clr_loader import get_coreclr
from pythonnet import set_runtime
runtime = get_coreclr(runtime_config=str(runtimeConfig))
set_runtime(runtime)
import clr
# Allow importing `HyperX.Scripting`
# import HyperX.Scripting as hxapi
clr.AddReference(str(scriptingDll))
clr.AddReference(str(typesDll))
# Allow C#-compatible types.
# from System.Collections.Generic
import List
clr.AddReference('System.Collections')
# Enable dashboard features
clr.AddReference('System.Security.Cryptography.ProtectedData')
import HyperX.Scripting
import HyperX.Types
# Initialize environment and create application object
HyperX.Scripting.Environment.Initialize()
application = HyperX.Scripting.Application()
The below example demonstrates a Script written in C#, which has references to the HyperX C# assemblies and opens a HyperX Database. The Visual Studio project file (.csproj) for this Console App project is also provided, with relevant settings and references indicated.
-
Add references to HyperX Scripting assemblies.
-
Specify the location of the folder containing the HyperX binaries – this will be the path to a folder named “Executable” in your install directory.
-
Initialize the environment and create a new
Applicationobject.
using HyperX.Scripting;
internal class CSharpSampleScript
{
public static void Main(string[] args)
{
HyperX.Scripting.Environment.SetLocation($"PATH\\TO\\HYPERX\\INSTALL\\FOLDER\\Executable");
HyperX.Scripting.Environment.Initialize();
var hxApplication = new Application();
var databasePath = $"My\\Database\\Path.hdb3";
// Open database
hxApplication.OpenDatabase(databasePath);
}
}