0
$\begingroup$

For example:

camera_obj = bpy.data.camera.new("Camera")
obj = bpy.data.objects.new("Camera", camera_obj)

works as expected. But is it possible to create obj and camera_obj in separate places, then link(is it even the correct term?) them together?

camera_obj = bpy.data.camera.new("Camera")
# Much code later...
obj = bpy.data.objects.new("Camera", None)
# Much much code later...
obj.data = camera_obj # Doesn't work. What should this line look like?
$\endgroup$
5
  • 1
    $\begingroup$ No it doesn't work that way. An object with None as data is an empty and cannot be converted elsewise to another object type by setting the data. Nor can you make a mesh a camera or any other type once created. You can only assign another datablock of same type to an objects data. I'm sure this has been asked and answered before, but cannot find. $\endgroup$
    – batFINGER
    Commented Mar 29, 2020 at 17:47
  • $\begingroup$ @batFINGER Thank for your reply. So an object's type is decided when it's created with bpy.data.objects.new? And it's decided by what kind of object_data is passed to new...? Even after reading docs.blender.org/api/current/info_overview.html and docs.blender.org/api/current/info_api_reference.html several times I'm still confused. What's the relationships between Object, Datablock, and ID? Is ID just a baseclass of all of other subclasses? $\endgroup$ Commented Mar 29, 2020 at 18:24
  • 1
    $\begingroup$ Yes, yes and yes. All the objects in bpy.data. collections have ID as a base class. eg Object in objects, Mesh in meshes etc. $\endgroup$
    – batFINGER
    Commented Mar 29, 2020 at 18:24
  • $\begingroup$ Ok, thanks a lot. Hopefully I'm starting grasping it! $\endgroup$ Commented Mar 29, 2020 at 18:27
  • $\begingroup$ Re datablock it is how they are stored in blend file .. see blender.stackexchange.com/questions/145906/… .. blendfile.py shows how to read a blendfile datablocks with python outside blender. Blender visualizes them for us. Python API - lets us create, edit, update and destroy them $\endgroup$
    – batFINGER
    Commented Mar 29, 2020 at 18:33

0

You must log in to answer this question.

Browse other questions tagged .