Two scripts.
The first will go through each object you have selected move it to (0,0,0), set the rotation to (0,0,0), export to FBX and then put the object back in its original loc/rot. It drops the duplicate indication(.001 etc), and only saves if the file does not exist.
I scoured the internet and pieced it together, so I can't take credit for it. I ended up posting this on some Blender forum as I was seeking help, but got it working before I got any replies.
import bpy
import os
import re
#example path to store files
path = 'E:\\SteamLibrary\\steamapps\\common\\App Game Kit 2\\test1\\media\\levels\\'
#store selection
obs = bpy.context.selected_objects
for ob in obs:
#deselect all but just one object and make it active
bpy.ops.object.select_all(action='DESELECT')
ob.select_set(state=True)
bpy.context.view_layer.objects.active = ob
#store object location then zero it out
location = ob.location.copy()
bpy.ops.object.location_clear()
name = ob.name
name = re.sub("[.].*?$", '', name)
scale = ob.scale.copy()
ob.scale = (1,1,1)
rotx = ob.rotation_euler[0]
roty = ob.rotation_euler[1]
rotz = ob.rotation_euler[2]
ob.rotation_euler[0] = 0
ob.rotation_euler[1] = 0
ob.rotation_euler[2] = 0
#export fbx
filename = path + name + '.fbx'
if os.path.isfile(filename):
print("Already Exist")
else:
bpy.ops.export_scene.fbx(filepath=filename, use_selection=True, apply_scale_options='FBX_SCALE_UNITS')
#restore location
ob.location = location
ob.rotation_euler[0] = rotx
ob.rotation_euler[1] = roty
ob.rotation_euler[2] = rotz
ob.scale = scale
#reselect originally selected objects
for ob in obs:
ob.select_set(state=True)
This just creates a text file with the object data info. Found it on stackoverflow. Lost the source. This will also tell you what collection your object is in. I find it useful for merging certain objects together. Or knowing where to place lights, etc.
import bpy
import re
def grados(radianes):
x= (180*radianes)/3.141516
return x
#open path_file where I will save
full_filel = bpy.data.filepath.split("\\")
#print(full_filel)
#print(len(full_filel))
contador = 1
path_file = full_filel[0]
while contador != len(full_filel)-1:
path_file = str(path_file) + "\\" + str(full_filel[contador])
contador +=1
#path_file actual
print(path_file)
#file name
path = 'E:\\SteamLibrary\\steamapps\\common\\App Game Kit 2\\test1\\media\\levels\\'
file_name = "Level_1.txt"
#path blend file
file1 = open((path + file_name), 'w', encoding = "utf-8")
#objects = bpy.context.scene.objects
sel_obj = bpy.context.selected_objects
for ob in sel_obj:
if ob.type =="MESH":
name = ob.name
name = re.sub("[.].*?$", '', name)
col = ob.users_collection[0].name
loc = tuple(ob.location)
rot = [grados(ob.rotation_euler[0]), grados(ob.rotation_euler[1]), grados(ob.rotation_euler[2])]
scale = tuple(ob.scale)
#print(col, " ", name, " ", loc, " ", rot, " ", scale)
dato = (col, name," Location: ", loc, " Rotation: ", rot, " Scale: ", scale)
#write data in file
file1.write(str(dato) + "\n")
#close the file
file1.close()
Really makes me appreciate Python. I have never put in any effort until today.
Don't forget in Blender the y and z are transposed.