SearchAndReplacePath
 
 
 

SearchAndReplacePath

Introduced

v1.5

Description

Updates the file paths for files that are used in the scene. For example, when your picture directory location changes. You can view the list of paths, also called the 'external file list' by selecting Source Paths from the File menu.

You can use this command to rename all files in a specific category (eg., all Pictures) or to rename every file in the external file list. If no arguments are specified, a property page appears asking you to enter the input values.

Scripting Syntax

SearchAndReplacePath( [Category], [OldString], [NewString], [CaseSensitive], [Files] );

Parameters

Parameter Type Description
Category String Category of files to change. This corresponds to the Category column in the File > Source Paths dialog.

Default Value: All

Possible Values:

Description:

All All files in the ExternalFilesList.
Actions All actions(".eani") files.
Audio All audio (".wav", ".aiff", ".mov", etc.) files.
Models All model (".emdl") files.
MatLib All material library(".xsi") files.
Pictures All picture (".pic", ".tga", ".gif", etc.) files.
Render_Pictures All pictures for rendering ex: HDR.
Synoptic All synoptic (".htm", ".html") files.
Thumbnails All Thumbnails files.
OldString String The string to search for in the path(s) specified. This can be the name of a directory (eg., "fillet" in "c:\users\fillet\src"), an entire path (eg., "c:\users\fillet\src"), or a substring of the directory (eg., "fill" in "c:\users\fillet\src").

Default Value: If this parameter is not specified, a property page pops up asking for input.

NewString String The string to replace the OldString with in the path(s) specified.

Default Value: If this parameter is not specified, a property page pops up asking for input.

CaseSensitive Boolean True to perform the search-and-replace in a case-sensitive mode.

Default Value: False

Files XSICollection A collection of FileReference objects to be processed. If nothing is specified, all external files used by the scene will be processed. This is used by the External File Manager dialog.

Examples

JScript Example

//----------------------------------------------------------------------------
//
// This example demonstrates how to search and replace a portion of
// the path in the external file list.
//
//----------------------------------------------------------------------------
NewScene( null, false );
// First add the no_icon pic to the external file list by adding a texture
CreatePrim( "Sphere", "MeshSurface" );
BlendInPresets( null, null, 0, true, siReplaceNoBlend );
var oExternalFileList = GetValue( "Project.ExternalFilesList" );
// Print current external file list before SearchAndReplacePath
Application.LogMessage( "Original paths:" );
for ( var i=0; i< oExternalFileList.Count; i++ ) {
        Application.LogMessage( oExternalFileList.Item(i) );
}
// Change the pictures (only 1 in this case) to a new name which will be invalid
SearchAndReplacePath( "Pictures", "noIcon", "missingIcon" );
// Print replaced external file list
oExternalFileList = GetValue( "Project.ExternalFilesList" );
Application.LogMessage( "Changed paths:" );
for (i=0; i< oExternalFileList.Count; i++) {
        Application.LogMessage( oExternalFileList.Item(i) );
}
// Change back the pictures to the original filename.
SearchAndReplacePath( "Pictures", "missing", "no" );
// Print restored external file list
oExternalFileList = GetValue( "Project.ExternalFilesList" );
Application.LogMessage( "Restored paths:" );
for ( i=0; i< oExternalFileList.Count; i++ )
{
        Application.LogMessage( oExternalFileList.Item(i) );
}
//----------------------------------------------------------------------------
// Output of above script:
//----------------------------------------------------------------------------
// INFO : Original paths:
// INFO : $XSI_HOME/Application/rsrc/noIcon.pic
// INFO : Changing $XSI_HOME/Application/rsrc/noIcon.pic To $XSI_HOME/Application/rsrc/missingIcon.pic
// INFO : Changed paths:
// INFO : $XSI_HOME/Application/rsrc/missingIcon.pic
// INFO : Changing $XSI_HOME/Application/rsrc/missingIcon.pic To $XSI_HOME/Application/rsrc/noIcon.pic
// INFO : Restored paths:
// INFO : $XSI_HOME/Application/rsrc/noIcon.pic

See Also

FileReference Scene.GetExternalFile