XSIFactory.CreateObject
 
 
 

XSIFactory.CreateObject

Introduced

v4.0

Description

Creates an object from a type name.

C# Syntax

Object XSIFactory.CreateObject( String Name );

Scripting Syntax

oReturn = XSIFactory.CreateObject( NamespaceID );

Return Value

A Softimage object, for example a CustomProperty or CustomOperator

Parameters

Parameter Type Description
NamespaceID String Type Name. In the case of a Self-installed CustomProperty or CustomOperator this is the name as provided in PluginRegistrar.RegisterProperty and PluginRegistrar.RegisterOperator.

Examples

1. JScript Example

/*
        This example shows how to create a temporary instance of the Self-Installed 
        Custom Property called "CustomColor". This object is not part of the scene 
        so you don't have to delete it after you are done using it.
*/
var oColor = XSIFactory.CreateObject( "CustomColor" )
bCancelled = InspectObj( oColor, null, "Pick your favorite color", siModal, false ) ;
if ( !bCancelled )
{
        Application.LogMessage( "You picked " + oColor.Color_R.Value + "," + oColor.Color_G.Value + "," + oColor.Color_B.Value ) ;
}

2. VBScript Example

' 
' This example shows a typical use of XSIFactory.CreateObject to create a temporary
' CustomProperty object used as the UI for an Import or Export operation.
'
' There are two routines.  DoScanUI is a user-friendly version that lets the user pick
' the options for the operation via a temporary custom pset.  It then calls DoScanLowLevel 
' which does the actual operation without any UI.
'
DoScanUI Application.InstallationPath( siUserPath ), false 
sub DoScanUI( in_defaultScanLocation, in_bRecursive )
        if NOT Application.Interactive then                     
                ' If you want your script to work in batch mode you could skip the modal dialog box and just 
                ' use the default values.  But it would be clearly code to call DoScanLowLevel directly.
                DoScanLowLevel in_defaultScanLocation, in_bRecursive
                exit sub
        end if
        ' This CustomProperty is not part of the scene 
        ' and will not be persisted
        set oTempPSet = XSIFactory.CreateObject( "CustomProperty" )
        oTempPSet.Name = "Scan Options"
        oTempPSet.AddParameter3 "ScanFolder", siString
        oTempPSet.AddParameter3 "Recursive", siBool, , , , false
        ' Establish the default values in the Custom PSet
        oTempPSet.ScanFolder.Value = in_defaultScanLocation
        oTempPSet.Recursive.Value = in_bRecursive
        ' Build a custom layout
        set oLayout = oTempPSet.PPGLayout
        oLayout.AddItem "ScanFolder", "Scan Folder", siControlFolder
        oLayout.AddItem "Recursive"
        ' Show the custom ui, Softimage is frozen until the user closes the dialog
        bCancel = InspectObj( oTempPSet,,,siModal,false )
        if bCancel then
                Logmessage "Operation cancelled"
        else
                'Read the values from the pset  
                strScanLocation = oTempPSet.ScanFolder.Value
                bRecursive = oTempPSet.Recursive.Value
                DoScanLowLevel strScanLocation, bRecursive 
        end if
        ' No need to call DeleteObj
end sub
sub DoScanLowLevel( in_folder, in_bRecursive )
        ' Do the scanning operation not actually implemented in this example)
        strMsg = "Doing "
        if in_bRecursive then
                strMsg = strMsg & "recursive "
        end if
        Application.LogMessage strMsg & "scan of " & in_folder
end sub