Blender V5.0
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 "BLI_string.h"
13
14#include "BKE_main.hh"
15
16#include "DNA_ID.h"
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 so any path remapping is performed properly. */
29 STRNCPY(temp_lib_ctx->bmain_base->filepath, real_main->filepath);
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_freeN(temp_lib_ctx);
51}
Main * BKE_main_new()
Definition main.cc:89
void BKE_main_free(Main *bmain)
Definition main.cc:192
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:693
external readfile function prototypes.
void BLO_library_link_params_init(LibraryLink_Params *params, Main *bmain, int flag, int id_tag_extra)
Definition readfile.cc:5105
void BLO_library_link_end(Main *mainl, BlendHandle **bh, const LibraryLink_Params *params, ReportList *reports)
Definition readfile.cc:5293
BlendHandle * BLO_blendhandle_from_file(const char *filepath, BlendFileReadReport *reports)
void BLO_blendhandle_close(BlendHandle *bh) ATTR_NONNULL(1)
ID * BLO_library_link_named_part(Main *mainl, BlendHandle **bh, short idcode, const char *name, const LibraryLink_Params *params)
Definition readfile.cc:5037
Main * BLO_library_link_begin(BlendHandle **bh, const char *filepath, const LibraryLink_Params *params)
Definition readfile.cc:5133
ID and Library types, which are fundamental for SDNA.
@ ID_TAG_TEMP_MAIN
Definition DNA_ID.h:971
Read Guarded memory(de)allocation.
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
void BLO_library_temp_free(TempLibraryContext *temp_lib_ctx)
TempLibraryContext * BLO_library_temp_load_id(Main *real_main, const char *blend_file_path, const short idcode, const char *idname, ReportList *reports)
char filepath[1024]
Definition BKE_main.hh:179
BlendFileReadReport bf_reports