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: [email protected] 
Sent: Tuesday, March 03, 2015 7:34 AM 
To: [email protected] 
Subject: Softimage Digest, Vol 76, Issue 14 

Send Softimage mailing list submissions to
[email protected]

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
[email protected]

You can reach the person managing the list at
[email protected]

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" <[email protected]>
Subject: Re: Softimage Digest, Vol 76, Issue 13
To: <[email protected]>
Message-ID: <[email protected]>
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 <[email protected]>
Subject: Re: query shader parameters
To: [email protected]

hi  dan
unfortunately this gives an error:

# ERROR : Traceback (most recent call last):
#   File "<Script Block >", line 79, in <module>
#     if ( i.PortType == 0 ) :
#   File 
"C:\Autodesk\Softimage_2015\Application\python\Lib\site-packages\win32com\client\dynamic.py",
 
line 516, in __getattr__
#     raise AttributeError("%s.%s" % (self._username_, attr))
# AttributeError: <unknown>.PortType
#  - [line 79]

i can't wrap my head around that. is there a wrong context?
if i print oNode i get:
# Sources.Materials.DefaultLib.Scene_Material.Phong



On 3/3/2015 10:50 AM, Dan Yargici wrote:
> for i in oNode.Parameters :
>     if ( i.PortType == 0 ) :
>         print i

-- 

------------------------------------------------------------------------

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 <http://www.onlinevideo.ch/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://listproc.autodesk.com/pipermail/softimage/attachments/20150303/d4f642c0/attachment.html
 

------------------------------

Message: 2
Date: Tue, 3 Mar 2015 06:19:00 -0800
From: "Matt Lind" <[email protected]>
Subject: Re: query shader parameters
To: <[email protected]>
Message-ID: <[email protected]>
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 <[email protected]>
Subject: Re: query shader parameters
To: [email protected]

hi  dan
unfortunately this gives an error:

# ERROR : Traceback (most recent call last):
#   File "<Script Block >", line 79, in <module>
#     if ( i.PortType == 0 ) :
#   File 
"C:\Autodesk\Softimage_2015\Application\python\Lib\site-packages\win32com\client\dynamic.py",
 
line 516, in __getattr__
#     raise AttributeError("%s.%s" % (self._username_, attr))
# AttributeError: <unknown>.PortType
#  - [line 79]

i can't wrap my head around that. is there a wrong context?
if i print oNode i get:
# Sources.Materials.DefaultLib.Scene_Material.Phong



On 3/3/2015 10:50 AM, Dan Yargici wrote:
> for i in oNode.Parameters :
>     if ( i.PortType == 0 ) :
>         print i

-- 

------------------------------------------------------------------------

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 <http://www.onlinevideo.ch/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://listproc.autodesk.com/pipermail/softimage/attachments/20150303/6d939ce5/attachment.html
 

------------------------------

Message: 3
Date: Tue, 03 Mar 2015 16:33:58 +0100
From: Jan Dubied <[email protected]>
Subject: Re: query shader parameters
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="windows-1252"

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 "<Script Block >", line 84, in <module>
#     if oNodeParameterType.getItem( 0 ) == true:
# AttributeError: 'tuple' object has no attribute 'getItem'
#  - [line 84]



i think i'm close now... i hope so...





On 3/3/2015 3:19 PM, Matt Lind wrote:
> 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 <[email protected]>
> Subject: Re: query shader parameters
> To: [email protected]
> hi  dan
> unfortunately this gives an error:
> # ERROR : Traceback (most recent call last):
> #   File "<Script Block >", line 79, in <module>
> #     if ( i.PortType == 0 ) :
> #   File
> "C:\Autodesk\Softimage_2015\Application\python\Lib\site-packages\win32com\client\dynamic.py",
>  
>
> line 516, in __getattr__
> #     raise AttributeError("%s.%s" % (self._username_, attr))
> # AttributeError: <unknown>.PortType
> #  - [line 79]
> i can't wrap my head around that. is there a wrong context?
> if i print oNode i get:
> # Sources.Materials.DefaultLib.Scene_Material.Phong
> On 3/3/2015 10:50 AM, Dan Yargici wrote:
> > for i in oNode.Parameters :
> >     if ( i.PortType == 0 ) :
> >         print i
> -- 
> ------------------------------------------------------------------------
> 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 <http://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 <http://www.onlinevideo.ch/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://listproc.autodesk.com/pipermail/softimage/attachments/20150303/809b4334/attachment.html
 

------------------------------

_______________________________________________
Softimage mailing list
[email protected]
http://listproc.autodesk.com/mailman/listinfo/softimage


End of Softimage Digest, Vol 76, Issue 14
*****************************************

Reply via email to