[Bf-python] Fwd: Re: 'obj.data' returns NMesh data object even when made with Mesh class.

Toni Alatalo antont at kyperjokki.fi
Tue Aug 7 10:38:57 CEST 2007


On Tuesday 07 August 2007 07:13:19 Dietrich Bollmann wrote:
> Wouldn't it be enough for backward compatibility to let
> 'data' return the data object the blender object was created with?
> In the case of old code this would be NMesh anyway; in the case
> of code using the newer Mesh class this would be Mesh?

the api just exposes data that is in Blender, and Blender internals don't know 
how a certain Mesh datablock was created. hence there is currently no 
straightforward way to implement that kind of behaviour, and so such a 
possibility has probably never been even considered before.

i think it would be confusing too. imagine you get a blend from someone else, 
where some meshes would be marked as being created using NMesh, and some with 
Mesh, but you don't know, just get strange behaviour from same script working 
for some meshes but not for others.

to summarize: when you create py objects like Mesh data pyobjects in a script, 
those pyobjects are not stored anywhere. they are just a way to use Blender 
to create mesh datablocks, and in Blender (and in .blend files) they are just 
c structs with no py related information whatsoever. so the way you get the 
data (e.g. NMesh or Mesh) defines what you get, not how it has been created.

> Maybe an error message when trying to do something like
> >>> object.data.materials = [ material ]
> would be helpful.

hm .. i wonder if it would make sense for NMesh to handle some errors so that 
it suggests 'i am depracated, did you mean to use Mesh instead?. dunno if 
some hints could be easily hacked there somewhere.

> Or a note at
> http://www.blender.org/documentation/244PythonDoc/Object.Object-class.html#
>data
> Note: For backward compatibility 'data' returns an NMesh object
> even in the case of a blender object which has been created with
> a Mesh data object.  Use 'getData(False, True)' for getting the
> Mesh object.

i guess that sort of thing is the solution now. gotta go now myself, perhaps 
someone else can look into improving the doc.

> Dietrich

~Toni

> By the way - is there some "standard" terminology to talk about
> what I called "blender object" and "data object"?

afaik in Blender: Object, datablock.

e.g. Mesh object, Mesh datablock.

http://www.blender.org/development/architecture/ seems to pretty much concur 
(it has a " " between data and block though :)



More information about the Bf-python mailing list