Open Scripting ↓ Name it like ~ .py ↓ Write code and press execute button
Go to animation and press the play button
In 3Dviewport, press N ↓ Right-click at the key insertion point (green) ↓ Press clear key frame ↓ Press the N key to close the tab
Press the Text button ↓ Press the New button ↓ Name it like ~ .py
Press the button with a pattern like a document ↓ Select a script
bpy.ops.mesh. ~~~ _add ()
. Of course, you can choose from shift + A and add it.anim01.py
import bpy
#Specify the coordinates of the target
positions = (0,3,2),(4,1,6),(3,-5,1),(3,10,1),(1,8,1)
#Specify the starting coordinates
start_pos = (0,0,0)
#Assign the object in the 3D viewport to the variable ob
#ob = bpy.data.objects["Cube"]It is also possible to move a specific thing like
ob = bpy.context.object
#Specify the start frame
frame_num = 0
#Repeat the process of moving to the target coordinates
for p in positions:
#Set the start frame
bpy.context.scene.frame_set(frame_num)
#Substitute the target coordinate value for the variable location
ob.location = p
#Insert keyframe
ob.keyframe_insert(data_path = "location",index = -1)
#Shift the frame by 20
frame_num += 20
○Point : keyframe_insert A function that inserts keyframes. For the argument, use the information to be used (data_path), array format (index), etc. index is
-1 → x, y, z all 0 → x 1 → y 2 → z
It is also possible to operate with reference to a specific axis.
anim02.py
import bpy
#Use the randint function in a random library
from random import randint
#Use objects in 3D viewport(This time Sphere)
ob = bpy.data.objects["Sphere"]
frame_number = 0
#Repeat the process 50 times
for i in range(0,50):
#Randomly select an integer from the range from the first argument to the second argument
x = randint(-20,20)
y = randint(-40,20)
z = randint(-20,60)
bpy.context.scene.frame_set(frame_number)
ob.location = (x,y,z)
ob.keyframe_insert(data_path = "location",index = -1)
frame_number += 5
anim03.py
import bpy
#Prepare the sin function of the math library
from math import sin
start_pos = (0,0,0)
ob = bpy.context.object
frame_num = 0
for i in range(0,50):
bpy.context.scene.frame_set(frame_num)
#Specify the coordinates in the variable location
ob.location = (0,i,sin(i))
ob.keyframe_insert(data_path = "location",index = -1)
frame_num += 10
anim04.py
import bpy
scales = (1,3,2),(4,1,6),(3,5,1),(3,10,1),(1,8,1)
start_pos = (0,0,0)
ob = bpy.context.object
frame_num = 0
for s in scales:
bpy.context.scene.frame_set(frame_num)
ob.scale = s
#Insert the key based on the size information
ob.keyframe_insert(data_path = "scale",index = -1)
frame_num += 20
anim05.py
import bpy
from math import sin
start_pos = (0,0,0)
ob = bpy.context.object
frame_num = 0
for i in range(0,100):
bpy.context.scene.frame_set(frame_num)
ob.location = (0,-i,sin(i) * 3)
ob.scale = (1,1,1 + sin(i))
ob.keyframe_insert(data_path = "location",index = -1)
ob.keyframe_insert(data_path = "scale",index = -1)
frame_num += 5
Thank you for reading. Please feel free to contact us if you have any corrections!
Recommended Posts