Maxscript allows for use of OLE connections with other applications in windows, mainly other microsoft applications (there's no official list that I've ever found). With these features you can access most of the functionality of other applications and harness their power without needing to learn any other languages, just some funky syntax. Just to let you know, while this technique can be performed in most versions of Max, after Max 8, you can use .Net to interface with other applications. I'll post more on that later.
The Example
Ok, to get started all you really need to know is how to instantiate an OLE object and some key syntax to interface with Excel. Let me show you a sample script:
-- Generate a filename
excelFile = "C:\\test.xls
-- Start an Excel OLE Object
x = CreateOLEObject "Excel.Application
-- Create a new workbook in the new excel document
x.application.Workbooks.Add
-- Give the active sheet a name ("Test
x.ActiveSheet.Name = "Test"
-- This makes Excel Visible
x.visible = true
-- Put some content into Cell A1
(x.application.Range("A1")).value = "This is Cell A1"
-- Change the color of A1:B1 to red
(x.application.Range("A1:B1")).Interior.ColorIndex = 45
-- Save the spreadsheet
x.application.ActiveWorkbook.SaveAs(excelFile)
-- Close the spreadsheet
x.application.ActiveWorkbook.Close
-- quit excel
x.quit()
-- Release the OLE Object
releaseOLEObject x
-- Release ALL OLE Objects, just incase
releaseAllOLEObjects()
In this example you can get a feel for how to interact with excel. Each line is commented to explain how it works. In general the idea is to start an OLE object, which points to an application and then send it the commands you wish to execute. Conversly you can retrieve data from an excel spreadsheet using the same methods described above. This information is also documented in the maxscript help, unfortunately there isn't much information on the different methods you can use to work with excel, that must be gathered through online research. Questions?
No comments:
Post a Comment