-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
op_create_nodetree_info.py
114 lines (85 loc) · 3.9 KB
/
op_create_nodetree_info.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import bpy
import os
from .json_functions import create_json_file
from .op_create_manifest import generate_hash
from .print_functions import print_and_report
# draw nodetree info properties
def draw_nodetree_info_properties(prop_container, layout, tags_coll):
layout.prop(prop_container, "name")
layout.prop(prop_container, "description")
layout.prop(prop_container, "blender_version")
layout.prop(prop_container, "an_version")
layout.prop(prop_container, "image_preview_url")
layout.prop(prop_container, "video_preview_url")
layout.prop(prop_container, "file_url")
layout.prop(prop_container, "readme_url")
layout.prop(prop_container, "tags")
col = layout.column(align=True)
col.label(text="Existing Tags : ")
limit = 3
ct = 0
tag_reformat = ""
for tag in tags_coll:
tag_reformat += tag.name
ct += 1
if ct == limit:
col.label(text=tag_reformat)
tag_reformat = ""
ct = 0
else:
tag_reformat += ", "
if ct != 0:
tag_reformat = tag_reformat[:-2]
col.label(text=tag_reformat)
class ANTEMPLATES_OT_create_nodetree_info(bpy.types.Operator):
"""Create Nodetree Info File"""
bl_idname = "antemplates.create_nodetree_info"
bl_label = "Create Nodetree Info"
bl_options = {'REGISTER', 'INTERNAL'}
name : bpy.props.StringProperty(name="Name")
description : bpy.props.StringProperty(name="Description")
blender_version : bpy.props.StringProperty(name="Blender Version")
an_version : bpy.props.StringProperty(name="AN Version")
tags : bpy.props.StringProperty(name="Tags")
image_preview_url : bpy.props.StringProperty(name="Image Preview URL")
video_preview_url : bpy.props.StringProperty(name="Video Preview URL")
file_url : bpy.props.StringProperty(name="File URL")
readme_url : bpy.props.StringProperty(name="Readme URL")
@classmethod
def poll(cls, context):
winman = bpy.data.window_managers[0]
properties_coll = winman.an_templates_properties
if properties_coll.output_nodetree_info_file != "":
return not os.path.isdir(bpy.path.abspath(properties_coll.output_nodetree_info_file))
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
draw_nodetree_info_properties(self, self.layout, context.window_manager.an_templates_properties.tags)
def execute(self, context):
winman = context.window_manager
properties_coll = winman.an_templates_properties
# check and correct output path
json_path = bpy.path.abspath(properties_coll.output_nodetree_info_file)
if not os.path.isdir(os.path.dirname(json_path)):
print_and_report(self, "Incorrect Output Path", "WARNING")
return {'FINISHED'}
if not json_path.endswith(".json"):
properties_coll.output_nodetree_info_file += ".json"
json_path += ".json"
# create dataset
datas = {}
datas["name"] = self.name
datas["description"] = self.description
datas["blender_version"] = self.blender_version
datas["an_version"] = self.an_version
datas["tags"] = self.tags
datas["image_preview_url"] = self.image_preview_url
datas["video_preview_url"] = self.video_preview_url
datas["file_url"] = self.file_url
datas["readme_url"] = self.readme_url
datas["hash"] = generate_hash(10)
print_and_report(None, "Creating Nodetree Info File", "INFO") #debug
#print(datas) #debug
create_json_file(datas, json_path)
print_and_report(self, "Nodetree Info File Successfully Created", "INFO") #debug
return {'FINISHED'}