Read and Write Workspace xml files

Post Reply
clintonman
Captain
Posts: 2260
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Read and Write Workspace xml files

Post by clintonman » 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.

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();
}
Clinton Reese

http://clintons3d.com

User avatar
Draise
Captain
Posts: 2954
Joined: 21 Sep 2009, 19:33
Type the number ten into the box: 0
Location: Bogota, Colombia
Contact:

Re: Read and Write Workspace xml files

Post by Draise » 27 Feb 2018, 12:31

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.

clintonman
Captain
Posts: 2260
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Read and Write Workspace xml files

Post by clintonman » 27 Feb 2018, 15:05

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
Clinton Reese

http://clintons3d.com

User avatar
trueBlue
Captain
Posts: 1551
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Read and Write Workspace xml files

Post by trueBlue » 27 Feb 2018, 18:22

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.

User avatar
trueBlue
Captain
Posts: 1551
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Read and Write Workspace xml files

Post by trueBlue » 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!

clintonman
Captain
Posts: 2260
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Read and Write Workspace xml files

Post by clintonman » 29 Apr 2018, 16:16

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.
Clinton Reese

http://clintons3d.com

Post Reply