Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/json_reader.py
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/a550820353f47112f713 to your computer and use it in GitHub Desktop.
Save zeffii/a550820353f47112f713 to your computer and use it in GitHub Desktop.
import bpy
import json
def sv_main(scale=75.0, verticals=0.005):
verts_out = []
edges_out = []
in_sockets = [
['s', 'scale', scale],
['s', 'verticals', verticals]
]
out_sockets = [
['v', 'verts', [verts_out]],
['s', 'edges', [edges_out]]
]
text_obj = bpy.data.texts['multifile.json']
text_str = text_obj.as_string()
print(text_str)
nodes_json = json.loads(text_str)
graphs = nodes_json['graphs']
z_jump = 0
v_idx = 0
prime_start = graphs['0']['items']['0']['start']
for graph_key in sorted(graphs.keys()):
for idx in sorted(graphs[graph_key]['items']):
f = graphs[graph_key]['items'][idx]
print(f)
v1 = [(f['start'] - prime_start), 0, z_jump]
v2 = [(v1[0] + f['duration']), 0, z_jump]
v1[0] *= scale
v2[0] *= scale
z_jump -= verticals
verts_out.extend([v1, v2])
edges_out.append([v_idx, v_idx+1])
v_idx += 2
z_jump -= (verticals * 3)
return in_sockets, out_sockets
{
"graphs": {
"0": {
"items": {
"0": {
"bl_idname": "SvGenFloatRange",
"duration": 0.00010203810819531256,
"name": "Float Series",
"start": 2.624644403129448
},
"1": {
"bl_idname": "ScalarMathNode",
"duration": 0.00022125717095322628,
"name": "function",
"start": 2.6247534253655145
},
"2": {
"bl_idname": "ScalarMathNode",
"duration": 0.00018102859441659902,
"name": "function.001",
"start": 2.624980758727715
},
"3": {
"bl_idname": "GenVectorsNode",
"duration": 0.00013528255686123813,
"name": "Vectors in",
"start": 2.625167514306986
},
"4": {
"bl_idname": "ViewerNode2",
"duration": 0.00014540954227415526,
"name": "Viewer Draw2",
"start": 2.625308942896374
}
},
"name": "NodeTree"
},
"1": {
"items": {
"0": {
"bl_idname": "SvGenFloatRange",
"duration": 6.53714368725744e-05,
"name": "Float Series",
"start": 2.6261603779251272
},
"1": {
"bl_idname": "GenVectorsNode",
"duration": 8.5695248977391e-05,
"name": "Vectors in",
"start": 2.6262328033311495
},
"2": {
"bl_idname": "MatrixGenNode",
"duration": 0.00015867938522928782,
"name": "Matrix in",
"start": 2.6263248541364894
},
"3": {
"bl_idname": "GenListRangeIntNode",
"duration": 5.838730900142863e-05,
"name": "List Range Int",
"start": 2.626488981141458
},
"4": {
"bl_idname": "SvCircleNode",
"duration": 0.00030716194376667616,
"name": "Circle",
"start": 2.6265529557527563
},
"5": {
"bl_idname": "ViewerNode2",
"duration": 0.00025282542893023674,
"name": "Viewer Draw2",
"start": 2.626866543094164
}
},
"name": "NodeTree.001"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment