Follow Object

Follow object

GUI

Usage

1
2
3
4
5
6
7
step1. Select your A_object

step2. Check the B_object you want to follow

step3. Check your time range

step4. Apply

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#~~ IMPORT - Area ~~#

import maya.cmds as cmds
import maya.mel as mel

#~~ End of IMPORT Area ~~#

#~~ Script - Area ~~#

WindowWinUi="TargetFollow" #Here must to add ' and ' to be 'xxxxxxxx'

def zarmWppsWinExe(*args):
if cmds.window(WindowWinUi, exists = True):
cmds.deleteUI(WindowWinUi)



def Doit():
stime = cmds.intField( 'startTimeField', q=1, v=1 )
etime = cmds.intField( 'endTimeField', q=1, v=1 ) + 1
time = stime
sel = cmds.ls(sl = True)
for i in range(stime,etime):
cmds.currentTime(i)
cmds.xform( sel[0],ws=1, m=cmds.xform(sel[1],q=1,ws=1,m=1) )
cmds.setKeyframe(sel[0])

#~~ End of Script Area ~~#q

#~~ UI - Area ~~#
zarmWppsWinExe()

cmds.window(WindowWinUi,bgc=(0.5,0.5,0.5) )

#~~ Contents ~~#

cmds.columnLayout("A")

cmds.rowColumnLayout(p="A",nc=1,cw=[(1,100)])

cmds.text( label='Target Object:')

cmds.separator ( h=5, style='none')

cmds.button(l="Apply",bgc=(0.5,0.8,0.5), command=('Doit()'))

cmds.separator ( h=5, style='none')

cmds.text( label='Time Range:')

cmds.rowColumnLayout(p="A",nc=3,cw=[(1,100),(2,100)])

cmds.intField('startTimeField', v=cmds.playbackOptions( q=1, min=1))

cmds.intField('endTimeField', v=cmds.playbackOptions( q=1, max=1 ))


#~~ Contents ~~#

cmds.showWindow(WindowWinUi)
cmds.window(WindowWinUi,e=1,wh=(204,102),s=1 )
cmds.window(WindowWinUi,q=1,wh=1)

Follow Object
https://stonetein.github.io/codeArt-TechBlog/2024/06/29/Follow_object/
Author
Stone
Posted on
June 29, 2024
Licensed under