Hi Andy,
Yeah that is strange, I tested your script and came to the same
conclusion. Just by logging the number of parameters of the "diffuse"
parameter I can see that even after a disconnection, there is one one
parameter on the diffuse.
However I have found a way to fix your problem. It's a workaround,
nothing too elegant but it works on my end. Basically you have to
rebind variable(s) to the shader/parameter you wish to print once it
has been disconnected (sorry I have re-written your code to my liking
:-)
xsi = Application
def printRed( oShader ):
oMat = xsi.activeproject.activescene.materiallibraries(0).items(0)
oPhong = oMat.parameters( 'surface' ).source
oDiffuse = oPhong.parameters( 'diffuse' )
xsi.logmessage( oDiffuse.parameters.count )
xsi.logmessage( oDiffuse.parameters( 'red' ).value )
oMat = xsi.activeproject.activescene.materiallibraries(0).items(0)
oPhong = oMat.parameters( 'surface' ).source
# Check if diffuse parameter has a source
if not oPhong.parameters( 'diffuse' ).source:
xsi.logmessage( 'Shader has no source, print now.' )
printRed( oPhong )
oImage = xsi.createobjectfrompreset( 'Shaders\\Texture\\Image.Preset' )
oPhong.parameters( 'diffuse' ).connect( oImage )
else:
xsi.logmessage( 'Shader has a source, disconnect then print.' )
oPhong.parameters( 'diffuse' ).disconnect()
printRed( oPhong )
Cheers
Bernard
On 4/7/06, Andy Jones <andy(at)thefront.com> wrote:
> # I think this python code demonstrates a problem with parameter updates
> in XSI 5.1.
> # What seems to happen is that when a datasource is removed from a
> shader parameter,
> # the nested parameters don't get recreated until after the script has
> finished running.
> # This is a problem because in a lot of scripts, I might want to replace
> shader inputs
> # with hard-coded values.
>
> # Instructions: Run the script twice. Ideally, the value of the red
> parameter
> # of the diffuse input on the scene material's phong should be logged
> twice.
> # Instead, the red parameter is inaccessible, even after the shader
> input is
> # disconnected, until the script has finished.
>
> def LogRed(colorParam):
> try:
> # Attempt to read a value from red component
> Application.LogMessage(colorParam.red.Value)
>
> except:
> Application.LogMessage("Failed to retrieve red parameter")
>
> # Try to list the parameters (none get listed)
> for p in colorParam.Parameters:
> Application.LogMessage(p.FullName)
>
>
> # Grab the diffuse input of the scene material
> try:
> Application.SelectObj("Sources.Materials.DefaultLib.Scene_Material",
> "", "")
> scnMatPhongDiffuse = Application.Selection[0].surface.source.diffuse
> except:
> Application.NewScene("", "")
> Application.SelectObj("Sources.Materials.DefaultLib.Scene_Material",
> "", "")
> scnMatPhongDiffuse = Application.Selection[0].surface.source.diffuse
>
> # Connect and disconnect a shader every other run of the code and try to
> log red value
> if (scnMatPhongDiffuse.Source == None):
> LogRed(scnMatPhongDiffuse)
> Application.LogMessage("Connecting shader to diffuse")
> scnMatPhongDiffuse.ConnectFromProgID("Softimage.txt2d-image-explicit.1")
> else:
> Application.LogMessage("Disconnecting shader from diffuse")
> scnMatPhongDiffuse.Disconnect()
> LogRed(scnMatPhongDiffuse)
>
> ---
> Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
> unsubscribe xsi
>
---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi