Blender V5.3
readfile_tempload.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8#include "BLO_readfile.hh"
9
10#include "MEM_guardedalloc.h"
11
12#include "BKE_main.hh"
13
14#include "DNA_ID.h"
15
16namespace blender {
17
19 const char *blend_file_path,
20 const short idcode,
21 const char *idname,
22 ReportList *reports)
23{
25 temp_lib_ctx->bmain_base = BKE_main_new();
26 temp_lib_ctx->bf_reports.reports = reports;
27
28 /* Copy the file path and color-space so any remapping is performed properly. */
29 BKE_main_init_from_reference(*temp_lib_ctx->bmain_base, *real_main);
30
31 BlendHandle *blendhandle = BLO_blendhandle_from_file(blend_file_path, &temp_lib_ctx->bf_reports);
32
33 LibraryLink_Params lib_link_params;
34 BLO_library_link_params_init(&lib_link_params, temp_lib_ctx->bmain_base, 0, ID_TAG_TEMP_MAIN);
35
36 Main *bmain_lib = BLO_library_link_begin(&blendhandle, blend_file_path, &lib_link_params);
37
39 bmain_lib, &blendhandle, idcode, idname, &lib_link_params);
40
41 BLO_library_link_end(bmain_lib, &blendhandle, &lib_link_params, reports);
42 BLO_blendhandle_close(blendhandle);
43
44 return temp_lib_ctx;
45}
46
48{
49 BKE_main_free(temp_lib_ctx->bmain_base);
50 MEM_delete(temp_lib_ctx);
51}
52
53} // namespace blender
external readfile function prototypes.
ID and Library types, which are fundamental for SDNA.
Read Blender memory allocation and freeing.
BMesh Iterators.
BlendHandle * BLO_blendhandle_from_file(const char *filepath, BlendFileReadReport *reports)
void BLO_blendhandle_close(BlendHandle *bh) ATTR_NONNULL(1)
Main * BKE_main_new()
Definition main.cc:93
void BKE_main_init_from_reference(Main &bmain, const Main &reference)
Definition main.cc:100
ID * BLO_library_link_named_part(Main *mainl, BlendHandle **bh, short idcode, const char *name, const LibraryLink_Params *params)
Definition readfile.cc:5679
void BLO_library_link_params_init(LibraryLink_Params *params, Main *bmain, int flag, int id_tag_extra)
Definition readfile.cc:5747
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BLO_library_link_end(Main *mainl, BlendHandle **bh, const LibraryLink_Params *params, ReportList *reports)
Definition readfile.cc:5935
void BLO_library_temp_free(TempLibraryContext *temp_lib_ctx)
Main * BLO_library_link_begin(BlendHandle **bh, const char *filepath, const LibraryLink_Params *params)
Definition readfile.cc:5775
void BKE_main_free(Main *bmain)
Definition main.cc:202
@ ID_TAG_TEMP_MAIN
Definition DNA_ID.h:974
TempLibraryContext * BLO_library_temp_load_id(Main *real_main, const char *blend_file_path, short idcode, const char *idname, ReportList *reports)
BlendFileReadReport bf_reports