-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
16 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
## generic load datablock from blend | ||
def load_datablocks(self, src, names, type, link=True): | ||
with bpy.data.libraries.load(str(src), link=link) as (data_from, data_to): | ||
setattr(data_to, type, names) | ||
## Generic load datablock from blend (append/link) | ||
|
||
def load_datablocks(src, type, names, link=True): | ||
'''append/link datablock from a blend file | ||
ex: load_datablocks('path/to/file.blend', 'node_groups', ['ng_A', 'ng_B']) | ||
args: | ||
src (str or Path): path to source blend file | ||
type (str): datablock type (types found under bpy.data) | ||
names (list or str): single name or list of names to append/link | ||
link (bool): link if True else Append datablock | ||
''' | ||
|
||
return getattr(data_to, type) | ||
if isinstance(names, str): | ||
names = [names] | ||
with bpy.data.libraries.load(str(src), link=link) as (data_from, data_to): | ||
setattr(data_to, type, [item for item in getattr(data_from, type) if item in names]) | ||
return getattr(data_to, type) |