Fcurve selection callback

Fcurve selection callback

petecmartin
Advocate Advocate
9,119 Views
11 Replies
Message 1 of 12

Fcurve selection callback

petecmartin
Advocate
Advocate

Hi,  Is it possible to get a callback/synchronaziation event when selecting several frames in a fcurve?

For example, If i selected frames 3 to 10 in the lcl X translation curve, I could return a list of frames and fcurve values?

I'd even settle for a list of the seleted frames!

Ultimate goal is once an oblect is selected and I select my frame range, the script can at least tell me the frame range of the selected keys on the curve.  Maybe a synchronization event is better?  Although i've tried a crude one of those that can trigger on selecting an object, but I need to go teh step further and then select the frames in the curve.


0 Likes
Accepted solutions (1)
9,120 Views
11 Replies
Replies (11)
Message 2 of 12

lee.dunham
Collaborator
Collaborator
I haven't found a way to get this to work other than something like OnUIIdle with manual tracking (which I don't recommend for performance and stability reasons, unless you're quite adept).
I think this is definitely something lacking in the python API.
0 Likes
Message 3 of 12

lee.dunham
Collaborator
Collaborator
You can of course query the current selected key frames on demand, but that's not what I thought you were asking?
If I'm wrong then you just iterate the FCurve.Keys and condition by .Selected.
Don't forget to iter sub anim nodes also.
0 Likes
Message 4 of 12

petecmartin
Advocate
Advocate

I've had no luck on the fcurve selection front either.  Like you say,  it's something missing with the API.

 

I'm still plugging away at alternatives along the lines of the selected frames route.  

I'm triggering some stuff on the change of a sider value which is causing me some greif, but I'm making some progress!

 

Thanks for the reply.

Message 5 of 12

damian.pajda
Advocate
Advocate

I was investigating this issue for some time and the solution with quering selected keys from curves is working fine.

you can get selected keys like below (here I put all selected keys and their values on array):

for key in fcurve.Keys:
  if key.Selected == True:
    keysList.append([key, key.Value])

Up to Mobu 2019 there was problem with getting curves that are already visible in FCurve window. So it was not possible to get only currently visible and selected keys. Keys was still selected even if their curves were not visible in editor. But starting from 2019 there are options that allow to check this. I will post info about it later if you are interested.

But generally this allowed me to do some tool to manipulate selected keys\curves in FCurve window and it's working fine.

0 Likes
Message 6 of 12

lee.dunham
Collaborator
Collaborator

Incase you're interested, this snippet will do the same but will be quicker on larger scenes for a couple of reasons;

keysList.extend(
    (key, key.Value)
    for key in fcurve.Keys
    if key.Selected
)

Message 7 of 12

petecmartin
Advocate
Advocate

Thank You @lee.dunham and @damian.pajda , you've both been really helpful 🙂

I've managed to get around my problem somewhat by storing my global fcurves/frames/values using the 'ONTransaction()' function of the slider and manually selecting which axis to operate on via a UI (Not Ideal, but it works!)

Message 8 of 12

damian.pajda
Advocate
Advocate
Accepted solution

BTW. there is new function to get currently visible\selected properties in FCurve Editor -  FBFCurveEditorUtility().GetProperties(sel_prop_list, True)

It is also possible now to check if any property submember is selected (focused) by prop.IsFocusedChild(i). So you can quite quickly get only those curves that are currently visible\selected in FCurve window.

Script below will get curves of all properties that are animatable and selected.

From this point you could get selected keys\values from those curves.

But I'm not sure if this is what you are looking for 🙂

 

 

FBFCurveEditorUtility().GetProperties(sel_prop_list, True)
for prop in sel_prop_list:
    if prop.IsAnimated():
        if prop.GetSubMemberCount() > 1:
            for i in range(0, prop.GetSubMemberCount()):
                if prop.IsFocusedChild(i):
                   curves_list.append(prop.GetAnimationNode().Nodes[i].FCurve)
        else:
            curves_list.append(prop.GetAnimationNode().FCurve)

 

 

 

Message 9 of 12

lee.dunham
Collaborator
Collaborator
Ahh nice !
Good to know once we can move up a few versions.
Message 10 of 12

petecmartin
Advocate
Advocate

Cool!  @damian.pajda!
This could totally fix my issue!

from pyfbsdk import *

sel_prop_list = ["Translation (Lcl).x", "Translation (Lcl).y","Translation (Lcl).z","Rotation (Lcl).x","Rotation (Lcl).y","Rotation (Lcl).z"]

curves_list = []

FBFCurveEditorUtility().GetProperties(sel_prop_list, True)
for prop in sel_prop_list:
    if prop.IsAnimated():
        if prop.GetSubMemberCount() > 1:
            for i in range(0, prop.GetSubMemberCount()):
                if prop.IsFocusedChild(i):
                   curves_list.append(prop.GetAnimationNode().Nodes[i].FCurve)
        else:
            curves_list.append(prop.GetAnimationNode().FCurve)
            
print curves_list
Message 11 of 12

damian.pajda
Advocate
Advocate

It was added already in mobu 2019 🙂

I started using it in mobu 2023 and 2024

0 Likes
Message 12 of 12

petecmartin
Advocate
Advocate

Awesome!  I've got my stuff working now, thank you @damian.pajda and @lee.dunham  😀