List of all Shaders

Discussions concerning programming of SOFTIMAGE©
User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

List of all Shaders

Post by TwinSnakes007 » 05 Aug 2012, 23:10

Is there a way to get a list of all shaders without traversing the RenderTree port by port?

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: List of all Shaders

Post by xsisupport » 06 Aug 2012, 14:17

TwinSnakes007 wrote:Is there a way to get a list of all shaders without traversing the RenderTree port by port?
Not really. Here's a Python snippet that gets all the shaders in a render tree.
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: List of all Shaders

Post by TwinSnakes007 » 06 Aug 2012, 14:49

xsisupport wrote:
TwinSnakes007 wrote:Is there a way to get a list of all shaders without traversing the RenderTree port by port?
Not really. Here's a Python snippet that gets all the shaders in a render tree.
For a reference parameter on a shader, all shaders from all material libraries in the current scene are displayed in the picking session, whether the shader is connected to anything or not. Is that list available in the SDK?

edit: Thanks for the script.

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: List of all Shaders

Post by xsisupport » 06 Aug 2012, 15:02

TwinSnakes007 wrote:
xsisupport wrote:
TwinSnakes007 wrote:Is there a way to get a list of all shaders without traversing the RenderTree port by port?
Not really. Here's a Python snippet that gets all the shaders in a render tree.
For a reference parameter on a shader, all shaders from all material libraries in the current scene are displayed in the picking session, whether the shader is connected to anything or not. Is that list available in the SDK?

edit: Thanks for the script.
Can you give me an example of a reference parameter?
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: List of all Shaders

Post by TwinSnakes007 » 06 Aug 2012, 16:12

Steve,

When you set the filter attribute for a shader param:

Code: Select all

paramOptions.SetAttribute( constants.siReferenceFilterAttribute, constants.siShaderReferenceFilter )
and then set it's type to siShaderDataTypeReference:

Code: Select all

params.AddParamDef( "bsdf", constants.siShaderDataTypeReference, paramOptions )
In the PPG for that shader, you'll get a "Pick" button next to the connect icon for that parameter.

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: List of all Shaders

Post by xsisupport » 06 Aug 2012, 16:52

Ah well, I was hoping to save some time by looking at an existing shader to see the behavior you described.

Code: Select all

from sipyutils import si			# win32com.client.Dispatch('XSI.Application')
from sipyutils import C			# win32com.client.constants
si=si()

sClassID = "{6495C5C1-FD18-474E-9703-AEA66631F7A7}"
x = si.FindObjects( "", sClassID )
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: List of all Shaders

Post by TwinSnakes007 » 06 Aug 2012, 17:03

Steve,

I'm running to a meeting, but I thought about going the ClassID route too, but I have 30-50 custom shader def's. Wouldnt that mean I'd have to look for each one of them in a separate call?

P.S. I dont know of an existing SI shader, but you can load my shaderdefs here and look at one of them to see how the reference parameter behaves:

https://www.mitsuba-renderer.org/hg/mit ... Shaders.py

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: List of all Shaders

Post by xsisupport » 06 Aug 2012, 17:36

TwinSnakes007 wrote:Steve,

I'm running to a meeting, but I thought about going the ClassID route too, but I have 30-50 custom shader def's. Wouldnt that mean I'd have to look for each one of them in a separate call?

P.S. I dont know of an existing SI shader, but you can load my shaderdefs here and look at one of them to see how the reference parameter behaves:

https://www.mitsuba-renderer.org/hg/mit ... Shaders.py

Code: Select all

from sipyutils import si			# win32com.client.Dispatch('XSI.Application')
si=si()

sClassID = "{6495C5C1-FD18-474E-9703-AEA66631F7A7}"
shaders = si.FindObjects( "", sClassID )

#
# If your shaderdefs had a common prefix, you could 
# filter the XSICollection returend by FindObjects
#
#shaders.Filter( "", "", "MTS*")


#
# Using the shaderdef category:
#
def f(x):
    return x.ShaderDef.Category == "Mitsuba/bsdf"

# Get list of shaderdefs x that match the filter f(x)
defs = [x for x in filter( f, shaders ) ]
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: List of all Shaders

Post by TwinSnakes007 » 07 Aug 2012, 16:21

Thanks for the tip Steve...looking thru the sdk docs, there was an example there the whole time for FindObjects

Code: Select all

# Enumerate all shaders under the scene root.
from win32com.client import constants as c
shaders = Application.ActiveSceneRoot.FindObjects( c.siShaderID )
for s in shaders:
	LogMessage( s.ProgID )
# INFO : Softimage.soft_light.1.0

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: List of all Shaders

Post by xsisupport » 07 Aug 2012, 16:26

There's also Material.GetAllShaders, which I overlooked
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: List of all Shaders

Post by TwinSnakes007 » 08 Aug 2012, 02:41

Here's what I ended up with:

Code: Select all

from sipyutils import log

app = Application

oMatLib = app.ActiveProject.ActiveScene.MaterialLibraries

for oLib in oMatLib :
	log (oLib.Name)

	for oMaterial in oLib.Items :
		log (oMaterial.Name)

		oShaders = oMaterial.GetAllShaders()

		for oShader in oShaders:
			log (oShader.Name)