Skip to content

Commit

Permalink
Changes to _base, Page1, Scripts
Browse files Browse the repository at this point in the history
In _base, shortened function name run_script() to script()
Added .py to the script() function, so that calling scripts now requires only their name, and not the file extension:

Old Way:
run_script('KeyframeActive.py')

New Way:
script('KeyframeActive')

Scripts folder has 'KeyframeActive' and 'RotateActive' to facilitate the new 'active item' specific knobs:
ie: the knob will rotate and keyframe a mesh, edge, face, vertex, armature, edit bone, pose bone, curve or bezier point automatically

The old logic always targeted the active object, not any sub items of that object eg bones, vertices, which was not desirable behavior

Page1 was updated to include the new rotation and keyframing functions
  • Loading branch information
SpectralVectors authored Feb 21, 2023
1 parent 30183a0 commit 210ee47
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 12 deletions.
29 changes: 19 additions & 10 deletions Pico/lib/BoardSetup/Pages/Page1.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def Page1_Button3():
# Button 4
Page1_Button4_Name = 'Cycle Edit Mode'
def Page1_Button4():
run_script('CycleEditModes.py')
script('CycleEditModes')
print('Page 1 Button 4')
wait(0.1)

Expand Down Expand Up @@ -81,45 +81,54 @@ def Page1_Button9():
# Rotary 1
Page1_Rotary1_Left_Name = 'Rotate X +5'
def Page1_Rotary1_Left():
command('bpy.ops.transform.rotate(value=0.08726646, constraint_axis=(True,False,False))')
command('bmp=bpy.context.scene.bmp;bmp.Direction=1;bmp.Axis=0')
script('RotateActive')
print('Page 1 Rotary 1 Left')

Page1_Rotary1_Right_Name = 'Rotate X -5'
def Page1_Rotary1_Right():
command('bpy.ops.transform.rotate(value=-0.08726646, constraint_axis=(True,False,False))')
command('bmp=bpy.context.scene.bmp;bmp.Direction=-1;bmp.Axis=0')
script('RotateActive')
print('Page 1 Rotary 1 Right')

Page1_Rotary1_Button_Name = 'Keyframe Rotation X'
def Page1_Rotary1_Button():
command("bpy.context.object.keyframe_insert(data_path='rotation_euler', index=0, frame=bpy.data.scenes['Scene'].frame_current)")
command("bmp=bpy.context.scene.bmp;bmp.Axis=0")
script('KeyframeActive')

# Rotary 2
Page1_Rotary2_Left_Name = 'Rotate Y +5'
def Page1_Rotary2_Left():
command('bpy.ops.transform.rotate(value=0.08726646, constraint_axis=(False,True,False))')
command('bmp=bpy.context.scene.bmp;bmp.Direction=1;bmp.Axis=1')
script('RotateActive')
print('Page 1 Rotary 2 Left')

Page1_Rotary2_Right_Name = 'Rotate Y -5'
def Page1_Rotary2_Right():
command('bpy.ops.transform.rotate(value=-0.08726646, constraint_axis=(False,True,False))')
command('bmp=bpy.context.scene.bmp;bmp.Direction=-1;bmp.Axis=1')
script('RotateActive')
print('Page 1 Rotary 2 Right')

Page1_Rotary2_Button_Name = 'Keyframe Rotation Y'
def Page1_Rotary2_Button():
command("bpy.context.object.keyframe_insert(data_path='rotation_euler', index=1, frame=bpy.data.scenes['Scene'].frame_current)")
command("bmp=bpy.context.scene.bmp;bmp.Axis=1")
script('KeyframeActive')

# Rotary 3
Page1_Rotary3_Left_Name = 'Rotate Z +5'
def Page1_Rotary3_Left():
command('bpy.ops.transform.rotate(value=0.08726646, constraint_axis=(False,False,True))')
command('bmp=bpy.context.scene.bmp;bmp.Direction=1;bmp.Axis=2')
script('RotateActive')
print('Page 1 Rotary 3 Left')

Page1_Rotary3_Right_Name = 'Rotate Z -5'
def Page1_Rotary3_Right():
command('bpy.ops.transform.rotate(value=-0.08726646, constraint_axis=(False,False,True))')
command('bmp=bpy.context.scene.bmp;bmp.Direction=-1;bmp.Axis=2')
script('RotateActive')
print('Page 1 Rotary 3 Right')

Page1_Rotary3_Button_Name = 'Keyframe Rotation Z'
def Page1_Rotary3_Button():
command("bpy.context.object.keyframe_insert(data_path='rotation_euler', index=2, frame=bpy.data.scenes['Scene'].frame_current)")
command("bmp=bpy.context.scene.bmp;bmp.Axis=2")
script('KeyframeActive')

4 changes: 2 additions & 2 deletions Pico/lib/BoardSetup/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def command(command):
print(f"import bpy;{command};bpy.context.object.hide_render=bpy.context.object.hide_render")

# Helper function to make running scripts only a single line
def run_script(script):
def script(script):
kb.send(shift,ctrl,alt,insert)
wait(0.1)
print(f"exec(open('{drive}{path}{script}').read())")
print(f"exec(open('{drive}{path}{script}.py').read())")
40 changes: 40 additions & 0 deletions Pico/lib/Scripts/KeyframeActive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import bpy

context = bpy.context
bmp = context.scene.bmp
mode = context.mode
object = context.object
type = object.type
data = object.data

axis = bmp.Axis

if type == 'MESH':
if mode == 'EDIT_MESH':
bpy.ops.addon.messagebox('INVOKE_DEFAULT', Message='You cannot keyframe mesh data!')
else:
object.keyframe_insert(data_path='rotation_euler', index=axis)

elif type == 'ARMATURE':
if mode == 'POSE':
bone = context.selected_pose_bones[0]
bone.rotation_mode = 'XYZ'
bone.keyframe_insert(data_path='rotation_euler', index=axis)

elif mode == 'EDIT_ARMATURE':
bpy.ops.addon.messagebox('INVOKE_DEFAULT', Message='You cannot keyframe edit bones!')

else:
object.keyframe_insert(data_path='rotation_euler', index=axis)

elif type == 'CURVE':
if mode == 'EDIT_CURVE':
bpy.ops.addon.messagebox('INVOKE_DEFAULT', Message='You cannot keyframe bezier points!')

else:
object.keyframe_insert(data_path='rotation_euler', index=axis)

else:
object.keyframe_insert(data_path='rotation_euler', index=axis)

object.hide_render = object.hide_render
46 changes: 46 additions & 0 deletions Pico/lib/Scripts/RotateActive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import bpy

context = bpy.context
bmp = context.scene.bmp
mode = context.mode
object = context.object
type = object.type
data = object.data

direction = bmp.Direction
value = bmp.Value
axis = bmp.Axis

_axis = {
'0':(True,False,False),
'1':(False,True,False),
'2':(False,False,True),
}

if type == 'MESH':
if mode == 'EDIT_MESH':
bpy.ops.transform.rotate(value=value*direction, constraint_axis=_axis[str(axis)])
else:
object.rotation_euler[axis] += value*direction

elif type == 'ARMATURE':
if mode == 'POSE':
bone = context.selected_pose_bones[0]
bone.rotation_mode = 'XYZ'
bone.rotation_euler[axis] += value*direction

elif mode == 'EDIT_ARMATURE':
bpy.ops.transform.rotate(value=value*direction, constraint_axis=_axis[str(axis)])

else:
object.rotation_euler[axis] += value*direction

elif type == 'CURVE':
if mode == 'EDIT_CURVE':
bpy.ops.transform.rotate(value=value*direction, constraint_axis=_axis[str(axis)])

else:
object.rotation_euler[axis] += value*direction

else:
object.rotation_euler[axis] += value*direction

0 comments on commit 210ee47

Please # to comment.