Appending cameras to scene

Hello

I’m struggling a little with a task of appending cameras to scene from A to B. > Code

        link = False     
        newCameras = []
     
        print("Adding new cams")
        with bpy.data.libraries.load(path, link=link) as (data_from, data_to):
            for camera in data_from.cameras:
                newCameras.append(camera)
            data_to.cameras = newCameras
        print(newCameras)
        for camera in newCameras:
            bpy.context.scene.collection.objects.link(camera)

I get:

    bpy.context.scene.collection.objects.link(camera)
TypeError: CollectionObjects.link(): error with argument 1, "object" -  Function.object expected a Object type, not Camera

Any help would be great.
Thanks !

In Blender camera’s meshes, lights etc are object-data, not objects you can link to a collection.

You’ll need to either create a new camera object and link the camera to it or link in the camera objects (which will load the camera data too).

Hello

Yeah thanks, it was quite “fun” issue… I’m still confused by some decisions of blender api but o well… here is working code>

        newCameras = []
        camNames = []
        with bpy.data.libraries.load(path, link=link) as (data_from, data_to):
            for camera in data_from.cameras:
                camNames.append(camera)
            for cameraName in data_from.objects:
                if cameraName in camNames:
                    newCameras.append(cameraName)

            data_to.cameras = camNames
            data_to.objects = newCameras

        for cam in newCameras:
            bpy.context.scene.collection.objects.link(cam)