My current code looks like this:
context = bpy.context.copy()
bpy.context.scene.transform_orientation_slots[0].type = 'GLOBAL' #This has to be kept at global otherwise the parts won't come in at the insertion direction
bpy.context.scene.tool_settings.use_snap = True
bpy.context.scene.tool_settings.use_snap_align_rotation = False
# Iterate through the areas
for area in bpy.context.screen.areas:
if area.type in ('VIEW_3D'):
old_area = area.type
area.type = 'FILE_BROWSER'
area.ui_type = 'ASSETS'
bpy.context.space_data.params.asset_library_ref = 'Assets Library'
bpy.context.space_data.params.import_type = 'APPEND'
context['area'] = area
bpy.ops.screen.area_dupli(context, 'INVOKE_DEFAULT')
area.type = old_area
return {'FINISHED'}
So when I make this as a button operator, the first time I press it, it just turns the 3D viewport into the asset manager and throws an error from the bpy.context.space lines saying:
AttributeError: 'NoneType' object has no attribute 'asset_library_ref'
But if I just change it back to the 3D viewport and press it again, it works? I'm curious why it won't work on the first press. I can't seem to find any other way to set the correct asset library or set it to append.