Page 1 of 1
Help with simple script
Posted: 27 Sep 2017, 22:00
by gfeather
I am not a scripter at all. I am using softimage XSI 7.01, and all I really need it to do, is read the position and rotation information off a selected null or object on each frame and output that to a text file that looks like the image attatched.
It looks like there is 1 tab space between each parameter.
I am using this to load it back into tracking software and this is the format it uses.
Re: Help with simple script
Posted: 28 Sep 2017, 01:06
by rray
This script logs the data to the script output. There will be some //INFO like characters at the left that you would have to delete...
(script editor must be set to jscript to run this)
Code: Select all
var sel=Selection(0);
var space=" ";
var frames=20;
for(var n=1; n<frames; n++)
logmessage(n+space+
sel.kinematics.local.posx.value(n)+space+
sel.kinematics.local.posy.value(n)+space+
sel.kinematics.local.posz.value(n)+space+
sel.kinematics.local.roty.value(n)+space+
sel.kinematics.local.rotx.value(n)+space+
sel.kinematics.local.rotz.value(n)+space
);
Re: Help with simple script
Posted: 28 Sep 2017, 05:18
by myara
Nice rray! I didn't know you could get a frame position with that. I always used GetValue
I modified that code to round those values to 3 decimals, and write it into a TXT file:
Code: Select all
//JScript
//------------------------------
var space = " "
var startFrame = 1
var endFrame = 20
var roundDecimals = 3
var filePath = "D:\\test.txt"
//------------------------------
var sel=Selection(0);
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var txt = fso.OpenTextFile( filePath, 2, true )
for(var n=startFrame; n<endFrame+1; n++)
txt.WriteLine( n+space+
sel.kinematics.local.posx.value(n).toFixed(roundDecimals) +space+
sel.kinematics.local.posy.value(n).toFixed(roundDecimals) +space+
sel.kinematics.local.posz.value(n).toFixed(roundDecimals) +space+
sel.kinematics.local.roty.value(n).toFixed(roundDecimals) +space+
sel.kinematics.local.rotx.value(n).toFixed(roundDecimals) +space+
sel.kinematics.local.rotz.value(n).toFixed(roundDecimals) +space
);
txt.Close();
And a few notes:
In my modified version I separated the variables you can edit to the top, and the code to the bottom.
Be sure to run this in a JScript tab (not VBscript nor Python).
If you want global values, replace "local" with "global.
When you specify a file path, use \\ instead of \. (ex: D:\test.txt is wrong, D:\\test.txt is correct)
Re: Help with simple script
Posted: 28 Sep 2017, 14:56
by rray
Hehe didn't know either, just discovered by accident.. thought it might be worth a try before looking up the GetValue syntax with frames.
Re: Help with simple script
Posted: 28 Sep 2017, 18:45
by gfeather
Thank you so much, that does exactly what I needed!