コード例 #1
0
ファイル: blender.c プロジェクト: HugoLamarche/blender
/**
 * \return Success.
 */
bool BKE_copybuffer_paste(bContext *C, const char *libname, const short flag, ReportList *reports)
{
	Main *bmain = CTX_data_main(C);
	Scene *scene = CTX_data_scene(C);
	View3D *v3d = CTX_wm_view3d(C);
	Main *mainl = NULL;
	Library *lib;
	BlendHandle *bh;
		
	bh = BLO_blendhandle_from_file(libname, reports);
	
	if (bh == NULL) {
		/* error reports will have been made by BLO_blendhandle_from_file() */
		return false;
	}

	BKE_scene_base_deselect_all(scene);
	
	/* tag everything, all untagged data can be made local
	 * its also generally useful to know what is new
	 *
	 * take extra care BKE_main_id_flag_all(bmain, LIB_TAG_PRE_EXISTING, false) is called after! */
	BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
	
	/* here appending/linking starts */
	mainl = BLO_library_link_begin(bmain, &bh, libname);
	
	BLO_library_link_copypaste(mainl, bh);

	BLO_library_link_end(mainl, &bh, flag, scene, v3d);
	
	/* mark all library linked objects to be updated */
	BKE_main_lib_objects_recalc_all(bmain);
	IMB_colormanagement_check_file_config(bmain);
	
	/* append, rather than linking */
	lib = BLI_findstring(&bmain->library, libname, offsetof(Library, filepath));
	BKE_library_make_local(bmain, lib, true, false);
	
	/* important we unset, otherwise these object wont
	 * link into other scenes from this blend file */
	BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
	
	/* recreate dependency graph to include new objects */
	DAG_relations_tag_update(bmain);
	
	BLO_blendhandle_close(bh);
	/* remove library... */
	
	return true;
}
コード例 #2
0
ファイル: blender_copybuffer.c プロジェクト: diekev/blender
bool BKE_copybuffer_read(Main *bmain_dst, const char *libname, ReportList *reports)
{
	BlendHandle *bh = BLO_blendhandle_from_file(libname, reports);
	if (bh == NULL) {
		/* Error reports will have been made by BLO_blendhandle_from_file(). */
		return false;
	}
	/* Here appending/linking starts. */
	Main *mainl = BLO_library_link_begin(bmain_dst, &bh, libname);
	BLO_library_link_copypaste(mainl, bh);
	BLO_library_link_end(mainl, &bh, 0, NULL, NULL);
	/* Mark all library linked objects to be updated. */
	BKE_main_lib_objects_recalc_all(bmain_dst);
	IMB_colormanagement_check_file_config(bmain_dst);
	/* Append, rather than linking. */
	Library *lib = BLI_findstring(&bmain_dst->library, libname, offsetof(Library, filepath));
	BKE_library_make_local(bmain_dst, lib, true, false);
	/* Important we unset, otherwise these object wont
	 * link into other scenes from this blend file.
	 */
	BKE_main_id_tag_all(bmain_dst, LIB_TAG_PRE_EXISTING, false);
	BLO_blendhandle_close(bh);
	return true;
}