Skip to main content
Post Closed as "Duplicate" by p2or, Ray Mairlot, Denis, batFINGER, Shady Puck
changed "without" to "with" referencing the print command that's commented out
Source Link
J Rowoldt
  • 335
  • 1
  • 3
  • 10

So is importing .obj in 2.78 via script broken, or am I not doing it right? It's crashing on import in my script when I try and reference the object at all.

import bpy
file_loc = 'C:\\Users\\MyComp\\Documents\\3Dobjects\\obj\\humans\\human_figure_JOINED.obj'
imported_object = bpy.ops.import_scene.obj(filepath=file_loc)
obj_object = bpy.context.object
#print('Imported name', imported_object.name)
print('Imported name: ', obj_object.name)

Running this withoutwith the first print statement yields this:

AttributeError: 'set' object has no attribute 'name'

If I let it run as shown, the second print gives me an object "Point.001" which is I think the last created object, so the active one?

I have tried to link the imported object to the scene by adding the following code, but this doesn't seem to work:

scn = bpy.context.scene
scn.objects.link(imported_object)

This gives me an error:

TypeError: SceneObjects.link(): error with argument 1, "object" -  Function.object expected a Object type, not set

Appears to me to be something wrong with the import. If I import via the UI (File..Import...Wavefront(.obj) everything seems ok, as in it imports and can be manipulated.

Any ideas?

I would select it referencing the name but I can't even get the name because the reference getting it from "imported object" fails.

So is importing .obj in 2.78 via script broken, or am I not doing it right? It's crashing on import in my script when I try and reference the object at all.

import bpy
file_loc = 'C:\\Users\\MyComp\\Documents\\3Dobjects\\obj\\humans\\human_figure_JOINED.obj'
imported_object = bpy.ops.import_scene.obj(filepath=file_loc)
obj_object = bpy.context.object
#print('Imported name', imported_object.name)
print('Imported name: ', obj_object.name)

Running this without the first print statement yields this:

AttributeError: 'set' object has no attribute 'name'

If I let it run as shown, the second print gives me an object "Point.001" which is I think the last created object, so the active one?

I have tried to link the imported object to the scene by adding the following code, but this doesn't seem to work:

scn = bpy.context.scene
scn.objects.link(imported_object)

This gives me an error:

TypeError: SceneObjects.link(): error with argument 1, "object" -  Function.object expected a Object type, not set

Appears to me to be something wrong with the import. If I import via the UI (File..Import...Wavefront(.obj) everything seems ok, as in it imports and can be manipulated.

Any ideas?

I would select it referencing the name but I can't even get the name because the reference getting it from "imported object" fails.

So is importing .obj in 2.78 via script broken, or am I not doing it right? It's crashing on import in my script when I try and reference the object at all.

import bpy
file_loc = 'C:\\Users\\MyComp\\Documents\\3Dobjects\\obj\\humans\\human_figure_JOINED.obj'
imported_object = bpy.ops.import_scene.obj(filepath=file_loc)
obj_object = bpy.context.object
#print('Imported name', imported_object.name)
print('Imported name: ', obj_object.name)

Running this with the first print statement yields this:

AttributeError: 'set' object has no attribute 'name'

If I let it run as shown, the second print gives me an object "Point.001" which is I think the last created object, so the active one?

I have tried to link the imported object to the scene by adding the following code, but this doesn't seem to work:

scn = bpy.context.scene
scn.objects.link(imported_object)

This gives me an error:

TypeError: SceneObjects.link(): error with argument 1, "object" -  Function.object expected a Object type, not set

Appears to me to be something wrong with the import. If I import via the UI (File..Import...Wavefront(.obj) everything seems ok, as in it imports and can be manipulated.

Any ideas?

I would select it referencing the name but I can't even get the name because the reference getting it from "imported object" fails.

Source Link
J Rowoldt
  • 335
  • 1
  • 3
  • 10

Blender 2.78 .obj import via script

So is importing .obj in 2.78 via script broken, or am I not doing it right? It's crashing on import in my script when I try and reference the object at all.

import bpy
file_loc = 'C:\\Users\\MyComp\\Documents\\3Dobjects\\obj\\humans\\human_figure_JOINED.obj'
imported_object = bpy.ops.import_scene.obj(filepath=file_loc)
obj_object = bpy.context.object
#print('Imported name', imported_object.name)
print('Imported name: ', obj_object.name)

Running this without the first print statement yields this:

AttributeError: 'set' object has no attribute 'name'

If I let it run as shown, the second print gives me an object "Point.001" which is I think the last created object, so the active one?

I have tried to link the imported object to the scene by adding the following code, but this doesn't seem to work:

scn = bpy.context.scene
scn.objects.link(imported_object)

This gives me an error:

TypeError: SceneObjects.link(): error with argument 1, "object" -  Function.object expected a Object type, not set

Appears to me to be something wrong with the import. If I import via the UI (File..Import...Wavefront(.obj) everything seems ok, as in it imports and can be manipulated.

Any ideas?

I would select it referencing the name but I can't even get the name because the reference getting it from "imported object" fails.