Help with simple script

General questions and troubleshooting SOFTIMAGE©
Post Reply
gfeather
Posts: 14
Joined: 18 Nov 2016, 21:30

Help with simple script

Post by gfeather » 27 Sep 2017, 22:00

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.
test05.png

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: Help with simple script

Post by rray » 28 Sep 2017, 01:06

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
	);
softimage resources section updated Jan 5th 2024

User avatar
myara
Posts: 403
Joined: 28 Sep 2011, 10:33

Re: Help with simple script

Post by myara » 28 Sep 2017, 05:18

Nice rray! I didn't know you could get a frame position with that. I always used GetValue :P

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)
M.Yara
Character Modeler | Softimage Generalist (sort of)

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: Help with simple script

Post by rray » 28 Sep 2017, 14:56

Hehe didn't know either, just discovered by accident.. thought it might be worth a try before looking up the GetValue syntax with frames. :D
softimage resources section updated Jan 5th 2024

gfeather
Posts: 14
Joined: 18 Nov 2016, 21:30

Re: Help with simple script

Post by gfeather » 28 Sep 2017, 18:45

Thank you so much, that does exactly what I needed!

Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests