[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


Script Examples

Here are a couple of example scripts that illustrate the way you might want to write your scripts. These scripts are invoked from the command-line (Start/Programs/MS-DOS Prompt) using the wscript Windows Scripting Host executable.

The scripts in this section are:


Removing Object Code

This script accepts as the command-line parameter the path to the project to be opened. The absolute path needs to be included, for example:


wscript remobj.vbs "C:\testproejcts\test1.mcp"

If no command line arguments are given, the script prompts the user for the absolute path of the project file to be opened. If specified, the script tries to open the project, otherwise it opens the default one c:\testprojects\test1.mcp. This script opens the project and selects the files that belong to the default target.

remobj.vbs:


option explicit
'*******Variable declaration
dim codewarrior
dim project
dim projectname
dim targetIntf
dim count
dim projectCollection
dim targetcollection
dim result
dim showinputbox
dim objArgs

'****** Script ********
Set objArgs = Wscript.Arguments
projectname = "c:\testprojects\test1.mcp"

if objArgs.Count > 1 then
	MsgBox "This Script expects only one argument, rest of the arguments will be ignored!!"
	showinputbox = false
	projectname = CStr(objArgs(0))
end if

if objArgs.Count = 0 then 
	showinputbox = true
else
	showinputbox = false
	projectname = CStr(objArgs(0))
end if

if showinputbox = true then
	result = InputBox("Enter the absolute path for the project to be opened","Input", projectname, 100, 100)
	
	If result = "" Then
		projectname = "c:\testprojects\test1.mcp"
	else
		projectname = cstr(result)
	end if
end if

'Create automation app object
set codewarrior = CreateObject("CodeWarrior.CodeWarriorApp")
MsgBox "App Created"

project = Null
'open project 
set project = codewarrior.OpenProject(projectname, true, 2, 0 )
if TypeName( project ) <> "Null" then
	set targetcollection = project.Targets
	count = targetcollection.Count

	IF ( count > 0 ) then
		set targetIntf = targetcollection.Item( 0 )
		targetIntf.RemoveObjectCode( true )
	END IF
else
	MsgBox CStr( projectname & " does not exist" )
end if 


Build and Wait

This script accepts as a command-line parameter the name of the project to be opened. The absolute path needs to be included, for example:


wscript bldwait.vbs "C:\testprojects\test1.mcp"

If no command-line arguments are given, the script prompts the user for the absolute path of the project file to be opened. If specified, the script tries to open the project, else it opens the default one "c:\testprojects\test1.mcp".

bldwait.vbs:


option explicit
'*******Variable declaration
dim codewarrior
dim project
dim projectname
dim targetIntf
dim count
dim projectCollection
dim targetcollection
dim result
dim showinputbox
dim objArgs
dim buildErrors

'****** Script ********
Set objArgs = Wscript.Arguments
projectname = "c:\temp\none\none.mcp"

if objArgs.Count > 1 then
	MsgBox "This Script expects only one argument, rest of the arguments will be ignored!!"
	showinputbox = false
	projectname = CStr(objArgs(0))
end if

if objArgs.Count = 0 then 
	showinputbox = true
else
	showinputbox = false
	projectname = CStr(objArgs(0))
end if

if showinputbox = true then
	result = InputBox("Enter the absolute path for the project to be opened","Input", projectname, 100, 100)
	
	If result = "" Then
		projectname = "c:\testprojects\test1.mcp"
	else
		projectname = cstr(result)
	end if
end if

'Create automation app object
set codewarrior = CreateObject("CodeWarrior.CodeWarriorApp")
MsgBox "App Created"

project = Null
'open project 
set project = codewarrior.OpenProject(projectname, true, 2, 0 )
if TypeName( project ) <> "Null" then
	project.BuildAndWaitToComplete
else
	MsgBox CStr( projectname & " does not exist" )
end if 

project.close



[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 02, 2000