Page 1 of 1

Finding the name of an object file I imported?

Posted: Sat Nov 03, 2012 10:36 pm
by Jarmade
I want to do some operations on the mesh after i have imported it, like renaming it, but i can't find a way to get the object name

Here is how i imported the object:

Code: Select all

import bpy

folder = "D:/cg/export"

file = "test.obj"
foo = bpy.ops.import_scene.obj(filepath=(folder + "/" + file))

print(foo)

# foo = {'FINISHED'}
# so how do i access the object i just imported?

Posted: Mon Nov 05, 2012 10:16 am
by CoDEmanX
importers should clear previous user selection and select all newly imported objects, thus you should be able to access them via

bpy.context.selected_objects

Posted: Mon Nov 05, 2012 6:04 pm
by Jarmade
CoDEmanX wrote:importers should clear previous user selection and select all newly imported objects, thus you should be able to access them via

bpy.context.selected_objects
thanks, this is what i ended up doing, although it seems messy

Code: Select all

bpy.ops.import_scene.obj(filepath=fullpath)
imported = bpy.context.selected_objects[0]
print(imported.name)

Posted: Sun Nov 25, 2012 3:34 am
by ldo
The basic problem is that operators represent user actions, not really low-level functions. What you want is a separate API call for invoking .obj import that has no UI dependencies.