Why does my export script have this effect?

Hi everyone.

I’ve got a script that is supposed to:

  1. Duplicate all meshes and curves in a scene.
  2. Convert all of those to meshes, thereby applying any modifiers in the process.
  3. Apply all transformations on the duplicates.
  4. Select only the duplicates and export to 3ds.
  5. Delete the duplicates.

My test file has Object A and Object B.

When Object A is the active object and the script runs, it applies object A’s modifiers and transforms. This is NOT what I want to happen. It should leave both Object A and Object B untouched and only convert their duplicates for export.

Yet, if Object B is the active object, it works correctly.

All you need is in the blend file, but here’s the code anyway:

import bpy

scene_objects = bpy.context.scene.objects
previous_scene_objects = scene_objects[:]

temporary_objects = list()
previous_selection = list()
previous_active_object = scene_objects.active

print("


")

#collect all the mesh objects and curve objects in the scene.
#also, store the previous selection
for object in previous_scene_objects:
    if object.select:
        previous_selection.append(object)
   
    if object.type == 'MESH' or object.type == 'CURVE':
        print(object.name)
        object.select = False
   
        #make a temporary duplicate of the object and its data
        temporary_object = object.copy()
        print("	created new object: " + temporary_object.name)
        temporary_object.data = object.data.copy()
        print("	created new data: " + temporary_object.data.name)
        temporary_objects.append(temporary_object)

        #link the temporary object to the scene and select it
        scene_objects.link(temporary_object)
       
        temporary_object.select = True
        scene_objects.active = temporary_object
       
        #convert the temporary object to a mesh and apply its transformations.
        print("	converting " + scene_objects.active.name)
        bpy.ops.object.convert(target='MESH',keep_original=False)
        bpy.ops.object.transform_apply(location=True,rotation=True,scale=True)
        print("")

#export the selected temporary objects as a 3ds
bpy.ops.export_scene.autodesk_3ds(filepath=bpy.data.filepath[:-6] + ".3ds",check_existing=False,filter_glob="*.3ds",use_selection=True,axis_forward='Y',axis_up='Z')

#delete the temporary objects.
for object in temporary_objects:
    scene_objects.active = object
    bpy.ops.object.delete()
   
#restore the previous selections and active object
for object in previous_selection:
    object.select = True

scene_objects.active = previous_active_object

Thanks for any help!

Attachments

test.blend (491 KB)

trying to run your blend, it crashes Blender (version of this morning) …

remark: list() === [] , [] I prefer [] …

Looking at the commands, which looked to me essential, apart it works (done in the console)

So what line crashes this …?

(and learned a lot of your script :wink: )

Hmm. I should have mentioned I’m using the official 2.61 build from the blender.org website.

I’ll download the latest and run some more tests…