Page tree
Skip to end of metadata
Go to start of metadata

Summary

You can make your own examples to see this run, the code below is only a sample.

You will first have to enable scripts in Excel. To do this, open up Excel, select Tools > Macros > Security and set it to medium. Open up Excel, go to Tools > Macros > Visual Basic Editor and create a new code module

Code Snippets

Sub MWO01()
'note the name of the application to create the object came from
'running the registry editor "regedit" and looking under "HKEY_CLASSES_ROOT"
'for the "AWR.MWOffice" objects

On Error GoTo Catch

'uncomment the line for the proper version of AWR.
Set MWOffice2 = CreateObject("AWR.MWOffice.8.0")

MWOffice2.Open ("C:\Documents and Settings\ryan\My Documents\AWR\Scripts\batch\test1.emp")
MWOffice2.Project.simulate
MWOffice2.Project.Save
'MWOffice2.Project.Close
MWOffice2.Open ("C:\Documents and Settings\ryan\My Documents\AWR\Scripts\batch\test2.emp")
MWOffice2.Project.simulate
MWOffice2.Project.Save
'MWOffice2.Project.Close
MWOffice2.Open ("C:\Documents and Settings\ryan\My Documents\AWR\Scripts\batch\test3.emp")
MWOffice2.Project.simulate
MWOffice2.Project.Save
'MWOffice2.Project.Close
MWOffice2.Open ("C:\Documents and Settings\ryan\My Documents\AWR\Scripts\batch\test4.emp")
MWOffice2.Project.simulate
MWOffice2.Project.Save
'MWOffice2.Project.Close
MWOffice2.Open ("C:\Documents and Settings\ryan\My Documents\AWR\Scripts\batch\test5.emp")
MWOffice2.Project.simulate
MWOffice2.Project.Save
MWOffice2.Project.Close


Catch:
'MsgBox Err.Number & vbCrLf & Err.Description
    If Err.Number = 851 Then 'if not dirty will skip save command
        Resume Next
    Else
       'MsgBox Err.Number & vbCrLf & Err.Description
    End If
    
End Sub

Powershell as batch controller

A powershell batch file to load a project, simulate it and save it would look like:

$mwo = new-object -comobject "AWR.MWOffice"
sleep(5)
$mwo.Open($input_file)
$mwo.Project.Simulate()
$mwo.Project.SaveAs($output_file)
$mwo.Project.Close()
$mwo.Quit()

Assuming the variables $input_file and $output_file have been previously defined.

Note the code here is very similar to the excel code above, just run in a different engine.

  • No labels