Previous Thread  Next Thread

chat icon Finding the name of an object file I imported?

Jarmade

Posted: Sat Nov 03, 2012 10:36 pm
Joined: 03 Nov 2012
Posts: 4
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:

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?
Reply with quote


CoDEmanX

Posted: Mon Nov 05, 2012 10:16 am
Joined: 05 Apr 2009
Posts: 680
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
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Reply with quote


Jarmade

Posted: Mon Nov 05, 2012 6:04 pm
Joined: 03 Nov 2012
Posts: 4
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:

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


ldo

Posted: Sun Nov 25, 2012 3:34 am
Joined: 07 Nov 2010
Posts: 543
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.
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group