Blender 2.8 windows 10
So the idea of this script is that it will look in a directory for a good 3 thousand or so object files and one by one import them do some things like recalculating normals and converting triangles. And then saving blend files. However I am very very new to python coding and am having a bit of trouble.
import math import bpy import mathutils import os # a list of all models in the directory all models model_list = os.listdir("B:\Planetside LOA project\Assets\All Models") # the total number of models to be used in the while loop model_total = len(model_list) # current selected model model_select = 0 # path to the model directory # stored path of directory and specific model file target_path = "yeet" # to store the model's name in memory for simplicity temp_model_name = "dab" # the name of the object minus .obj cur_object = "yote" while (model_select != 1): target_path = "'B:\\Planetside LOA project\\Assets\\All Models\\" + model_list[model_select] + "\\'" # imports the model bpy.ops.import_scene.obj(filepath=target_path) # gets the name of the current object temp_model_name = model_list[model_select] # figures out the length of the filename minus 4 characters rem_obj = len(temp_model_name) - 4 # stores cur object as the object name as it is imported into blender cur_object = "bpy.data.objects['" + temp_model_name[0:rem_obj] + "']" # selects the object that was imported cur_object.select = True model_select = model_select + 1
The while loop has been modified for testing purposes it would normally be model_select != model_total. The problem seemed to initially be with the target path string the backslashes where causing line continuation errors so I doubled them up after doing some research. Interesting note however I entered this line into the console
>>> str = "B:\Planetside LOA project\Assets\All Models"
the output is well confusing to say the least here is what it reads.
>>> str 'B:\\Planetside LOA project\\Assets\\All Models'
I have exactly zero idea why the output would double up the \s. Entering the same code with doubled slashes leads to the same output. Just a side note that was confusing Anyway the console spits an error about the script failing and to check the info console but there is no further information. And I am completely stumped. here it is exactly not very informative
bpy.ops.text.run_script() Python script failed, check the message in the system console
And there is no further console info. At least for my messed up string it gave me something.