AddRefModelResolution
 
 
 

AddRefModelResolution

Introduced

v6.0

Description

Adds a resolution to a referenced Model. A referenced model can have an unlimited number of resolutions. Each resolution has a name and a file.

Scripting Syntax

AddRefModelResolution( Model, [ResolutionName], [FileName] );

Parameters

Parameter Type Description
Model String The model where you want to add a resolution.

Default Value: Current selection

ResolutionName String The name of the resolution. If not specified a default name is given.
FileName String The filename to use for this new resolution. By default the file path is not set.

Examples

JScript Example

/* 
        This example illustrates how to add and remove resolutions on a reference model. It also demonstrates
        how to navigate through the resolution information on a reference model (see the convenience functions
        at the bottom of the example, especially GetAllResolutions).
*/
// Import a referenced model.
NewScene( null, false );
var sModelPath =  XSIUtils.BuildPath( Application.InstallationPath(siFactoryPath), 
        "Data", "XSI_SAMPLES", "Models", "ManSkeleton_Basic.emdl" );
ImportModel( sModelPath, null, true );
// Add a new resolution
var oRefModel = Application.ActiveSceneRoot.Models.Item(0);
AddRefModelResolution( oRefModel, "MyRes", sModelPath );
// Display the current resolutions
LogResolutions( oRefModel );
// Now remove the original resolution and verify that the new resolution is there
var iTargetRes = GetResolutionIndexByName( oRefModel, "res1" );
if ( iTargetRes > -1 ) {
        var iCurrentRes = oRefModel.NestedObjects("Active Resolution").Value;
        if ( iCurrentRes == iTargetRes ) {
                // Change the active resolution to the new one and remove the original
                oRefModel.NestedObjects("Active Resolution").Value = iTargetRes + 1;
                RemoveRefModelResolution( oRefModel, "res1", true );
        }
        // Display again the resolutions
        LogResolutions( oRefModel );
}
// Expected results:
// INFO : res0
// INFO :     file =  
// INFO :     name =  Offloaded
// INFO : res1
// INFO :     file =  Models\ManSkeleton_Basic.emdl
// INFO :     name =  res1
// INFO : res2
// INFO :     file =  Models\ManSkeleton_Basic.emdl
// INFO :     name =  MyRes
// INFO : res0
// INFO :     file =  
// INFO :     name =  Offloaded
// INFO : res1
// INFO :     file =  Models\ManSkeleton_Basic.emdl
// INFO :     name =  MyRes
/*
        These are convenience functions that do most of the work of navigating through
        the resolutions information nested under each reference model. The resolutions 
        info is never displayed in the UI, but you can think of its structure like so:
                ReferenceModel (model)
                        - Resolutions (special container)
                                - res0 (compound parameter)
                                        - File parameter (eg., "<installationpath>/Data/XSI_SAMPLES/Models/ManSkeleton_Basic.emdl")
                                        - Name parameter (eg., "MyRes")
                                + res1
                                  ...
                                + resN
        In order to access this info you need to use the SIObject.NestedObjects property
        on the ReferenceModel, the Resolutions container, and then each resolution parameter.
*/
function GetAllResolutions( in_oRefModel )
{
        var e = new Enumerator( in_oRefModel.NestedObjects );
        for ( ; !e.atEnd(); e.moveNext() ) {
                var oCurrentContainer = e.item();
                if ( oCurrentContainer.Name == "Resolutions" ) {
                        return oCurrentContainer.NestedObjects;
                }
        }
}
/* 
        Logs the file and name values of each resolution to history
*/
function LogResolutions( in_oRefModel )
{
        // Visit each resolution and find its name and file info
        var oResolutions = GetAllResolutions( in_oRefModel );
        for ( var i=0; i<oResolutions.Count; i++ ) {
                var oResolutionParameter = oResolutions(i);
                Application.LogMessage( oResolutionParameter.Name );
                // The file and name parameters are nested under the compound resolution parameter
                var oResInfo = oResolutionParameter.NestedObjects;
                for ( var j=0; j<oResInfo.Count; j++ ) {
                        Application.LogMessage( "    " + oResInfo(j).Name + " =  " + oResInfo(j).Value );
                }
        }
}
/* 
        Returns the index number of the resolution given its name
*/
function GetResolutionIndexByName( in_oModel, in_sResName )
{
        // Visit each resolution and check its name against the specified name
        var oResolutions = GetAllResolutions( in_oModel );
        for ( var i=0; i<oResolutions.Count; i++ ) {
                var oResolutionParameter = oResolutions(i);
                if ( oResolutionParameter.NestedObjects("name").Value == in_sResName ) {
                        return i;
                }
        }
        // If not found, return a negative value
        return -1;
}

See Also

RemoveRefModelResolution