Finding the name of an object file I imported?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Jarmade
Posts: 4
Joined: Sat Nov 03, 2012 10:12 pm

Finding the name of an object file I imported?

Postby Jarmade » Sat Nov 03, 2012 10:36 pm

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?

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Mon Nov 05, 2012 10:16 am

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...

Jarmade
Posts: 4
Joined: Sat Nov 03, 2012 10:12 pm

Postby Jarmade » Mon Nov 05, 2012 6:04 pm

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)

ldo
Posts: 544
Joined: Sun Nov 07, 2010 11:30 pm
Location: Hamilton, New Zealand

Postby ldo » Sun Nov 25, 2012 3:34 am

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.


Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest