Hello Blender Community,
With my groupmate, we are working on a traffic simulation on Blender as our graduation project. Initially, the simulation engine runs and outputs a .txt file, sim_log.txt, containing the details to be processed by the script on Blender. Then, we run the script and get a visualization of the traffic flow.
Sometimes, I could not really figure out why, the Blender script throws the following exception when trying to read the output file which is in the same directory with the .blender file:
Info: Deleted 0 object(s) Traceback (most recent call last): File "C:\BlenderTest\CS402\SimulationAnimator.blend\Text", line 24, in <module> FileNotFoundError: [Errno 2] No such file or directory: 'sim_log.txt' Error: Python script failed, check the message in the system console
The script up to the line that the error occurs is as follows:
import bpy import os import numpy import random #Test values time = "day" # Clean console, view and orphan data os.system("cls") bpy.ops.object.select_all(action='SELECT') bpy.ops.object.delete() bpy.types.BlendData.orphans_purge() # Set world background if time == "day": bpy.data.worlds['World'].node_tree.nodes['Environment Texture'].image = bpy.data.images.load("//hdris\day.hdr", check_existing=True) else: bpy.data.worlds['World'].node_tree.nodes['Environment Texture'].image = bpy.data.images.load("//hdris\\night.hdr", check_existing=True) cameraCar = "" # Name of the car that camera will follow # File read section f = open("sim_log.txt", "r")
I mostly encounter this problem after another program accesses this file, but sometimes it occurs randomly. I could not find a way to tell Python API/Blender that the file actually is there, so I have been copying the file and updating the filename in the script. I thought the community could spot the problem, so I would not need to work with sim_logv19.txt anymore :)
If you would like to take a look at the project repository, here is the link: https://github.com/sefasenlik/TrafficSim