XSIFactory.CreateShaderDef operator

Introduced

v9.0 (2011)

Description

Creates a new shader definition. Softimage shader definitions can be accessed via either XSIApplication.ShaderDefinitions or by ShaderDef.ProgID via XSIApplication.GetShaderDef.

Note: Each shader definition has a unique ProgID which is built from the four specified components. For more information, see Instantiating Shader Definitions and the ProgID.

Tip: On-the-fly (nonpersisted) shader definitions act like parser-based shader definitions that are never parsed (ShaderDef.Parsed always returns false) and have no definition file (ShaderDef.DefinitionPath is always empty). However, you must specify a parser name, and it cannot be either "Softimage" or the name of a parser already registered.

C# Syntax

ShaderDef XSIFactory.CreateShaderDef( String in_strParserName, String in_strClassName, UInt32 in_ulMajor, UInt32 in_ulMinor );

Scripting Syntax

oReturn = XSIFactory.CreateShaderDef( in_strParserName, in_strClassName, in_ulMajor, in_ulMinor );

Return Value

ShaderDef

Parameters

Parameter Type Description
in_strParserName String Name of the parser for the new shader definition. This is basically a dummy string, since shader definitions created with this method are not defined by either plug-ins or parsers.
in_strClassName String Name of the shader class. If you don't specify a UI name for the shader definition, this is the name that appears on the shader node when instantiated in the render tree.
in_ulMajor Long Major version number ('2' in v2.5)
in_ulMinor Long Minor version number ('5' in v2.5)

Examples

Python Example

#
# This example demonstrates how to create a completely bogus shader 
# definition on the fly (ie., not to be persisted) and then how to
# instantiate it on a scene object
#
from win32com.client import constants as si
app = Application
app.NewScene("", False)
# This function creates a bogus shader definition on the fly and returns its ProgID
def CreateDefOnTheFly () :
	otmpShaderDef = XSIFactory.CreateShaderDef("NoParser", "Nunce", 1, 0)
	otmpShaderDef.Category = "Test Shaders"
	# family
	otmpShaderDef.AddShaderFamily("mrTexture")
	# paramdef options (in)
	otmpShadPDefOpts = XSIFactory.CreateShaderParamDefOptions()
	otmpShadPDefOpts.SetTexturable(True)
	otmpShadPDefOpts.SetShortName("squelch")
	# paramdef (in)
	otmpInParams = otmpShaderDef.InputParamDefs
	otmpInParams.AddParamDef("west", si.siColorParameterType, otmpShadPDefOpts)
	# paramdef options (out)
	otmpShadPDefOpts = XSIFactory.CreateShaderParamDefOptions()
	otmpShadPDefOpts.SetTexturable(True)
	otmpShadPDefOpts.SetShortName("splosh")
	# paramdef (out)
	otmpOutParams = otmpShaderDef.OutputParamDefs
	otmpOutParams.AddParamDef("east", si.siColorParameterType, otmpShadPDefOpts)
	# renderer
	otmpRendDef = otmpShaderDef.AddRendererDef("whoops")
	otmpRendOpts = otmpRendDef.RendererOptions
	otmpRendOpts.Set("plain", False)
	# attributes
	otmpAttrs = otmpShaderDef.Attributes
	otmpAttrs.Set("chuckle", "on")
	otmpAttrs.Set("nbr", 456123)
	# return the ProgID of the new shader
	return otmpShaderDef.ProgID
# This function tests to see whether the specified parser name is 
# a registered parser name already (if it is, the script will not
# attempt to create a definition on the fly (to avoid errors)
def IsNotRegistered( in_name ) :
	oPC = Application.Plugins
	for p in oPC :
		for pi in p.Items :
			if pi.Type == "Shader Language Parser" :
				if pi.Name == in_name :
					return False
	# If no match is found, return true
	return True
# First check to make sure the parser name isn't already registered
if IsNotRegistered("NoParser"):
	# Create the shader definition on the fly and get its ProgID
	sProgID = CreateDefOnTheFly()
	# Now create a cube and instantiate this shader on it
	oCube = app.CreatePrim("Cube", "MeshSurface")
	app.CreateShaderFromProgID(sProgID, "Sources.Materials.DefaultLib.Scene_Material")
	app.SIConnectShaderToCnxPoint("Sources.Materials.DefaultLib.Scene_Material.Nunce.east", 
		"Sources.Materials.DefaultLib.Scene_Material.Phong.ambient", False)
	# Finally, remove it (we don't want to clutter up the system)
	oRemoveMe = app.ShaderDefinitions(sProgID)
	if oRemoveMe :
		XSIFactory.RemoveShaderDef(oRemoveMe)
else :
	app.LogMessage("Parser name is already registered.")

See Also

XSIFactory.RemoveShaderDef XSIFactory.CreateShaderParamDefOptions XSIApplication.ShaderDefinitions XSIApplication.GetShaderDef Instantiating Shader Definitions and the ProgID