Re: query shader parameters

2015-03-03 Thread Matt Lind
Here is my JScript example rewritten in Python:

##- start of script (Python) ---
from win32com.client import constants as xsi;

#
# Constants class
#
class Constants :

INDEX_SHADER_PORT_TYPE  = 0;
INDEX_SHADER_PARAMETER_TYPE = 1;

#
# GetShaderParameterInfo()
#
def GetShaderParameterInfo( oObject ) :

oConstants = Constants();

if not oObject.IsClassOf( xsi.siX3DObjectID ) :
return;

oMaterial= oObject.Material;
oShaderParameter = oMaterial.Parameters( "surface" ).Source;

if ( oShaderParameter ) :

oShader = oShaderParameter.Parent;
LogMessage( "Shader: " + oShader.FullName, xsi.siComment );

oParameters = oShader.Parameters;

for oParameter in oParameters :

aParameterData = oShader.GetShaderParameterType( 
oParameter.ScriptName );

if ( oShaderParameterType[ oConstants.INDEX_SHADER_PORT_TYPE ] == 
True ) :
# input parameter
LogMessage( "INPUT: " + oParameter.ScriptName + ", " + str( 
aParameterData[ oConstants.INDEX_SHADER_PARAMETER_TYPE ] ), xsi.siComment );
else:
# output parameter
LogMessage( "OUTPUT: " + oParameter.ScriptName + ", " + str( 
aParameterData[ oConstants.INDEX_SHADER_PARAMETER_TYPE ] ), xsi.siComment );

return;


#
GetShaderParameterInfo( Application.Selection(0) );

##--- end of script ---


Matt






-Original Message- 
From: softimage-requ...@listproc.autodesk.com 
Sent: Tuesday, March 03, 2015 7:34 AM 
To: softimage@listproc.autodesk.com 
Subject: Softimage Digest, Vol 76, Issue 14 

Send Softimage mailing list submissions to
softimage@listproc.autodesk.com

To subscribe or unsubscribe via the World Wide Web, visit
http://listproc.autodesk.com/mailman/listinfo/softimage
or, via email, send a message with subject or body 'help' to
softimage-requ...@listproc.autodesk.com

You can reach the person managing the list at
softimage-ow...@listproc.autodesk.com

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Softimage digest..."


Today's Topics:

   1. Re: Softimage Digest, Vol 76, Issue 13 (Matt Lind)
   2. Re: query shader parameters (Matt Lind)
   3. Re: query shader parameters (Jan Dubied)


--

Message: 1
Date: Tue, 3 Mar 2015 06:18:32 -0800
From: "Matt Lind" 
Subject: Re: Softimage Digest, Vol 76, Issue 13
To: 
Message-ID: 
Content-Type: text/plain; charset="iso-8859-1"

You need a reference to the shader object, then use it's methods to test each 
parameter as shown here:

// start of script (JScript) 
var INDEX_SHADER_PORT_TYPE  = 0;
var INDEX_SHADER_PARAMETER_TYPE = 1;

GetShaderParameterInfo( Selection(0) );

function GetShaderParameterInfo( oObject )
{
if ( !oObject.IsClassOf( siX3DObjectID ) ) {
return;
}
var oMaterial= oObject.Material;
var oShaderParameter = oMaterial.Parameters( "surface" ).Source;

if ( oShaderParameter ) {

var oShader = oShaderParameter.Parent;
LogMessage( "Shader: " + oShader.FullName, siComment );

var oParameters = oShader.Parameters;

for ( var i = 0; i < oParameters.Count; i++ ) {

var oParameter   = oParameters(i);
var oShaderParameterType = oShader.GetShaderParameterType( 
oParameter.ScriptName );

if ( oShaderParameterType.getItem( INDEX_SHADER_PORT_TYPE ) == true 
) {
// input parameter
LogMessage( "INPUT: " + oParameter.ScriptName + ", " + 
oShaderParameterType.getItem( INDEX_SHADER_PARAMETER_TYPE ), siComment );
} else {
// output parameter
LogMessage( "OUTPUT: " + oParameter.ScriptName + ", " + 
oShaderParameterType.getItem( INDEX_SHADER_PARAMETER_TYPE ), siComment );
    }
    }
}

return;
}
//- end of script 



Matt






Date: Tue, 03 Mar 2015 10:56:00 +0100
From: Jan Dubied 
Subject: Re: query shader parameters
To: softimage@listproc.autodesk.com

hi  dan
unfortunately this gives an error:

# ERROR : Traceback (most recent call last):
#   File "

Re: query shader parameters

2015-03-03 Thread Jan Dubied

thanks guys
i can use it like that:

# Manually Select Phong first

oNode = Application.Selection(0)

Application.LogMessage(oNode.Name)

for i in oNode.Parameters :
oNodeParameterType = oNode.GetShaderParameterType( i.ScriptName )
for ii in oNodeParameterType :
if ii == False :
print i


and yes, i'll rename the variables once they work :-)

thanks a lot!
j



On 3/3/2015 5:10 PM, Matt Lind wrote:

For starters, I'd name your variables to reflect what they are.  Doing so
will make it easier to follow the logic and spot the problem.

Look up ShaderParameter.GetShaderParameterType() in the SDK manuals and
you'll see the method returns an array.  the first index of that array 
is a

boolean indicating whether the parameter is an input parameter (true) or
output parameter (false).  the 2nd index of the array is an enum which
indicates the parameter type (float, integer, color, vector, ...).  In my
example code, I defined two constants to specify which array index to 
lookup
(INDEX_SHADER_PARAMETER_TYPE, INDEX_SHADER_PORT_TYPE).  I did that to 
make

the code easier to read and understand.  Also to avoid making stupid
mistakes if the array needs to be accessed in many different areas of the
code.  Not really necessary in a snippet this small, but useful in larger
scripts and good practice.

The '.getItem()' method is specific to JScript as all Softimage methods
returning arrays in the JScript script engine return them as VBSafeArray
objects.  Instead of using the usual array[index] notation, you must use
array.getItem(index) method.  However, if you're using Python, you 
don't use

the .getItem() method at all.  You use whatever is normally used for
indexing a python array.

Matt





Date: Tue, 03 Mar 2015 16:33:58 +0100
From: Jan Dubied 
Subject: Re: query shader parameters
To: softimage@listproc.autodesk.com

hi matt
thank you
i tried to translate to python:

this part works and prints:

for i in oNode.Parameters :
oNodeParameterType = oNode.GetShaderParameterType( i.ScriptName )
print oNodeParameterType

# (True, 1)
# (True, 3)
# (True, 1)
# (True, 1)
# (False, 4)


now, how to get the first thing? (true/false)

this does not work:

for i in oNode.Parameters :
oNodeParameterType = oNode.GetShaderParameterType( i.ScriptName )
print oNodeParameterType
if oNodeParameterType.getItem( 0 ) == true:
print i
else:
print str(i) + "OUTPUT"


# ERROR : Traceback (most recent call last):
#   File "

Re: query shader parameters

2015-03-03 Thread Matt Lind

For starters, I'd name your variables to reflect what they are.  Doing so
will make it easier to follow the logic and spot the problem.

Look up ShaderParameter.GetShaderParameterType() in the SDK manuals and
you'll see the method returns an array.  the first index of that array is a
boolean indicating whether the parameter is an input parameter (true) or
output parameter (false).  the 2nd index of the array is an enum which
indicates the parameter type (float, integer, color, vector, ...).  In my
example code, I defined two constants to specify which array index to lookup
(INDEX_SHADER_PARAMETER_TYPE, INDEX_SHADER_PORT_TYPE).  I did that to make
the code easier to read and understand.  Also to avoid making stupid
mistakes if the array needs to be accessed in many different areas of the
code.  Not really necessary in a snippet this small, but useful in larger
scripts and good practice.

The '.getItem()' method is specific to JScript as all Softimage methods
returning arrays in the JScript script engine return them as VBSafeArray
objects.  Instead of using the usual array[index] notation, you must use
array.getItem(index) method.  However, if you're using Python, you don't use
the .getItem() method at all.  You use whatever is normally used for
indexing a python array.

Matt





Date: Tue, 03 Mar 2015 16:33:58 +0100
From: Jan Dubied 
Subject: Re: query shader parameters
To: softimage@listproc.autodesk.com

hi matt
thank you
i tried to translate to python:

this part works and prints:

for i in oNode.Parameters :
oNodeParameterType = oNode.GetShaderParameterType( i.ScriptName )
print oNodeParameterType

# (True, 1)
# (True, 3)
# (True, 1)
# (True, 1)
# (False, 4)


now, how to get the first thing? (true/false)

this does not work:

for i in oNode.Parameters :
oNodeParameterType = oNode.GetShaderParameterType( i.ScriptName )
print oNodeParameterType
if oNodeParameterType.getItem( 0 ) == true:
print i
else:
print str(i) + "OUTPUT"


# ERROR : Traceback (most recent call last):
#   File "

Re: query shader parameters

2015-03-03 Thread Jan Dubied

hi matt
thank you
i tried to translate to python:

this part works and prints:

for i in oNode.Parameters :
oNodeParameterType = oNode.GetShaderParameterType( i.ScriptName )
print oNodeParameterType

# (True, 1)
# (True, 3)
# (True, 1)
# (True, 1)
# (False, 4)


now, how to get the first thing? (true/false)

this does not work:

for i in oNode.Parameters :
oNodeParameterType = oNode.GetShaderParameterType( i.ScriptName )
print oNodeParameterType
if oNodeParameterType.getItem( 0 ) == true:
print i
else:
print str(i) + "OUTPUT"


# ERROR : Traceback (most recent call last):
#   File "

Re: query shader parameters

2015-03-03 Thread Matt Lind
You need a reference to the shader object, then use it's methods to test each 
parameter as shown here:

// start of script (JScript) 
var INDEX_SHADER_PORT_TYPE  = 0;
var INDEX_SHADER_PARAMETER_TYPE = 1;

GetShaderParameterInfo( Selection(0) );

function GetShaderParameterInfo( oObject )
{
if ( !oObject.IsClassOf( siX3DObjectID ) ) {
return;
}
var oMaterial= oObject.Material;
var oShaderParameter = oMaterial.Parameters( "surface" ).Source;

if ( oShaderParameter ) {

var oShader = oShaderParameter.Parent;
LogMessage( "Shader: " + oShader.FullName, siComment );

var oParameters = oShader.Parameters;

for ( var i = 0; i < oParameters.Count; i++ ) {

var oParameter   = oParameters(i);
var oShaderParameterType = oShader.GetShaderParameterType( 
oParameter.ScriptName );

if ( oShaderParameterType.getItem( INDEX_SHADER_PORT_TYPE ) == true 
) {
// input parameter
LogMessage( "INPUT: " + oParameter.ScriptName + ", " + 
oShaderParameterType.getItem( INDEX_SHADER_PARAMETER_TYPE ), siComment );
} else {
// output parameter
LogMessage( "OUTPUT: " + oParameter.ScriptName + ", " + 
oShaderParameterType.getItem( INDEX_SHADER_PARAMETER_TYPE ), siComment );
}
}
}

return;
}
//- end of script 



Matt






Date: Tue, 03 Mar 2015 10:56:00 +0100
From: Jan Dubied 
Subject: Re: query shader parameters
To: softimage@listproc.autodesk.com

hi  dan
unfortunately this gives an error:

# ERROR : Traceback (most recent call last):
#   File "

Re: query shader parameters

2015-03-03 Thread Jan Dubied

i try to make a clone shader command...
here is small portion of the python script.
if you select a node in the render tree and run, it should work so far.
PortType remains unknown...


### Import Definitions

from win32com.client import constants as si

### Simplify Commands

a = Application

### Get The Active View

oLayout = a.Desktop.ActiveLayout
oRTViews = oLayout.Views.Filter( "Render Tree" )

x = oRTViews(0)
y = x.GetAttributeValue( "selection" ).split(",")

### Get The Shader Parameters

a.SelectObj(y, "", "")

oNode = a.Selection(0)


### Do Stuff

print oNode

for i in oNode.Parameters :
print i







On 3/3/2015 10:54 AM, Dan Yargici wrote:
Ah, looks like you're trying to get the port type of a parameter 
object rather than a port.


I'd check the SDK docs.  I'd need to know more about the context of 
what you're trying to do to be of any help.


DAN

On Tue, Mar 3, 2015 at 9:50 AM, Dan Yargici > wrote:


Hi Jan,

Try:

for i in oNode.Parameters :
if ( i.PortType == 0 ) :
print i


siPortType


  Description

Enumerates the different kinds of ports.


  C# Syntax

siPortType.siPortInput  
 // 0
siPortType.siPortOutput 
// 1

ConstantValue   Description
siPortInput 0   Input port.
siPortOutput1   Output port.





On Tue, Mar 3, 2015 at 9:45 AM, Jan Dubied
mailto:j.dub...@onlinevideo.ch>> wrote:

thank you jacob
i should have been more exact:

i can get the selected shader node, but i did not post that
part here.
the only thing i cannot evaluate is if "i" (the shader
parameter) is input or output...

for exaple:

for i in oNode.Parameters :
print i

this prints the parameters of the shader. in- and output.

# Sources.Materials.DefaultLib.Scene_Material.Phong.Name

# Sources.Materials.DefaultLib.Scene_Material.Phong.diffuse
# Sources.Materials.DefaultLib.Scene_Material.Phong.specular
# Sources.Materials.DefaultLib.Scene_Material.Phong.out







On 3/3/2015 10:40 AM, Jacob Gonzalez wrote:

Not sure if this is what you are trying to do, hope it helps:

for param in oNode.NestedObjects:
if  param.Name == "surface":
surfaceParam = param

myOutputShader = surfaceParam.NestedObjects(0)

print   myOutputShader
 sphere.Material.Lambert

On Tue, Mar 3, 2015 at 7:53 AM, Jan Dubied
mailto:j.dub...@onlinevideo.ch>> wrote:

hi guys
any idea how i can sort out "output" ports and just query
shader input parameters?

i tried this:

for i in oNode.Parameters :
if ( i.PortType == siPortInput ) :
print i

where oNode is the selected shader node in the render tree.
but it seems that PortInput is not defined...

thanks in advance


-- 





Jan Dubied
2D/3D Artist

*ON LINE VIDEO 46 AG*
Leutschenbachstr. 46 / 8050 Zurich / Switzerland
Phone +41 44 305 73 73  /
Fax +41 44 305 73 00 
www.onlinevideo.ch 




-- 




Jan Dubied
2D/3D Artist

*ON LINE VIDEO 46 AG*
Leutschenbachstr. 46 / 8050 Zurich / Switzerland
Phone +41 44 305 73 73  / Fax
+41 44 305 73 00 
www.onlinevideo.ch 





--



Jan Dubied
2D/3D Artist

*ON LINE VIDEO 46 AG*
Leutschenbachstr. 46 / 8050 Zurich / Switzerland
Phone +41 44 305 73 73 / Fax +41 44 305 73 00
www.onlinevideo.ch 



Re: query shader parameters

2015-03-03 Thread Jan Dubied

hi  dan
unfortunately this gives an error:

# ERROR : Traceback (most recent call last):
#   File "

Re: query shader parameters

2015-03-03 Thread Dan Yargici
Ah, looks like you're trying to get the port type of a parameter object
rather than a port.

I'd check the SDK docs.  I'd need to know more about the context of what
you're trying to do to be of any help.

DAN

On Tue, Mar 3, 2015 at 9:50 AM, Dan Yargici  wrote:

> Hi Jan,
>
> Try:
>
> for i in oNode.Parameters :
> if ( i.PortType == 0 ) :
> print i
>
>
> siPortTypeDescription
>
> Enumerates the different kinds of ports.
> C# Syntax
>
> siPortType.siPortInput  
> // 0
> siPortType.siPortOutput 
> // 1
>
> ConstantValueDescriptionsiPortInput0Input port.siPortOutput1Output port.
>
>
>
>
> On Tue, Mar 3, 2015 at 9:45 AM, Jan Dubied 
> wrote:
>
>>  thank you jacob
>> i should have been more exact:
>>
>> i can get the selected shader node, but i did not post that part here.
>> the only thing i cannot evaluate is if "i" (the shader parameter) is
>> input or output...
>>
>> for exaple:
>>
>> for i in oNode.Parameters :
>> print i
>>
>> this prints the parameters of the shader. in- and output.
>>
>> #  Sources.Materials.DefaultLib.Scene_Material.Phong.Name
>> # Sources.Materials.DefaultLib.Scene_Material.Phong.diffuse
>> # Sources.Materials.DefaultLib.Scene_Material.Phong.specular
>> # Sources.Materials.DefaultLib.Scene_Material.Phong.out
>>
>>
>>
>>
>>
>>
>>
>> On 3/3/2015 10:40 AM, Jacob Gonzalez wrote:
>>
>>  Not sure if this is what you are trying to do, hope it helps:
>>
>>  for param in oNode.NestedObjects:
>> if  param.Name == "surface":
>> surfaceParam = param
>>
>>  myOutputShader = surfaceParam.NestedObjects(0)
>>
>>  print   myOutputShader
>>  sphere.Material.Lambert
>>
>>
>> On Tue, Mar 3, 2015 at 7:53 AM, Jan Dubied 
>> wrote:
>>
>>>  hi guys
>>> any idea how i can sort out "output" ports and just query shader input
>>> parameters?
>>>
>>> i tried this:
>>>
>>> for i in oNode.Parameters :
>>> if ( i.PortType == siPortInput ) :
>>> print i
>>>
>>> where oNode is the selected shader node in the render tree.
>>> but it seems that PortInput is not defined...
>>>
>>> thanks in advance
>>>
>>>
>>> --
>>>
>>>  --
>>>
>>> Jan Dubied
>>> 2D/3D Artist
>>>
>>> *ON LINE VIDEO 46 AG*
>>>  Leutschenbachstr. 46 / 8050 Zurich / Switzerland
>>> Phone +41 44 305 73 73 <%2B41%2044%20305%2073%2073> / Fax +41 44 305 73
>>> 00 <%2B41%2044%20305%2073%2000>
>>> www.onlinevideo.ch
>>>
>>
>>
>> --
>>
>>  --
>>
>> Jan Dubied
>> 2D/3D Artist
>>
>> *ON LINE VIDEO 46 AG*
>>  Leutschenbachstr. 46 / 8050 Zurich / Switzerland
>> Phone +41 44 305 73 73 / Fax +41 44 305 73 00
>> www.onlinevideo.ch
>>
>
>


Re: query shader parameters

2015-03-03 Thread Dan Yargici
Hi Jan,

Try:

for i in oNode.Parameters :
if ( i.PortType == 0 ) :
print i


siPortTypeDescription

Enumerates the different kinds of ports.
C# Syntax

siPortType.siPortInput  // 0
siPortType.siPortOutput // 1

ConstantValueDescriptionsiPortInput0Input port.siPortOutput1Output port.




On Tue, Mar 3, 2015 at 9:45 AM, Jan Dubied  wrote:

>  thank you jacob
> i should have been more exact:
>
> i can get the selected shader node, but i did not post that part here.
> the only thing i cannot evaluate is if "i" (the shader parameter) is input
> or output...
>
> for exaple:
>
> for i in oNode.Parameters :
> print i
>
> this prints the parameters of the shader. in- and output.
>
> #  Sources.Materials.DefaultLib.Scene_Material.Phong.Name
> # Sources.Materials.DefaultLib.Scene_Material.Phong.diffuse
> # Sources.Materials.DefaultLib.Scene_Material.Phong.specular
> # Sources.Materials.DefaultLib.Scene_Material.Phong.out
>
>
>
>
>
>
>
> On 3/3/2015 10:40 AM, Jacob Gonzalez wrote:
>
>  Not sure if this is what you are trying to do, hope it helps:
>
>  for param in oNode.NestedObjects:
> if  param.Name == "surface":
> surfaceParam = param
>
>  myOutputShader = surfaceParam.NestedObjects(0)
>
>  print   myOutputShader
>  sphere.Material.Lambert
>
>
> On Tue, Mar 3, 2015 at 7:53 AM, Jan Dubied 
> wrote:
>
>>  hi guys
>> any idea how i can sort out "output" ports and just query shader input
>> parameters?
>>
>> i tried this:
>>
>> for i in oNode.Parameters :
>> if ( i.PortType == siPortInput ) :
>> print i
>>
>> where oNode is the selected shader node in the render tree.
>> but it seems that PortInput is not defined...
>>
>> thanks in advance
>>
>>
>> --
>>
>>  --
>>
>> Jan Dubied
>> 2D/3D Artist
>>
>> *ON LINE VIDEO 46 AG*
>>  Leutschenbachstr. 46 / 8050 Zurich / Switzerland
>> Phone +41 44 305 73 73 <%2B41%2044%20305%2073%2073> / Fax +41 44 305 73
>> 00 <%2B41%2044%20305%2073%2000>
>> www.onlinevideo.ch
>>
>
>
> --
>
>  --
>
> Jan Dubied
> 2D/3D Artist
>
> *ON LINE VIDEO 46 AG*
>  Leutschenbachstr. 46 / 8050 Zurich / Switzerland
> Phone +41 44 305 73 73 / Fax +41 44 305 73 00
> www.onlinevideo.ch
>


Re: query shader parameters

2015-03-03 Thread Jan Dubied

thank you jacob
i should have been more exact:

i can get the selected shader node, but i did not post that part here.
the only thing i cannot evaluate is if "i" (the shader parameter) is 
input or output...


for exaple:

for i in oNode.Parameters :
print i

this prints the parameters of the shader. in- and output.

#  Sources.Materials.DefaultLib.Scene_Material.Phong.Name
# Sources.Materials.DefaultLib.Scene_Material.Phong.diffuse
# Sources.Materials.DefaultLib.Scene_Material.Phong.specular
# Sources.Materials.DefaultLib.Scene_Material.Phong.out






On 3/3/2015 10:40 AM, Jacob Gonzalez wrote:

Not sure if this is what you are trying to do, hope it helps:

for param in oNode.NestedObjects:
if  param.Name == "surface":
surfaceParam = param

myOutputShader = surfaceParam.NestedObjects(0)

print   myOutputShader
 sphere.Material.Lambert

On Tue, Mar 3, 2015 at 7:53 AM, Jan Dubied > wrote:


hi guys
any idea how i can sort out "output" ports and just query shader
input parameters?

i tried this:

for i in oNode.Parameters :
if ( i.PortType == siPortInput ) :
print i

where oNode is the selected shader node in the render tree.
but it seems that PortInput is not defined...

thanks in advance


-- 




Jan Dubied
2D/3D Artist

*ON LINE VIDEO 46 AG*
Leutschenbachstr. 46 / 8050 Zurich / Switzerland
Phone +41 44 305 73 73  / Fax +41
44 305 73 00 
www.onlinevideo.ch 




--



Jan Dubied
2D/3D Artist

*ON LINE VIDEO 46 AG*
Leutschenbachstr. 46 / 8050 Zurich / Switzerland
Phone +41 44 305 73 73 / Fax +41 44 305 73 00
www.onlinevideo.ch 



Re: query shader parameters

2015-03-03 Thread Jacob Gonzalez
Not sure if this is what you are trying to do, hope it helps:

for param in oNode.NestedObjects:
if  param.Name == "surface":
surfaceParam = param

myOutputShader = surfaceParam.NestedObjects(0)

print   myOutputShader
 sphere.Material.Lambert


On Tue, Mar 3, 2015 at 7:53 AM, Jan Dubied  wrote:

>  hi guys
> any idea how i can sort out "output" ports and just query shader input
> parameters?
>
> i tried this:
>
> for i in oNode.Parameters :
> if ( i.PortType == siPortInput ) :
> print i
>
> where oNode is the selected shader node in the render tree.
> but it seems that PortInput is not defined...
>
> thanks in advance
>
>
> --
>
>  --
>
> Jan Dubied
> 2D/3D Artist
>
> *ON LINE VIDEO 46 AG*
>  Leutschenbachstr. 46 / 8050 Zurich / Switzerland
> Phone +41 44 305 73 73 / Fax +41 44 305 73 00
> www.onlinevideo.ch
>


query shader parameters

2015-03-02 Thread Jan Dubied

hi guys
any idea how i can sort out "output" ports and just query shader input 
parameters?


i tried this:

for i in oNode.Parameters :
if ( i.PortType == siPortInput ) :
print i

where oNode is the selected shader node in the render tree.
but it seems that PortInput is not defined...

thanks in advance


--



Jan Dubied
2D/3D Artist

*ON LINE VIDEO 46 AG*
Leutschenbachstr. 46 / 8050 Zurich / Switzerland
Phone +41 44 305 73 73 / Fax +41 44 305 73 00
www.onlinevideo.ch