Page 1 of 1

Extracting object data from truespace into excel

Posted: 29 Nov 2009, 14:57
by Rhino169
I have been playing around with Google Sketch up and they had a feature where you could export a .csv file to excel about custom object information.

This information is created by setting up custom attributes for objects such as cost, part number, etc..

I figure in the link editor I could use the panel editor to make custom fields like the ones mentioned above. If I could put data there....is there a way to get it exported out?

The other place I figure that could be used on an object by object basis is the "Objects note editor". Is that data extractable?

Any help here would be great. :worship:

Thanks in advance!

Re: Extracting object data from truespace into excel

Posted: 30 Nov 2009, 14:47
by froo
Hi Jeff.
Yes, you can create data connectors on the node,
and, in a panel view, attach text fields to those connectors.
You can then add a button to that panel which executes a jscript
command. The jscript command gets the data from the connectors,
and writes that data to a CSV file.

That is a basic approach, though you may want more options.

Re: Extracting object data from truespace into excel

Posted: 16 Nov 2013, 16:36
by Rhino169
Froo...can you show a screen shot of attaching text field to the data connectors?
Sorry but I am not very saavy with the interface yet....or at I'm trying to get back into it.


Also in the Trueplay default scene, there is an orange folder and when you click it, your My Documents dierectory opens in windows. here is the script for the command:
' Execute
' Called to execute the command
Sub Execute(params)
Dim objShell
Set objShell=CreateObject("WScript.Shell")
objShell.Run "explorer.exe"
End Sub

How would I run a specific MS Excel File from this coding. Say: objShell.Run "test.xls"
Would that work or do I need to open excel first then load the file?

Thanks for any help on this.

Regards...Jeff

Re: Extracting object data from truespace into excel

Posted: 18 Nov 2013, 03:37
by clintonman
Here are some links that might help. I found them by searching for "jscript com excel.application"

http://msdn.microsoft.com/en-us/library/ff194565.aspx" onclick="window.open(this.href);return false; has vb code

Code: Select all

Set xl = CreateObject("Excel.Sheet") 
xl.Application.Workbooks.Open "newbook.xls"
corresponding jscript would look something like

Code: Select all

xl = new ActiveXObject("Excel.Sheet") 
xl.Application.Workbooks.Open("newbook.xls")
I have no idea if the above code works. Just a quick translation from vbscript to jscript

http://support.microsoft.com/kb/234774" onclick="window.open(this.href);return false;
http://msdn.microsoft.com/en-us/library ... 94%29.aspx" onclick="window.open(this.href);return false;

Javascript and Jscript are essentially the same language so you should also find info with a search on "javascript excel.application"

I don't have ms excel but it should also have a developer/macro/scripting section that uses vbscript that you might be able to use as a guide.

Re: Extracting object data from truespace into excel

Posted: 20 Nov 2013, 23:14
by trueBlue

Code: Select all

// Execute 
// Called to execute the command 
var cubeSize = 1.0 

function Execute(ret) 
{ 
	ExcelApp = new ActiveXObject("Excel.Application"); 
	rosDir = System.GetMainDir(); 

	ExcelApp.Workbooks.Open(rosDir + '\\RS Data\\labyrinth2.xls'); 
	
	// load height and width 
	width = ExcelApp.ActiveSheet.Cells(1,1).Value; 
	height = ExcelApp.ActiveSheet.Cells(2,1).Value; 

	// load labyrinth matrix 
	for (x = 1; x <= width; x++) 
	{
		for (y = 4; y <= height+4; y++) 
		{ 
			if (ExcelApp.ActiveSheet.Cells(y, x).Value) 
			{ 
				// create "wall" here 
				name = Space.Cube(cubeSize,cubeSize,cubeSize,1, 1, 1); 
				// set position 
				Node.Value(name,'tx') = x; 
				Node.Value(name,'ty') = y; 
				Node.Value(name,'tz') = 1.0; 
			}
		} 
	}
	ExcelApp.Quit(); 
} 
You can find the above script in Activities/My Activities/Labyrinth.RsObj
This script reads the labyrinth2.xls in your tS7.61 installation in the RS Data folder and adds cubes into your scene as outlined from the cells in the Excel file. You must have Excel installed in order for this to work. Not sure how to get information to Excel though.

Re: Extracting object data from truespace into excel

Posted: 21 Nov 2013, 03:39
by Rhino169
Holy Moly! Thanks trueblue! :bananaguitar:

I will have to study this...and execute it with the labyrinth scene.

I am looking to be able to apply this code (or modified version) to an object in trueplay and spit info out about the object. Preferably custom object data that I might apply to the object while in Truespace along with location or size data.

Is there a way to pass the object name to the excel file name. Meaning that if the object was "cube". It would open "cube.xls" This way I could copy it to each object needed and it would not need to be edited. Something like:

ExcelApp.Workbooks.Open(rosDir + '\\RS Data\\"objectname".xls');

Where "objectname" is the truespace object name and if then the associated excel file would open. I would just have to have excel files to match the obects with the open excel code.

Regards,Jeff