Skip to content

Instantly share code, notes, and snippets.

@farcaller
Created April 17, 2022 07:37
Show Gist options
  • Save farcaller/9166ee8fb20389e6357ecf14ff47456d to your computer and use it in GitHub Desktop.
Save farcaller/9166ee8fb20389e6357ecf14ff47456d to your computer and use it in GitHub Desktop.
import bpy, mathutils
WORKSPACE_NAME = 'Sculpting.001'
LEADER_OBJECT = 'Sculpt'
FOLLOWER_OBJECT = 'Empty.001'
SYNC_FREQ = 0.05
# this is bpy.context.screen if you're in the proper workspace. Not when you run this from the Scripting one
screen = bpy.data.workspaces[WORKSPACE_NAME].screens[0]
# the default sculpting layout has a view3d at index 2 and the one pulled from the left would be index 3.
# the better way is to tie this to the tool and use its context? somehow? idk.
area1 = screen.areas.items()[2][1]
area2 = screen.areas.items()[3][1]
def sync():
obj1 = bpy.data.objects[LEADER_OBJECT]
obj2 = bpy.data.objects[FOLLOWER_OBJECT]
area2.spaces.active.region_3d.view_rotation = area1.spaces.active.region_3d.view_rotation
area2.spaces.active.region_3d.view_location = obj2.location + (area1.spaces.active.region_3d.view_location - obj1.location)
area2.spaces.active.region_3d.view_distance = area1.spaces.active.region_3d.view_distance
area2.spaces.active.region_3d.view_perspective = area1.spaces.active.region_3d.view_perspective
global timer_set
if timer_set is not None:
return timer_set
timer_set = SYNC_FREQ
bpy.app.timers.register(sync)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment