Mesh.getFromObject() loses materials

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
CWalther
Posts: 0
Joined: Sat Aug 23, 2008 3:51 pm

Mesh.getFromObject() loses materials

Post by CWalther »

In Blender 2.46, with this file, running the following session in the interactive Python console (and also in a script, where I encountered the problem in the first place)

Code: Select all

o = bpy.data.scenes.active.objects[0]
o.getData(mesh=True).materials
m = Mesh.New()
m.getFromObject(o)
m.materials
gives me different results for the two material lists: [[Material "MatShlWal"]] for the first (which is correct), but [None] for the second. The object in question does not have any modifiers attached.

In addition, the call m.getFromObject(o) somehow seems to actually damage the material (or at least affect it in some way) - its box in the Outliner Oops Schematic becomes empty (I don't know exactly what that means), and when I want to edit it in the Material buttons, the Link to Object field in the Links and Pipeline panel with contents MA:MatShlWal has a red background.

Possibly related observation: When I select the object, the Links and Pipeline panel in the Material buttons has the OB button pressed. When I switch to the ME button before running the exercise above, everything works correctly.

Here is a screenshot of the situation. The oops schematic shown in it has not been touched since running the Python commands, so it still shows the state from before.

Is this the intended behavior?
  • If yes: Could somebody explain to me why? My experience so far has been that the original (cage) mesh from Object.getData() always has the same materials as the deformed mesh from Mesh.getFromObject(), even if the object has modifiers. Under what circumstances is this not the case?
  • If not: Is this a bug in Blender 2.46? Or could it be that the file is somehow corrupted? I don't know exactly how that file was created, I got it from someone else and for this demonstration stripped it down to the minimum that still exhibits the problem.

bam93
Posts: 0
Joined: Thu Jan 29, 2009 1:14 am

Re: Mesh.getFromObject() loses materials

Post by bam93 »

CWalther wrote:In Blender 2.46, running the following session in the interactive Python console (and also in a script, where I encountered the problem in the first place)

Code: Select all

o = bpy.data.scenes.active.objects[0]
o.getData(mesh=True).materials
m = Mesh.New()
m.getFromObject(o)
m.materials
gives me different results for the two material lists: [[Material "MatShlWal"]] for the first (which is correct), but [None] for the second. The object in question does not have any modifiers attached.
Hi, I've got a similar problem when trying to union meshes (see here: http://www.blender.org/forum/viewtopic. ... 0942#70942).

Did you find a workaround/correction?

CWalther
Posts: 0
Joined: Sat Aug 23, 2008 3:51 pm

Post by CWalther »

Part of it has been recognized as a bug and fixed, and part explained as intended behavior.

See http://projects.blender.org/tracker/?fu ... group_id=9.

Post Reply