-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjson_functions.py
More file actions
67 lines (45 loc) · 1.79 KB
/
Copy pathjson_functions.py
File metadata and controls
67 lines (45 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import json
import bpy
# read json
def read_json(filepath):
with open(filepath, "r") as read_file:
dataset = json.load(read_file)
return dataset
# create json file
def create_json_file(datas, path) :
with open(path, "w") as write_file :
json.dump(datas, write_file, indent=4, sort_keys=False)
# set attributes from json
def set_properties_from_dataset(datasetin, datasetout, avoid_list):
for prop in datasetin:
chk_avoid = False
for a in avoid_list:
if a in prop:
chk_avoid = True
if not chk_avoid:
setattr(datasetout, '%s' % prop, datasetin[prop])
# load json in collection
def load_json_in_collection(dataset, collection, json_coll_name):
# remove existing in collection
collection.clear()
for f in dataset[json_coll_name]:
new = collection.add()
if isinstance(f, str):
new.name = f
else:
set_properties_from_dataset(f, new, ())
return dataset
# set up nodetrees collection from json file
def set_nodetrees_from_json(dataset):
winman = bpy.data.window_managers[0]
nodetrees_coll = winman.an_templates_nodetrees
load_json_in_collection(dataset, nodetrees_coll, 'nodetrees')
# set up properties collection from json file
def set_properties_from_json(dataset):
winman = bpy.data.window_managers[0]
properties_coll = winman.an_templates_properties
load_json_in_collection(dataset, properties_coll.blender_versions, 'blender_versions')
load_json_in_collection(dataset, properties_coll.an_versions, 'an_versions')
load_json_in_collection(dataset, properties_coll.categories, 'categories')
load_json_in_collection(dataset, properties_coll.tags, 'tags')
properties_coll.manifest_hash = dataset["manifest_hash"]