Python调用VISSIM COM接口GetQueued方法报错的技术问询
GetQueued() COM Error in VISSIM-Python Integration Let's break down why you're hitting that com_error and how to fix it:
The Root Cause
Your code calls cars.GetQueued() where cars is a Vehicles collection object returned by link1.GetVehicles(). The problem is straightforward: VISSIM's COM interface does not implement a GetQueued() method for the Vehicles collection. That's exactly what the error message "Not implemented method called." is telling you.
Correct Approaches to Get Queued Vehicle Data
There are two reliable ways to retrieve queued vehicle information for a link via VISSIM's COM interface:
1. Get Queue Length & Count Directly (Simplest)
If you only need the number of queued vehicles or the physical queue length, use the GetQueueLength() method directly on the Link object. This returns a tuple with two values: queue length in meters, and the count of queued vehicles.
import win32com.client as com vissim_com = com.Dispatch("Vissim.Vissim") Sim = vissim_com.Simulation vissim_com.LoadNet(r'D:\Tracer\labprogramme\vissim\test.inp') vnet = vissim_com.net links = vnet.Links link1 = links.GetLinkByNumber(1) # Fixed typo: GetLinkByNUmber → GetLinkByNumber Sim.Period = 3600 for i in range(3600): Sim.RunSingleStep() # Extract queue metrics directly from the link queue_length, queued_vehicle_count = link1.GetQueueLength() print(f"Step {i}: Queued vehicles: {queued_vehicle_count}, Queue length: {queue_length}m")
2. Filter Vehicles to Get Queued Objects
If you need access to the actual queued Vehicle objects (e.g., to check individual vehicle properties), iterate over all vehicles on the link and use their IsQueued property to filter:
import win32com.client as com vissim_com = com.Dispatch("Vissim.Vissim") Sim = vissim_com.Simulation vissim_com.LoadNet(r'D:\Tracer\labprogramme\vissim\test.inp') vnet = vissim_com.net links = vnet.Links link1 = links.GetLinkByNumber(1) Sim.Period = 3600 for i in range(3600): Sim.RunSingleStep() cars = link1.GetVehicles() queued_cars = [] for car in cars: if car.IsQueued: # Check if the vehicle is in queue state queued_cars.append(car) print(f"Step {i}: Number of queued vehicles: {len(queued_cars)}")
Quick Additional Notes
- I fixed a small typo in your original code (
GetLinkByNUmber→GetLinkByNumber)—this could have caused an extra error if left unaddressed! - If you're using an older VISSIM version, double-check the
VISSIMCOM.HLPfile mentioned in your error for version-specific method names (some older builds useQueueLengthinstead ofGetQueueLength).
内容的提问来源于stack exchange,提问作者tracer

