Script to append obj from blend file not working!


import bpy
import os

# "//" prefix is a Blender specific identifier for the current blend file
#filepath = "//link_library.blend"
#abs_filepath = bpy.path.abspath(filepath) # returns the absolute path

# os.path.abspath(__file__) returns path to the script

filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "blenderfile1.blend")

print ('filepath = ' , filepath  )

# link all objects starting with 'Cube'

with bpy.data.libraries.load( filepath , link = False) as (data_from, data_to):
    data_to.objects = [name for name in data_from.objects if name.startswith("Cube")]

# link object to scene collection

for obj in data_to.objects:
    if obj is not None:
       bpy.context.collection.objects.link(obj)


#####


class MY_OT_custom_append(bpy.types.Operator):

    blend = StringProperty(name="Library Blend File")
    object_name = StringProperty(name="Object Name")


 # On a panel
class MY_PT_custom_panel(Panel):

    row = layout.row()
    props = row.operator(MY_OT_custom_append.bl_idname)
    props.blend = "link_library.blend"
    props.object_name = "Cube"



# Test call
bpy.ops.scene.custom_append(blend="link_library.blend", object_name="Cube")




i tried to make this script in 2.79 but get an error on the file path!

can some one help to correct this script

and can this work in 2.8 too or need to be modified ?

thanks
happy bl

Yes you havn’t made the execution function of your class “MY_OT_custom_append”, it’s normal!
YOUR CLASS DON’T MAKE SOMETHING !

panel - i know not really using it for now

i found another way to bring object in new file
but it is linked or as a proxy object in 2.79

in 2.8 it is appended

don’t know why so many changes in API
hard to follow all changes !

will try to continue to advance on the 2.8 version
but now need to copy data to another object with same name

thanks
happy bl