v1.0
プリセットを基準に新しいオブジェクトを作成して戻します。 オブジェクトは TransientObjectContainer 内に作成されるため、シーン内には保持されず、シーン Explorer にも表示されません。 この領域は新しいシーンがロードされるたびにフラッシュされます。 このコマンドは、以下の例に示すとおり、一時的な CustomProperty オブジェクトを作成する際に便利です。
oReturn = CreateObjectFromPreset( PresetObj, [Name] ); |
新規に作成されたオブジェクトを戻します。
| パラメータ | タイプ | 説明 |
|---|---|---|
| PresetObj | 文字列 | プリセット オブジェクトまたはプリセット ファイルの完全パス。 「モデル プリセット」、「パス プリセット」、「プリミティブ プリセット」、「プロパティ プリセット」、および「シェーダ プリセット」を参照してください。 |
| Name | 文字列 | 作成されるオブジェクトにつける名前 |
/*
Example of creating a temporary custom property (aka custom pset).
This can be useful for showing a temporary yet non-modal custom pset
to the user. The user doesn//t have to close the PPG immediately
yet the object does not clutter up the scene file.
*/
NewScene( "", false );
// Demonstrate how you can use it to create a built-in custom pset
var oAnnotation = CreateTemporaryCustomPSet( "Annotation", Application.InstallationPath(siFactoryPath), "MyA" );
if ( oAnnotation ) {
InspectObj( oAnnotation, "", "Annotation Test", siModal, false );
}
// Create an instance of one of the SDK workgroup sample psets
var presetpath = XSIUtils.BuildPath(
Application.InstallationPath( siFactoryPath ),
"XSISDK", "examples", "workgroup", "Addons", "PSetUIDemo"
);
var oPSetUIDemo = CreateTemporaryCustomPSet( "PSetUIDemo", presetpath, "" );
if ( oPSetUIDemo ) {
InspectObj( oPSetUIDemo, "", "PSetUIDemo Test", siModal, false );
}
// Now the following lines will log, declaring that these instances live inside the TransientObjectContainer:
// INFO : Full path of Annotation instance is: TransientObjectContainer.MyA
// INFO : Full path of PSetUIDemo instance is: TransientObjectContainer.PSetUIDemo
// ... but nothing exists under the Scene_Root...
var oProp = Application.ActiveSceneRoot.Properties("PSetUIDemo");
if (oProp == null || typeof(oProp) == "undefined") {
Application.LogMessage( "No instances found." );
} else {
Application.LogMessage( "Found an instance." );
}
// INFO : No instances found.
// ... until you apply it
Application.ActiveSceneRoot.AddProperty( XSIUtils.BuildPath(presetpath, "Data", "DSPresets", "Properties", "PSetUIDemo.Preset") );
oProp = Application.ActiveSceneRoot.Properties("PSetUIDemo");
if (oProp == null || typeof(oProp) == "undefined") {
Application.LogMessage( "No instances found." );
} else {
Application.LogMessage( "Found an instance." );
}
// INFO : Found an instance.
// Function CreateTemporaryCustomPSet
// Creates a temporary custom property set. This does not appear in the scene explorer and you do not have to
// worry about deleting it.
//
// in_PresetName - Name of the preset, which normally matches the name of the spdl file. Do not include the extension
// in_PresetLocation - May be one of the siInstallationPath values (e.g. siUserPath, siUserAddonPath, etc.) or a string path
// in_CustomPSetName - Desired name for the new object, or leave empty for default behavior
//
// Return Value: newly created custom pset
function CreateTemporaryCustomPSet( in_PresetName, in_PresetLocation, in_CustomPSetName )
{
var oPSet;
// Last argument is optional
if ( in_CustomPSetName == "" ) {
in_CustomPSetName = in_PresetName;
}
// Figure out whether this is a string path or an siInstallationPath value
in_PresetLocation = ( typeof(in_PresetLocation) == "string" )
? in_PresetLocation
: Application.InstallationPath(in_PresetLocation);
var presetFullPath = XSIUtils.BuildPath(
in_PresetLocation, "Data", "DSPresets", "Properties", in_PresetName + ".Preset"
);
try {
oPSet = CreateObjectFromPreset( presetFullPath, in_CustomPSetName );
Application.LogMessage( "Full path of " + in_PresetName + " instance is: " + oPSet.FullName );
} catch(e) {
Application.LogMessage( "Failed to create temporary instance of " + in_PresetName + " preset", siWarning );
return null;
}
return oPSet;
} |