Interesting problem. BTW, it is also present in XSI 5.0 QFE9. After some testing, I have found this simple one-line workaround to "restore" the object:
scnMatPhongDiffuse.Disconnect()
scnMatPhongDiffuse = scnMatPhongDiffuse.Parent.diffuse # <-----
LogRed(scnMatPhongDiffuse)
Cheers,
Francois
> De: "Bernard Lebel" <3dbernard(at)gmail.com>
> Date: 2006/04/07 ven. PM 10:46:01 GMT-04:00
> À: XSI(at)Softimage.COM
> Objet: Re: Problem with shader nested parameters in XSI? Workarounds?
>
> Initially, before I posted the script above, I used a slightly
> different approach to get the shader back. I "got the shader back" by
> populating a collection with its fullname. So, your wrapper would look
> like this:
>
>
> # In the import/instantiation block
> import win32com
> xsifactory = win32com.client.Dispatch( 'XSI.Factory' )
>
> # ...
>
> def RefreshObject( oShader ):
> oColl = xsifactory.createobject( 'XSI.Collection' )
> oColl.items = oShader.fullname
> return oColl(0)
>
>
> You might want to consider this approach for large amounts of shader
> to handle :-)
>
>
>
> Cheeres
> Bernard
>
>
>
>
> On 4/7/06, Andy Jones <andy(at)thefront.com> wrote:
> > I think I'm going with the following:
> >
> > def RefreshObject(object):
> > return Application.Dictionary.GetObject(object.FullName)
> >
> >
> > Andy Jones wrote:
> >
> > > Ah, this is great. I guess this means XSI must be sort of "uprooting"
> > > the object heirarchy I've already grabbed and replacing it somewhere
> > > upstream. So, I just need to figure out how far back I need to reach
> > > to catch the root of the new object heirarchy and write a script that
> > > takes a buggered shader parameter and uses it to find the new version
> > > (so that my equivalent of printRed will actually use its argument).
> > > Or, maybe I'll do it as a wrapper for disconnect.
> > >
> > > Thanks,
> > > Andy
> > >
> > > Bernard Lebel wrote:
> > >
> > >> 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