ZBrushCentral

ZScript How to map rotation of one subtool onto another

Hi,

I’m trying to write a script that will read the rotation of one sub-tool and then apply the same rotation to the subtool below it in the tool. The plan so to make a script where I can replace a head or a shield etc by matching rotation and position of two sub-tools. This is where I have got to in my code, but the result always ends up out on one rotation axis:

[IButton,???,“copy the location of an object”,

[varDef,JBSX, 0]
[varDef,JBSY, 0]
[varDef,JBSZ, 0]
[varDef,JBEX, 0]
[varDef,JBEY, 0]
[varDef,JBEZ, 0]
[varDef,JBLINE, 0]

[varDef,JBXR, 0]
[varDef,JBYR, 0]
[varDef,JBZR, 0]
[varDef,JBXG, 0]
[varDef,JBYG, 0]
[varDef,JBZG, 0]
[varDef,JBXB, 0]
[varDef,JBYB, 0]
[varDef,JBZB, 0]

[varDef,xRot, 0]
[varDef,yRot, 0]
[varDef,zRot, 0]

[TransposeGet, JBSX, JBSY, JBSZ, JBEX, JBEY, JBEZ, JBLINE, JBXR, JBYR, JBZR, JBXG, JBYG, JBZG, JBXB, JBYB, JBZB]

// calculate the z rotation
[varSet, xRot, ATAN2(JBYB,JBZB)]
[varSet, yRot, -1 * ASIN(JBXB)]
[varSet, zRot, -1 * ATAN2(JBYR,JBXR)]

[IPress,Tool:SubTool:SelectDown]
[IPress, Tool:Masking:Clear]
[IModSet,Tool:Deformation:Rotate,4]
[ISet,Tool:Deformation:Rotate, zRot]

[IModSet,Tool:Deformation:Rotate,2]
[ISet,Tool:Deformation:Rotate, yRot]

[IModSet,Tool:Deformation:Rotate,1]
[ISet,Tool:Deformation:Rotate, xRot]

]/end of script/

I can’t see the issue in my trig. I’m hoping that someone has already done this and can point me at a working example, but so far I have not seen anything that quite matches on the forum.