PowerShell sample¶
PowerShell drives the API as a COM host: activate it with
New-Object -ComObject and call members directly. This sample opens a SIDRA
project, processes every site, and prints its level of service and degree of
saturation.
Note
Complete the Getting started prerequisites first
(SIDRA Intersection installed, .NET 8). You also need a SIDRA project
(.sipx) file to open. Save one from SIDRA Intersection, or point the
sample at any existing project. Replace C:\Samples\Demo.sipx below with
its path. If anything fails, see Troubleshooting.
Important
Use a 64-bit PowerShell host. The SIDRA API is x64-only; a 32-bit host
fails to activate it with 0x80040154 REGDB_E_CLASSNOTREG. Windows
PowerShell 5.1 (powershell.exe) and PowerShell 7 (pwsh) are 64-bit on
64-bit Windows.
1. Write the script¶
first_program.ps1:
$api = New-Object -ComObject "SIDRASolutions.SI.API"
try {
if (-not $api.OpenProject("C:\Samples\Demo.sipx")) {
throw "Could not open project: $($api.LastErrorMessage)"
}
$project = $api.Project
Write-Host "Project: $($project.Name)"
# Project -> SiteFolders -> Sites. In SIDRA a "site" is an intersection.
$folders = $project.SiteFolders
for ($f = 0; $f -lt $folders.Count; $f++) {
$sites = $folders.Item_2($f).Sites
for ($s = 0; $s -lt $sites.Count; $s++) {
$site = $sites.Item_2($s)
[void]$site.Process() # run the analysis for this site
# Site-level vehicle results live under Outputset.OutputSiteVehicle.
$result = $site.Outputset.OutputSiteVehicle
$dos = "{0:N3}" -f $result.Deg_satn
Write-Host " $($site.Name): LOS $($result.Level_of_service), degree of saturation $dos"
}
}
}
finally {
[void][System.Runtime.InteropServices.Marshal]::FinalReleaseComObject($api)
}
2. Run it¶
Expected output (values depend on your project):
Project: Demo
North Rd / Main St: LOS B, degree of saturation 0.742
East Ave / Main St: LOS C, degree of saturation 0.871
Note
The collection interfaces expose two indexers: by name and by position.
Over late-bound COM (as PowerShell uses) these surface as separate members:
Item(name) looks up by name, and Item_2(index) retrieves by position.
The example above iterates by position with Item_2.
Releasing the object¶
Release the COM object when finished with
[System.Runtime.InteropServices.Marshal]::FinalReleaseComObject($api). The
.NET COM host keeps the SIDRA Intersection runtime alive until every reference
is released.