The beginning steps of VISSIM COM programming with MATLAB script
Tamas Tettamanti,
Budapest University of Technology, Dept. of Vehicle and Transportation Control
H-1111 Stoczek Jozsef u. 2. www.traffic.bme.hu/index.php/en
Note that some parts of the VISSIM COM interface are not available through MATLAB. In this case,
you should use e.g. VISUAL BASIC or VISUAL C++ for COM programming. Nevertheless, for simple
problems, MATLAB can be sufficient.
1. Open a new script file (*.m) in MATLAB. Create a new a COM (ActiveX) Automation server:
vissim_com=actxserver('VISSIM.vissim.540');
For more information use the help option of MATLAB in the Command Window:
>> help actxserver
2. MATLAB COM methods can be shown by
>> help com
However, only the following methods can be called via VISSIM COM:
delete
events
get
interfaces
invoke
move
release
set
- Delete a COM object.
- Return list of events the COM object can trigger.
- Get COM object properties.
- List custom interfaces supported by a COM server.
- Invoke method on object or interface, or display methods.
- Move and/or resize an ActiveX control in its parent window.
- Release a COM interface.
- Set a property value on a COM object.
For more information about a VISSIM COM method, type in the MATLAB Command Window:
>> vissim_com.[COM method name]
3. A simple COM program in MATLAB script is given below.
clear all;
clc;
format compact;
vissim_com=actxserver('VISSIM.vissim.540');
vissim_com.LoadNet('E:\Kutatas\Vissim_Com_Matlab\vissim_files\matlab_test.inp');
vissim_com.LoadLayout('E:\Kutatas\Vissim_Com_Matlab\vissim_files\vissim.ini');
sim=vissim_com.simulation;
timestep=1;
sim.Resolution=timestep;
vnet=vissim_com.net;
scs=vnet.signalcontrollers;
sc=scs.GetSignalControllerByNumber(1);
sgs=sc.signalgroups;
sg_1=sgs.GetSignalGroupByNumber(1);
sg_2=sgs.GetSignalGroupByNumber(2);
links=vnet.links;
link_1=links.GetLinkByNumber(1);
link_2=links.GetLinkByNumber(2);
for i=0:1800
sim.RunSingleStep;
pause(.05)
if rem(i,10)==0
density=link_1.GetSegmentResult('Density', 0, 0.0,1,0)
if density>40
sg_1.set('State',3); %Green=3
sg_2.set('State',1);
else
sg_1.set('State',1); %Red=1
sg_2.set('State',3);
end
disp(['Simulation Time: ' num2str(i)]);
end
end
4. Start simulation from Debug/Run *.m or by using button F5.
5. Further help on VISSIM COM programming can be found in the official VISSIM help
documentation in your local file directory: C:\Program Files\PTV_Vision\VISSIM5.40\Doc.
If you have found this document useful in your work, please, cite one of my papers in your thesis or
publication, e.g. VISSIM-MATLAB Simulation Environment.