Setting keyframe from Daz script

RaketeRakete Posts: 48

How can I set a keyframe from a daz script programmatically? I found this:

where it says I can use DzProperty.setValue(dzTime, value), which should set a property to value and also create a keyframe at dzTime. But as far as I can tell, that does not work.

I have to use code like this:

for (var i = firstFrame+1; i < lastFrame; i++) {    Scene.setFrame(i);		    modifiers[i].getValueChannel().setValue(1);    createKeyFrame.trigger();}

where createKeyFrame comes from

var mgr = MainWindow.getActionMgr();for(var i = 0; i < mgr.getNumActions(); i++) {    action = mgr.getAction(i);    actionText = action.text ;       if (actionText == "Create Keys (Selected Nodes)") {        createKeyFrame = action;    }   }

But this is incredibly slow since I need to do Scene.setFrame(i) and my scene is relatively complex, so switching frames is slow (and creating a recursive keyframe is not fast either).

If I use setValue like so:

for (var i = firstFrame+1; i < lastFrame; i++) {	    modifiers[i].getValueChannel().setValue(timeStep * i, 1);}

no keyframe is created.

Post edited by Rakete on


  • This seems to work, using setValue(timeStep, value), run with a base G8F pre-selected:

    var sel = Scene.getPrimarySelection();var timeStep = Scene.getTimeStep();print(timeStep.valueOf());var obj = sel.getObject();var numMods = obj.getNumModifiers();var mod, valChan, val;Scene.setFrame(5);for (var m = 0; m < numMods; m++) {	mod = obj.getModifier(m);	print(mod.getLabel(), mod.getNumProperties());		valChan = mod.getValueChannel();		valChan.setValue(timeStep *4, 1);	valChan.setValue(timeStep *6, 0.5);	val = valChan.getValue();	print(val);	if (m >= 10) {		break;	}}

    The value 1 is set on frame 4, 0.5 on frame 6, for the first 10 modifiers.  The Scene.setFrame isn't required for the setValue() to work, but it means the print(val) prints the value of the property at frame 5 (interpolated value between 1 and 0.5).  The keyframes don't show up on the timeline, but the property (morph) sliders show the value and the figure reflects the morphs applied at those values.

  • RaketeRakete Posts: 48

    Thanks that helped, I guess it must have been working all the time but I was thrown off by the fact that nothing shows up in the timeline. I tried it now using your code as reference and it worked.

Sign In or Register to comment.