以前「Python版踏切スクリプト改の改」にて書いたスクリプトでは使い回しする上では厳しいだろうということで、設定方法を変えた改良版を考えました。動作自体は以前と同じです。
#OBJID=53
#手前進入センサー(設定用)
import vrmapi
#踏切名(共通ステータス名)
#手前側警報機ID:47
#奥側警報機ID:48
#先降下遮断機1ID:49
#先降下遮断機2ID:51
#後降下遮断機1ID:50
#後降下遮断機2ID:52
#先降下待ち時間:3.0
#後降下待ち時間:6.0
#上昇待ち時間:2.0
crossinglist001 = ['踏切001' , 47 , 48 , 49 , 51 , 50 , 52 , 3.0 , 6.0 , 2.0]
def vrmevent_53(obj,ev,param):
di = obj.GetDict()
if ev == 'init':
obj.SetSNSMode(0)
stime = 3.0 #遮断機降下時間
global crossinglist001
di['crossingname'] = crossinglist001[0]
di['crossing_k1'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[1])
di['crossing_k2'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[2])
di['crossing_s1'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[3])
di['crossing_s2'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[4])
di['crossing_s3'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[5])
di['crossing_s4'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[6])
di['crossing_t1'] = crossinglist001[7]
di['crossing_t2'] = crossinglist001[8]
di['crossing_s1'].SetCrossingTime(stime)
di['crossing_s2'].SetCrossingTime(stime)
di['crossing_s3'].SetCrossingTime(stime)
di['crossing_s4'].SetCrossingTime(stime)
elif ev == 'broadcast':
dummy = 1
elif ev == 'timer':
dummy = 1
elif ev == 'time':
dummy = 1
elif ev == 'after':
if param['eventUID'] == 100:
di['crossing_s1'].SetCrossingStatus(2)
di['crossing_s2'].SetCrossingStatus(2)
if param['eventUID'] == 101:
di['crossing_s3'].SetCrossingStatus(2)
di['crossing_s4'].SetCrossingStatus(2)
elif ev == 'frame':
dummy = 1
elif ev == 'catch':
if obj.GetForward() == 1:
crossarea = vrmapi.LAYOUT().GetStatusDataInt(di['crossingname'])
crossarea = crossarea + 1
#vrmapi.LOG(crossarea)
vrmapi.LAYOUT().SetStatusDataInt(di['crossingname'], crossarea)
di['crossing_k1'].IncAutoSignStatus(1)
di['crossing_k2'].IncAutoSignStatus(0)
di['crossing_k1'].SetCrossingStatus(2)
di['crossing_k2'].SetCrossingStatus(2)
obj.SetEventAfter(di['crossing_t1'],100)
obj.SetEventAfter(di['crossing_t2'],101)
#OBJID=54
#手前退出センサー
import vrmapi
def vrmevent_54(obj,ev,param):
di = obj.GetDict()
if ev == 'init':
obj.SetSNSMode(1)
global crossinglist001
di['crossingname'] = crossinglist001[0]
di['crossing_k1'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[1])
di['crossing_k2'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[2])
di['crossing_s1'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[3])
di['crossing_s2'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[4])
di['crossing_s3'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[5])
di['crossing_s4'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[6])
di['crossing_t3'] = crossinglist001[9]
elif ev == 'broadcast':
dummy = 1
elif ev == 'timer':
dummy = 1
elif ev == 'time':
dummy = 1
elif ev == 'after':
if param['eventUID'] == 100:
di['crossing_s1'].SetCrossingStatus(1)
di['crossing_s2'].SetCrossingStatus(1)
di['crossing_s3'].SetCrossingStatus(1)
di['crossing_s4'].SetCrossingStatus(1)
elif ev == 'frame':
dummy = 1
elif ev == 'catch':
if obj.GetForward() == 1:
crossarea = vrmapi.LAYOUT().GetStatusDataInt(di['crossingname'])
crossarea = crossarea - 1
#vrmapi.LOG(crossarea)
vrmapi.LAYOUT().SetStatusDataInt(di['crossingname'], crossarea)
di['crossing_k1'].DecAutoSignStatus(1)
di['crossing_k2'].DecAutoSignStatus(0)
if crossarea == 0:
di['crossing_k1'].SetCrossingStatus(1)
di['crossing_k2'].SetCrossingStatus(1)
obj.SetEventAfter(di['crossing_t3'],100)
#OBJID=55
#奥進入センサー
import vrmapi
def vrmevent_55(obj,ev,param):
di = obj.GetDict()
if ev == 'init':
obj.SetSNSMode(0)
global crossinglist001
di['crossingname'] = crossinglist001[0]
di['crossing_k1'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[1])
di['crossing_k2'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[2])
di['crossing_s1'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[3])
di['crossing_s2'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[4])
di['crossing_s3'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[5])
di['crossing_s4'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[6])
di['crossing_t1'] = crossinglist001[7]
di['crossing_t2'] = crossinglist001[8]
elif ev == 'broadcast':
dummy = 1
elif ev == 'timer':
dummy = 1
elif ev == 'time':
dummy = 1
elif ev == 'after':
if param['eventUID'] == 100:
di['crossing_s1'].SetCrossingStatus(2)
di['crossing_s2'].SetCrossingStatus(2)
if param['eventUID'] == 101:
di['crossing_s3'].SetCrossingStatus(2)
di['crossing_s4'].SetCrossingStatus(2)
elif ev == 'frame':
dummy = 1
elif ev == 'catch':
if obj.GetForward() == 1:
crossarea = vrmapi.LAYOUT().GetStatusDataInt(di['crossingname'])
crossarea = crossarea + 1
#vrmapi.LOG(crossarea)
vrmapi.LAYOUT().SetStatusDataInt(di['crossingname'], crossarea)
di['crossing_k1'].IncAutoSignStatus(0)
di['crossing_k2'].IncAutoSignStatus(1)
di['crossing_k1'].SetCrossingStatus(2)
di['crossing_k2'].SetCrossingStatus(2)
obj.SetEventAfter(di['crossing_t1'],100)
obj.SetEventAfter(di['crossing_t2'],101)
#OBJID=56
#奥退出センサー
import vrmapi
def vrmevent_56(obj,ev,param):
di = obj.GetDict()
if ev == 'init':
obj.SetSNSMode(1)
global crossinglist001
di['crossingname'] = crossinglist001[0]
di['crossing_k1'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[1])
di['crossing_k2'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[2])
di['crossing_s1'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[3])
di['crossing_s2'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[4])
di['crossing_s3'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[5])
di['crossing_s4'] = vrmapi.LAYOUT().GetCrossing(crossinglist001[6])
di['crossing_t3'] = crossinglist001[9]
elif ev == 'broadcast':
dummy = 1
elif ev == 'timer':
dummy = 1
elif ev == 'time':
dummy = 1
elif ev == 'after':
if param['eventUID'] == 100:
di['crossing_s1'].SetCrossingStatus(1)
di['crossing_s2'].SetCrossingStatus(1)
di['crossing_s3'].SetCrossingStatus(1)
di['crossing_s4'].SetCrossingStatus(1)
elif ev == 'frame':
dummy = 1
elif ev == 'catch':
if obj.GetForward() == 1:
crossarea = vrmapi.LAYOUT().GetStatusDataInt(di['crossingname'])
crossarea = crossarea - 1
#vrmapi.LOG(crossarea)
vrmapi.LAYOUT().SetStatusDataInt(di['crossingname'], crossarea)
di['crossing_k1'].DecAutoSignStatus(0)
di['crossing_k2'].DecAutoSignStatus(1)
if crossarea == 0:
di['crossing_k1'].SetCrossingStatus(1)
di['crossing_k2'].SetCrossingStatus(1)
obj.SetEventAfter(di['crossing_t3'],100)
設定は赤文字の所を変更してください。また踏切を追加する場合にはオレンジ色のグローバル変数の名前を変更する必要があります。ちょっと大変ですが以前のように踏切のIDを全部書き換えるよりは楽になっていると思います。