0

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?
Lai Yu-Hsuan
  • 1,982
  • 1
  • 12
  • 39
  • 1
    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. – batFINGER Mar 29 '20 at 17:47
  • @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 https://docs.blender.org/api/current/info_overview.html and https://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? – Lai Yu-Hsuan Mar 29 '20 at 18:24
  • 1
    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. – batFINGER Mar 29 '20 at 18:24
  • Ok, thanks a lot. Hopefully I'm starting grasping it! – Lai Yu-Hsuan Mar 29 '20 at 18:27
  • Re datablock it is how they are stored in blend file .. see https://blender.stackexchange.com/questions/145906/manipulating-blend-file-text-blocks-with-blendfile-py-crud .. 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 – batFINGER Mar 29 '20 at 18:33

0 Answers0