Page 1 of 1

Read and Write Workspace xml files

Posted: 27 Feb 2018, 04:31
by clintonman
I thought we couldn't write to trueSpace xml files from script, but we can. The trick is to use TristateTrue which means read and write unicode instead of ascii text. The sample changes the render to file width value. You can see the change by clicking the Render to File button.

Code: Select all

// Execute 
// Called to execute the command 
function Execute(params)
{

	var forReading = 1, forWriting = 2, forAppending = 8;
	var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0; 

	fso = new ActiveXObject("Scripting.FileSystemObject");

	f = fso.GetFile(System.GetMainDir() + "\\Scripts\\D3DView.RenderToFile.Settings.xml");

	if(!f) return;

	lines = [];

	connToFile = f.OpenAsTextStream( forReading, TristateTrue );//unicode

	while (!connToFile.AtEndOfStream) {

		lines.push(connToFile.ReadLine());
	}

	connToFile.Close();

	connToFile = f.OpenAsTextStream( forWriting, TristateTrue );//unicode

	re = /WIDTH="\d+/;

	for(var i=0;i<lines.length;i++) {
		curline = lines[i];
		System.Trace(curline);
		matchFound = curline.match(re);

		if(matchFound) {
			curline = curline.replace(re,'WIDTH="' + "9876")
			System.Trace(curline);
		}
		connToFile.WriteLine(curline);
	}
	connToFile.Close();
}

Re: Read and Write Workspace xml files

Posted: 27 Feb 2018, 12:31
by Draise
Wait.... does that mean I could potentially batch script render the viewport from workspace!?!?!

This was one of the reasons why I chose not to use TS for a production. I could not automate the D3D rendering.

Re: Read and Write Workspace xml files

Posted: 27 Feb 2018, 15:05
by clintonman
RendertofileSettings.jpg
It means you can set the render options with script.

As far as automating the workspace render you can check out this script. It was created to "realtime" render the animations coming from modelspace and workspace together. It can be used with just workspace animations.

http://clintons3d.com/plugins/truespace ... ender.html

Re: Read and Write Workspace xml files

Posted: 27 Feb 2018, 18:22
by trueBlue
clintonman wrote:
27 Feb 2018, 04:31
I thought we couldn't write to trueSpace xml files from script, but we can. The trick is to use TristateTrue which means read and write unicode instead of ascii text. The sample changes the render to file width value. You can see the change by clicking the Render to File button.
Oh cool! I discovered when saving the onnewscene.xml file that I needed to save as unicode.

Re: Read and Write Workspace xml files

Posted: 29 Apr 2018, 14:54
by trueBlue
Clinton,
What program do you use to edit tS761 xml files?
I notice that the original xml files are encoded using utf-8 and has a GUID.
When I save a script from tS761's jScript Editor it saves in utf-16 and does not have a GUID.
They work but I am not sure if they are right.
I have noticed in the Command History that sometimes a script shows even though it has not been called. :shock:
I would like fix these files encoded using utf-8 with a unique GUID.
Thanks in advance!

Re: Read and Write Workspace xml files

Posted: 29 Apr 2018, 16:16
by clintonman
trueBlue wrote:
29 Apr 2018, 14:54
Clinton,
What program do you use to edit tS761 xml files?
I notice that the original xml files are encoded using utf-8 and has a GUID.
When I save a script from tS761's jScript Editor it saves in utf-16 and does not have a GUID.
They work but I am not sure if they are right.
I have noticed in the Command History that sometimes a script shows even though it has not been called. :shock:
I would like fix these files encoded using utf-8 with a unique GUID.
Thanks in advance!
I haven't edited any of the xml files, but if I was I would probably use visual studio code since it has a select encoding button on the bottom right of it's window. It also has some extensions available for generating guids.