Automating with Python
This guide shows you how to automate AdSec using Python. This allows you to script workflows for tasks such as creating sections, running analyses, and extracting results.
By following this guide, you will:
- Install the AdSec API
- Activate your license
- Run a working Python script
Before proceeding, ensure you meet the general requirements for automating with AdSec.
Step 1: Install the AdSec API
Ensure Python is installed. Check by running the following command in your terminal or command prompt:
python --version
If Python is not installed, install Python (version 3.11 or earlier recommended).
Next, install the AdSec API package by running the following command:
python -m pip install oasys.adsec
Step 2: Activate your license
The AdSec API requires a license. To activate it, you will need:
- A license number
- A password
If you do not have these, contact Oasys support.
Run the activation script
Copy and run the following script, then input the required information in the terminal:
import oasys.adsec
from Oasys.AdSec import ILicense
if __name__ == "__main__":
res = ILicense.ActivateLicense(input("Please enter your license number: "), input("Please enter your password: "))
if res.ActionStatus == 1:
print("License activated successfully!")
else:
print("Failed to activate license.")
print("Product Name:", res.ProductInformation.ProductName)
print("Version:", res.ProductInformation.Version)
print("Company Name:", res.LicenseInformation.CompanyName)
print("License Id:", res.LicenseInformation.LicenseId)
print("Number of Days left:", res.LicenseInformation.NumberOfDays)
print("Number of Seats remaining:", res.LicenseInformation.NumberOfSeats)
print("Session Id:", res.LicenseInformation.SessionId)
print("Time Allocated Until Expiry:", res.LicenseInformation.TimeAllocatedUntilExpiry)
for warning in res.Warnings:
print(warning.Description)
Step 3: Verify activation
Your license is successfully activated when the script runs without errors and prints license information.Run this short script to confirm everything is set up:
import oasys.adsec
from Oasys.AdSec import IVersion
print("AdSec API version:", IVersion.Api())
If a version number is printed, your setup is complete.
If activation fails, check the following:
- All general requirements are met
- Your license number and password are correct
If the issue persists, contact Oasys support.
Step 4: Run your first script
You are now ready to run AdSec automations using Python.
To get started, run one of the example scripts:
Step 5: You are ready to build
You have now:
- Installed the AdSec API
- Activated your license
- Run a sample script
Start building AdSec automations with Python