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