On Fri, Oct 7, 2016 at 2:08 PM likage <[email protected]> wrote:

> 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?
>
Well the fact of the matter is that you would have to persist this
information somewhere, right? There are a ton of places to store this
information, but it also depends on whether you need this persistent to
outlive the current Maya session?

global dictionary in your module
optionVars
files (json, ...)
custom attribute on the node to store the original value

The last one could be useful, because it would obviously be stored directly
on the node in which you are considering. And you could check to see if the
custom attribute exists to know whether you have ever applied a change with
your UI.

>
> 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]
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/785548cf-e276-433b-aaf8-6e8462a295a4%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/785548cf-e276-433b-aaf8-6e8462a295a4%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1%3DWTwtXc9Tv19p6kZ61bHt8w7KrS_KXLQ3AYb9ySSJqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to