[Maya][Mel] Object with animatable pivotpoint. how to make one?

Hellos everyone. I have been fidgeting with the idea of an animatable pivot point on objects for a while now and I was trying to script one, but my scripting skills are still not that great and needed some help on how to use scripJob’s properly to be able to implement it I think.

I created these objects:

curve -d 1 -p 0.5 0.5 -0.499999 -p -0.5 0.5 -0.5 -p -0.5 0.5 0.5 -p -0.5 -0.5 0.5 -p -0.5 -0.5 -0.5 -p 0.5 -0.5 -0.5 -p 0.5 -0.5 0.5 -p 0.499999 0.5 0.5 -p 0.5 0.5 -0.499999 -p 0.5 -0.5 -0.5 -p -0.5 -0.5 -0.5 -p -0.5 0.5 -0.5 -p -0.5 0.5 0.5 -p 0.499999 0.5 0.5 -p 0.5 -0.5 0.5 -p -0.5 -0.5 0.5 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 ;
curve -d 1 -p 0 0 0.1 -p 0.1 0 0 -p 0 0.1 0 -p 0 0 0.1 -p -0.1 0 0 -p 0 0.1 0 -p -0.1 0 0 -p 0 0 -0.1 -p 0 0.1 0 -p 0 0 -0.1 -p 0.1 0 0 -p 0 -0.1 0 -p 0 0 0.1 -p -0.1 0 0 -p 0 -0.1 0 -p 0 0 -0.1 -p 0.1 0 0 -p 0 -0.1 0 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9 -k 10 -k 11 -k 12 -k 13 -k 14 -k 15 -k 16 -k 17 ;

parent curve2 curve1 ;
select -r curve1 ;
setAttr -k on |curve1.displayLocalAxis;
setAttr -k on |curve1.displayRotatePivot;
setAttr -k on |curve1.rotatePivotTranslateX;
setAttr -k on |curve1.rotatePivotTranslateY;
setAttr -k on |curve1.rotatePivotTranslateZ;
setAttr -k on |curve1.rotatePivotX;
setAttr -k on |curve1.rotatePivotY;
setAttr -k on |curve1.rotatePivotZ;
setAttr "curve1.displayRotatePivot" 1;
setAttr "curve1.displayLocalAxis" 1;
connectAttr -f curve2.translate curve1.rotatePivot;

After having the objects created I started thinking how to counter animate the rotatepivot translation.
I started to make the compensation for atribute modifications to rotateZ only with a ortogonal front view.

curve1.rotatePivotTranslateX = - curve2.translateX + curve2.translateX * cosd(curve1.rotateZ);
curve1.rotatePivotTranslateY = curve2.translateX * sind(curve1.rotateZ);

With this as an expression I am able to compensate the curve2 translation on X axis in local mode.
However my rotationZ on curve1 will also be compensated and will move on the center despite the rotatepivot translation in X having values diferent of zero.
My idea is that I need a way to block my channels inputs into the object. for that I thought of using a scriptJob with a attributechange in the expression but I am unable to make it happen properly.

for the moment what I had is:

//scriptJob
int $index = scriptJob -attributeChange "curve1.rotatePivotX" "adjustX()" ;

//scriptJob adjustment
proc float adjustX(){
curve1.rotatePivotTranslateX = - curve2.translateX + curve2.translateX * cosd(curve1.rotateZ);
curve1.rotatePivotTranslateY = curve2.translateX * sind(curve1.rotateZ);
}

but this is far from working Q_Q

Any help or info would be welcomed. thanks.

If you want to animatre the pivot, you’ll be better off doing it with an expression rather than a scriptJobl; an expression will properly update the attribute (usually the .rotatePivotTranslate attribute) but a script job will not fire during animation playback.