Offset Key

Discussions concerning programming of SOFTIMAGE©
Post Reply
User avatar
Boris
Posts: 67
Joined: 25 May 2012, 16:35
Location: R&M

Offset Key

Post by Boris » 08 Aug 2012, 14:01

Hello Guys ! Yesterday I have found a script for animation and it doesn't work , who can help to fix it? i have received an error # ERROR : invalid syntax - [line 24] -- if fc.GetMinKeyFrame() maxFrame:

Code: Select all

from win32com.client import Dispatch as d

xsi = Application
ks = xsi.GetKeyboardState()

def getCollections(item):
    for param in item.Kinematics.Local.Parameters:
        if param.Keyable:
            collParams.AddItems(param)
            if param.Source:
                collFCurves.AddItems(param.Source)
            
    for property in item.Properties:
        if property.Type == "customparamset":
            for param in property.Parameters:
                if param.Keyable:
                    collParams.AddItems(param)
                    if param.Source:
                        collFCurves.AddItems(param.Source)

def getMinFrame(collFCurves, current):
    minFrame = current
    for fc in collFCurves:
        if fc.GetMinKeyFrame()  maxFrame:
            maxFrame = fc.GetMaxKeyFrame()
    return maxFrame

# Execute                        
if ks(1) != 4:
    collParams = d( "XSI.Collection" )
    collFCurves = d( "XSI.Collection" )
    current = xsi.GetValue("PlayControl.Current")
    sel = tuple(xsi.Selection)
    for item in sel:
        getCollections(item)

    # Move Left 1 frame
    if ks(1) == 2:
        offset = -1
        startFrame = getMinFrame(collFCurves, current)
        endFrame = current
    # Move Left Input frames            
    elif ks(1) == 3:
        offset = -1*float(xsi.XSIInputBox("Number of frames?", "Negative Offset", "3"))
        startFrame = getMinFrame(collFCurves, current)
        endFrame = current
    # Move Right Input frames        
    elif ks(1) == 1:
        offset = float(xsi.XSIInputBox("Number of frames?", "Positive Offset", "3"))
        startFrame = current
        endFrame = getMaxFrame(collFCurves, current)
    # Move Right 1 frame
    else:
        offset = 1
        startFrame = current
        endFrame = getMaxFrame(collFCurves, current)
        
    params = collParams.GetAsText()
    xsi.ScaleAndOffset(params, "siInputParameters", offset, "", startFrame, endFrame, 0, False, "siFCurvesAnimationSources", True, "", False)

# Alt Menu    
else:
    XSIUIToolkit.MsgBox( '''=============================================


=============================================

Notes about this tool:

pmOffsetKeys allows you to quickly move the keys in one direction or another using the current frame as a starting point

=============================================

Instructions:

Select your animated objects
Run the script:
Default:        Offset by 1 frame to the right
Crtl:        Offset by 1 frame to the left
Shift:        User input offset to the right
Shift+Ctrl:        User input offset to the left

=============================================
''', 0, "pmOffsetKeys Info" )
Last edited by Boris on 06 Jan 2015, 10:26, edited 2 times in total.
Oops ,something went wrong :D

User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

Re: Offset Key

Post by Hirazi Blue » 08 Aug 2012, 16:01

Don't know if that's the root of the problem, but there is something missing in this line

Code: Select all

if fc.GetMinKeyFrame() maxFrame:
The "if" statements expects an condition, but there is no operator (like "==","<", ">" or maybe "in"???)
between the "fc.GetMinKeyFrame()" and "maxFrame".

BTW: using our special CODE tags makes posts with code somewhat easier to read... :ymdaydream:
Stay safe, sane & healthy!

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: Offset Key

Post by rray » 08 Aug 2012, 16:27

It looks like there's a whole block of code missing. There's probably a "<" and a ">" in there which the code parser of the website where this was copied from (http://philmelancon.wordpress.com/) interpreted as a tag ... my best guess is:

Code: Select all

def getMinFrame(collFCurves, current):
	minFrame = current
	for fc in collFCurves:
		if fc.GetMinKeyFrame() < minFrame:
			minFrame = fc.GetMinKeyFrame()
	return minFrame

def getMaxFrame(collFCurves, current):
	maxFrame = current
	for fc in collFCurves:
		if fc.GetMaxKeyFrame() > maxFrame:
			maxFrame = fc.GetMaxKeyFrame()
	return maxFrame
softimage resources section updated Jan 5th 2024

User avatar
Boris
Posts: 67
Joined: 25 May 2012, 16:35
Location: R&M

Re: Offset Key

Post by Boris » 08 Aug 2012, 16:54

rray wrote:It looks like there's a whole block of code missing. There's probably a "<" and a ">" in there which the code parser of the website where this was copied from (http://philmelancon.wordpress.com/) interpreted as a tag ... my best guess is:

Code: Select all

def getMinFrame(collFCurves, current):
	minFrame = current
	for fc in collFCurves:
		if fc.GetMinKeyFrame() < minFrame:
			minFrame = fc.GetMinKeyFrame()
	return minFrame

def getMaxFrame(collFCurves, current):
	maxFrame = current
	for fc in collFCurves:
		if fc.GetMaxKeyFrame() > maxFrame:
			maxFrame = fc.GetMaxKeyFrame()
	return maxFrame
oh my god :) Now I know where I have seen it . Thank you Guys for participation!
Oops ,something went wrong :D

User avatar
thecook
Posts: 22
Joined: 19 Nov 2009, 15:33

Re: Offset Key

Post by thecook » 05 Jan 2015, 20:17

hey guys
finding this script, i wonder if there is some other scripts where i can give an individual offset on each selected object.
eg,
obj_1 starts frame 1
obj_2 starts frame 10
obj_3 starts frame 20
...

for a start i found this on the as usual brilliant caffein abuse:
http://caffeineabuse.blogspot.ch/2008/1 ... -time.html

but this works with expressions.

i need to "physically" offset my srt fcurves on 2500 objects...
anyone has a help here?

Newcomer (<20 posts) alert: please use the URL tags - HB

User avatar
Hirazi Blue
Administrator
Posts: 5107
Joined: 04 Jun 2009, 12:15

Re: Offset Key

Post by Hirazi Blue » 06 Jan 2015, 00:07

Is there a specific reason why you don't want to use a similar method to the one caffeinabuse describes?
Stay safe, sane & healthy!

User avatar
thecook
Posts: 22
Joined: 19 Nov 2009, 15:33

Re: Offset Key

Post by thecook » 06 Jan 2015, 00:16

Hirazi Blue wrote:Is there a specific reason why you don't want to use a similar method to the one caffeinabuse describes?
cause i do have fcurves already on all objects.
now i need to offset them.

and this is the script that does it:
http://www.xsiforum.de/thread.php?threa ... ion+offset

i think rather handy.
thanks to PPanther and Helli.

mantom
Posts: 10
Joined: 21 Nov 2014, 07:55

Re: Offset Key

Post by mantom » 07 Jan 2015, 01:23

Why don't you use the HLE mode in the animation editor and offset your FCurves in bulk?

You can also put all your FCurves into mixer source(s) and apply offset map(s).

User avatar
thecook
Posts: 22
Joined: 19 Nov 2009, 15:33

Re: Offset Key

Post by thecook » 07 Jan 2015, 11:09

guys, i probably did not explain this properly.
this is what i'm talking.

i know how to offset fcurves manually.
and now this script applies it on my 1500 animated objects.

i use this alot for MoGraph an stuff.
Attachments
fcurve_offset.JPG

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests