Python sample¶
[!IMPORTANT] Use 64-bit Python. The SIDRA API is x64-only and will refuse to load into a 32-bit interpreter with
pywintypes.com_error: ... Class not registered.
import win32com.client
import pythoncom
# Activate the API.
api = win32com.client.Dispatch("SIDRASolutions.SI.API")
try:
api.OpenProject(r"C:\Samples\Demo.sip")
project = api.Project
print(f"Project: {project.Name}")
api.Analysis.Run()
for f in range(project.SiteFolders.Count):
folder = project.SiteFolders(f)
for s in range(folder.Sites.Count):
site = folder.Sites(s)
for i in range(site.Intersections.Count):
intersection = site.Intersections(i)
print(f" {intersection.Name}: LOS = {intersection.LevelOfService}")
finally:
del api
pythoncom.CoUninitialize()
Generating early-bound bindings¶
win32com.client.Dispatch uses late binding by default. For better
performance and intellisense in IDEs, generate early-bound classes once:
After that win32com.client.Dispatch("SIDRASolutions.SI.API") returns a
typed wrapper.
Threading¶
pywin32 initializes COM in MTA mode on worker threads. The SIDRA
Intersection API requires STA — call pythoncom.CoInitialize() on
the thread before activating, and pythoncom.CoUninitialize() when done.