Many thanks to Martynas Žiemys for his answer here:
how can I export object position info from blender to text file?
which basically works for me, however I have an issue when the very last object prints.
@batFINGER helped by pointing out fstrings; I then went away to condense and clarify the problem, but it got more bizarre! Here's the test code:
import bpy
def Export() :
count = 0
print ( "Export:" )
for obj in bpy.context.scene.objects:
count += 1
print(f"{count} {obj.name} {' '.join(map(str, obj.dimensions))}")
def CreateObject ( i ) :
bpy.ops.mesh.primitive_cube_add ( location = ( i * 10 , 0 , 0 ) )
obj = bpy.context.active_object
obj.dimensions = ( i * 2 , 1 , 1 )
obj.name = "obj_%d" % i
print(f"{i} {obj.name} {' '.join(map(str, obj.dimensions))}")
print ( "Blender version: %s" % bpy.app.version_string )
delete all objects from any previous run
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False, confirm=False)
print ( "Create first 3 objects:" )
for i in range ( 1 , 4 ) :
CreateObject ( i )
Export()
print ( "Create extra object (4th):" )
CreateObject ( 4 )
print ( "Create extra object (5th):" )
CreateObject ( 5 )
Export()
I'm printing each object twice: during creation and at export. Here's the terminal output:
Blender version: 2.93.1
Info: Deleted 5 object(s)
Create first 3 objects:
1 obj_1 2.0 2.0 2.0
2 obj_2 2.0 2.0 2.0
3 obj_3 2.0 2.0 2.0
Export:
1 obj_1 2.0 1.0 1.0
2 obj_2 4.0 1.0 1.0
3 obj_3 2.0 2.0 2.0
Create extra object (4th):
4 obj_4 2.0 2.0 2.0
Create extra object (5th):
5 obj_5 2.0 2.0 2.0
Export:
1 obj_1 2.0 1.0 1.0
2 obj_2 4.0 1.0 1.0
3 obj_3 6.0 1.0 1.0
4 obj_4 8.0 1.0 1.0
5 obj_5 2.0 2.0 2.0
All of the creation reports are wrong. All but the last export report are correct.
Create:
1 obj_1 2.0 2.0 2.0
2 obj_2 2.0 2.0 2.0
3 obj_3 2.0 2.0 2.0
Export:
1 obj_1 2.0 1.0 1.0
2 obj_2 4.0 1.0 1.0
3 obj_3 2.0 2.0 2.0
How can I post the test code? Limited to 600 characters here.
– Steve Myatt Aug 11 '21 at 00:02