This repository was archived by the owner on Jun 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetVissimStaticRouteExemption.py
More file actions
66 lines (51 loc) · 2.67 KB
/
setVissimStaticRouteExemption.py
File metadata and controls
66 lines (51 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'''
This script is to give a vehicle class exemption on route decisions.
i.e. vehicles of this class will not make left/right turns and always go straight.
'''
import pandas as pd
import os
from pandas.core.frame import DataFrame
import win32com.client as com
# This is the vehicle class to be exculded from the static route decisions
VEHICLE_CLASS_TO_EXEMPT = 70
#############################################################################
###################### PARAMETERS TO SET
#############################################################################
# !!!!!! change the absolute_folder_path
absolute_folder_path = os.path.abspath(os.path.join(os.getcwd(), r'.\VISSIMfiles')) # absolute folder path of the vissim .inpx and .layx files
file_name = 'RealSimNetwork' # file name of vissim network and layout without extension .inpx and .layx
#############################################################################
###################### LAUNCH VISSIM
#############################################################################
# Load a Vissim Network & Layout
netname = '{}.inpx'.format(file_name)
NetFilename = os.path.join(absolute_folder_path, netname)
flag_read_additionally = False # you can read network(elements) additionally, in this case set "flag_read_additionally" to true
layoutname = '{}.layx'.format(file_name)
LayoutFilename = os.path.join(absolute_folder_path, layoutname)
# Connecting the COM Server => Open a new Vissim Window:
# !!!! change VISSIM version if needed
Vissim = com.Dispatch("Vissim.Vissim-64.2100")
Vissim.LoadNet(NetFilename, flag_read_additionally)
# Load a Layout
Vissim.LoadLayout(LayoutFilename)
# get all vehicle classes
VehicleClassesAll = Vissim.Net.VehicleClasses.GetAll()
VehicleClassInRouteStr = "" # all these vehicle classes will follow route decisions
for vehClass in VehicleClassesAll:
vehClassNo = vehClass.AttValue("No")
if vehClassNo != VEHICLE_CLASS_TO_EXEMPT:
VehicleClassInRouteStr = VehicleClassInRouteStr+str(vehClassNo)+","
VehicleClassInRouteStr = VehicleClassInRouteStr[:-1]
# loop over all routing decisions and disable the class specified
VehicleRoutingDecisionAll = Vissim.Net.VehicleRoutingDecisionsStatic.GetAll()
for vehRoute in VehicleRoutingDecisionAll:
vehRoute.SetAttValue("AllVehTypes", 0)
vehRoute.SetAttValue("VehClasses", VehicleClassInRouteStr)
# setup ends
print("Done! Exempted vehicle class {} from static route decisions!".format(VEHICLE_CLASS_TO_EXEMPT))
#############################################################################
###################### SAVE and EXIT VISSIM
#############################################################################
Vissim.SaveNet()
Vissim.Exit()