Getting the original shader assignment

0
down vote
favorite
Was wondering if anyone has any good ways for approaching this problem of mine…

I have a few rigs in which it is a reference. I am trying to do some shader-assignment that targets for a certain name in these rigs.

In my UI, if the user selects a certain color in the combobox, it will create a new shader and assign to the geos within that rig(s). And if it selects the first index of the combobox which is a blank, it will reassign those geos back to shaders that it was initially assigned.

For example, I have a test_geo (this is a reference) and it comes with a “test_geoShader (lambert)”. If I select any other color, the connect between the test_geo and test_geoShader will be disconnected and it will be assigned with a new shader, eg. newShader (lambert) If I select the ‘blanked’ option, it will disconnect test_geo with the new shader and assigned back to test_geoShader

However, my code (pls see below) only works on the first try to get the original assignment… Meaning to say if I open my UI the first time, did some new shader assignments, close and reopen my UI, it will pick up the current assignment it has as the original assignment…

Any suggestions in approaching this? And is it possible to do so without creating any new files (json etc…) to store the data?

def get_orig_shader(self, nodes_list):
    orig_shader_dict = {}
    for node_name in nodes_list:            
        node_shapes = get_shape(node_name)
        for node in node_shapes:
            if "defaultPtx" in node:
                shading_grps = cmds.listConnections(node, type='shadingEngine')
                shaders = cmds.ls(cmds.listConnections(shading_grps), materials=1)
                orig_shader_dict[node] = shaders[0]

Maybe you should keep the shading groups and only reconnect the shader balls to the SGs from your UI – that will leave the original structure intact and let you just swap visuals around. Giving the SGs meaningul names would also make it easier to provide UI feedback

[QUOTE=Theodox;30704]Maybe you should keep the shading groups and only reconnect the shader balls to the SGs from your UI – that will leave the original structure intact and let you just swap visuals around. Giving the SGs meaningul names would also make it easier to provide UI feedback[/QUOTE]

Hi Theodox, thanks for your reply.

Pardon my ignorance, but how do you go about assigning SGs to the geos?
To the best of my knowledge, I am only aware of the following command: cmds.hyperShade(assign=“Name of the shader”)

The SG’s are already assigned; they are the link between a collection of geometry and a shader. If you reassign the outcolor of the shading groups to different shaders you’ll preserve the grouping of components and only change the visual appearance