Excel to 3D Graph Script
Excel to 3D Graph Script
#
# Python Script To Read Data From An Excel File & Create Animated 3D Bars
#
# This script is originally written by 5 Minutes Blender YouTube channel
#
###########################################################################
import bpy
import math
import pandas as pds
context = bpy.context
scene = context.scene
###########################################################################
###########################################################################
#
# CHANGE THE FOLLOWING INPUT AS PER YOUR EXCEL FILE
# BE CAREFUL - ANY WRONG INPUT WILL RAISE AN ERROR.
excel_file_path = r"C:\Data\Database.xlsx"
data_column = 3
month_column = 2
currency_symbol = "$"
###########################################################################
###########################################################################
anim_start_frame = 2
anim_length_data = 20
graph_start_position = 1
distance_bet_points = 2
normalized_data = []
for data in data_list:
normalized_data.append(data * 10/data_height_mean)
bezier_curve = curve.splines.new('BEZIER')
bezier_curve.bezier_points.add(number_of_data-1)
context.scene.collection.objects.link(curve_path)
curve_path.select_set(True)
context.view_layer.objects.active = curve_path
bpy.ops.object.editmode_toggle()
bpy.ops.curve.select_all(action='SELECT')
bpy.ops.curve.handle_type_set(type='AUTOMATIC')
bpy.ops.object.editmode_toggle()
follow_path = sphere.constraints.new(type='FOLLOW_PATH')
follow_path.target = curve_path
follow_path.forward_axis = 'TRACK_NEGATIVE_Z'
follow_path.up_axis = 'UP_Y'
follow_path.use_fixed_location = True
follow_path.offset_factor = 0.0
follow_path.keyframe_insert("offset_factor", frame=anim_start_frame)
follow_path.offset_factor = 1.0
follow_path.keyframe_insert("offset_factor", frame=anim_end_frame)
fcurves = sphere.animation_data.action.fcurves
for fcurve in fcurves:
for kf in fcurve.keyframe_points:
kf.interpolation = 'LINEAR'
kf.easing = 'AUTO'
bpy.ops.constraint.followpath_path_animate(constraint=follow_path.name)
group_input = geometry_nodes.nodes.new("NodeGroupInput")
group_input.location = (-340.0, 0.0)
group_input.width, group_input.height = 140.0, 100.0
group_output = geometry_nodes.nodes.new("NodeGroupOutput")
group_output.location = (609.8951416015625, 0.0)
group_output.width, group_output.height = 140.0, 100.0
trim_curve = geometry_nodes.nodes.new("GeometryNodeTrimCurve")
trim_curve.location = (-63.592041015625, 22.438913345336914)
trim_curve.width, trim_curve.height = 140.0, 100.0
trim_curve.mode = 'FACTOR'
trim_curve.inputs[1].default_value = True
trim_curve.inputs[2].default_value = 0.0
trim_curve.inputs[3].default_value = 0.0
trim_curve.inputs[3].keyframe_insert('default_value', frame=start_frame)
trim_curve.inputs[3].default_value = 1.0
trim_curve.inputs[3].keyframe_insert('default_value', frame=end_frame)
curve_to_mesh = geometry_nodes.nodes.new("GeometryNodeCurveToMesh")
curve_to_mesh.location = (169.89512634277344, 18.004777908325195)
curve_to_mesh.width, curve_to_mesh.height = 140.0, 100.0
curve_to_mesh.inputs[2].default_value = False
curve_circle = geometry_nodes.nodes.new("GeometryNodeCurvePrimitiveCircle")
curve_circle.location = (-340.7394104003906, -86.51416015625)
curve_circle.width, curve_circle.height = 140.0, 100.0
curve_circle.mode = 'RADIUS'
curve_circle.inputs[0].default_value = 32
curve_circle.inputs[1].default_value = (-1.0, 0.0, 0.0)
curve_circle.inputs[2].default_value = (0.0, 1.0, 0.0)
curve_circle.inputs[3].default_value = (1.0, 0.0, 0.0)
curve_circle.inputs[4].default_value = 0.03
set_material = geometry_nodes.nodes.new("GeometryNodeSetMaterial")
set_material.location = (389.71429443359375, 25.688528060913086)
set_material.width, set_material.height = 140.0, 100.0
set_material.inputs[1].default_value = True
set_material.inputs[2].default_value = material
geometry_nodes.links.new(set_material.outputs[0], group_output.inputs[0])
geometry_nodes.links.new(group_input.outputs[0], trim_curve.inputs[0])
geometry_nodes.links.new(trim_curve.outputs[0], curve_to_mesh.inputs[0])
geometry_nodes.links.new(curve_circle.outputs[0], curve_to_mesh.inputs[1])
geometry_nodes.links.new(curve_to_mesh.outputs[0], set_material.inputs[0])
fcurves = geometry_nodes.animation_data.action.fcurves
for fcurve in fcurves:
for kf in fcurve.keyframe_points:
kf.interpolation = 'LINEAR'
kf.easing = 'AUTO'
return geometry_nodes
text_month = str(month_list[data_counter])
text_data = currency_symbol + str(data_list[data_counter])
ob.location = [graph_start_position+distance_bet_points*data_counter, 0,
display_data[data_counter]+1.5]
ob.rotation_euler = [math.radians(90),0,0]
anim_curr_frame -= anim_length_text
ob.location = [graph_start_position+distance_bet_points*data_counter, 0,
display_data[data_counter]+1]
ob.rotation_euler = [math.radians(90),0,0]
# Clean-up work
# Reset 3D cursor location back to the original
scene.cursor.location.xyz = saved_cursor_loc
context.active_object.select_set(False)