XSI Common Object Model


Microsoft’s COM technology is a key component of the windows operating system and an excellent approach to share data where applications can communicate, not only passing data, but executing other’s applications tools from your own. XSI is built on top of this approach as a true com application and therefore from any com application you can call XSI and vice-versa.

Why this is important? it is not just about about sharing data but encapsulating into a single tool the capability to use other tools installed like calling Photoshop actions from inside XSI or even more interesting, call any office application tools to retrieve or process data. A typical example is talking to excel or outlook, automating tasks that otherwise would require complex programming and also very time consuming without this technology.

Remember, any application that is COM based exports a list of tools to the rest of your environment and you can use them, obviously you must know the syntax but it is fairly easy.

Talking to Excel

Probably a good example of how to expand your capabilities is by retrieving data from Excel to use it inside XSI for your own purposes, let’s say read a database of point to construct the terrain. In this example it is just a simple script to read and write data into excel, feel free to modify it. (i would love to know what are you using it for if you have the time to email me).

// Comunicating with Microsoft Excel
// Created by Jordi Bares, 2002

// Conect with Excel
var app = new ActiveXObject("Excel.Application");

// Open a Excel XLS file
var wb = app.Workbooks.Open("D:\\temp\\DataSheet.xls");

// Select the worksheet to work with
var ws = wb.Worksheets(1);

var suffix = "_changed";

// Main loop
for (row=1 ; row<8 ; row++)
// Get the values
x = ws.Cells(row, 1);
y = ws.Cells(row, 2);
z = ws.Cells(row, 3);
// Print the value so we know where we are
Application.LogMessage ("Row: " & row & " Column: " & 1 & " Value: " & x);
Application.LogMessage ("Row: " & row & " Column: " & 2 & " Value: " & y);
Application.LogMessage ("Row: " & row & " Column: " & 3 & " Value: " & z);

// Calculate the sum
sum = x+y+z;

// Dump the new value into the excel sheet
ws.Cells(row, 4).Value = sum

// Drop something inside excel
ws.Cells(row+1, 1).Value = "Example by"
ws.Cells(row+1, 2).Value = "Jordi Bares"

// Save back the file with the same name

// Close the sheet

// Quit from Excel

// Empty everything
var ws = "";
var wb = "";
var app = "";

Talking to Outlook

Another very handy communication would be to send an email once some process has finished (rendering or a heavy simulation). In any case this can be done by using a script and opening a communication with (for example) outlook. Again we need some kind of sintax that is provided by Outlook, not XSI, so remember to look carefully at that program’s manual.

// Conect with OutLook (not Outlook express!!!)
var app = new ActiveXObject(Outlook.Application);

// Open an image file
var mail = app.CreateItem();

// Fill Outlook fields with data
mail.To = "jordibares@hotmail.com";
mail.Subject = "Automail";
mail.Body = "This is a test of email from inside XSI";

// Send the email

// Close the document

// Quit from Outlook

// Empty everything
var mail = "";
var app = "";

Talking to Photoshop

Photoshop is probably the most used tool of any 3D artist, sometimes more than the 3D tool itself, but photoshop has much more than a great set of artist tools available, also has the ability to execute actions from outside. This is an special case as Adobe has not put together (yet) a full COM application, therefore you can’t think the same way than with excel, access or other fully COM applications. Photoshop provides just a call to the actions by name that can be run from another COM application, in this case from inside XSI.

// Created by Jordi Bares, 2002
// Talking to photoshop to run an action
// Conect with Photoshop
var app = new ActiveXObject("Photoshop.Application");

// Open an image file
var psd = app.Open("D:\\temp\\test.pic");

var suffix = "_changed"

// Call some Action - you have to give a correct name

// Save the new document with a new name
psd.SaveTo( "D:\\temp\\test" + suffix + ".pic" );
// Close the document

// Quit from Photoshop
// Empty everything
var psd = "";
var app = "";

Final words

Although at the beggining could be seen as something complex, the truth is that is extremely easy to share data and expand your toolset, opening a door to the future of 3D software communication, now you can talk without any extra file or file format with other applications (if they are COM based obviously). From SQL databases, Excel sheets, Word processing systems, project management tools, image manipulation tools, mathematical analisys and much more, it is just a matter of time that the solutions start to become obvious for you.

This post is tagged:

Leave a Reply