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]
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]
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/785548cf-e276-433b-aaf8-6e8462a295a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hey Justin, correct me if I am wrong on this..So while I did try using global dictionary, it only works on the first try too, but as soon as I close and reopen my UI, the original assignment is gone.. Giving me the same issue as stated in my thread.I must be doing something very wrong in my logic and if possible, could you kindly enlighten me on this?
some_persistent_dict = {}
...
entry = 'node_name'
if not entry in some_persistent_dict:
# We have never recorded the original shader.
some_persistent_dict[entry] = get_original_shader(entry)
# Standard behavior
assign_new_shader(entry)
Hope this helps
I suppose using of json files work but if can be, I would not want to introduce in a new file creation which is solely just for containing the assignments.Will need to check up on optionsVars to see if it caters to my need
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/27ee5537-6bdc-48c3-abb0-dacc403af448%40googlegroups.com.
cur_keytext_in_dict = {'|Stack|model_from_groupA|group_01|model_A_roof_grp|model_A_roof_geoShape':'brick_shader','|Stack|model_from_groupB|group_01|model_B_roof_grp|model_B_roof_geoShape':'brick_shader'}
'|Stack|model_B|group_01|model_A_roof_grp|model_A_roof_geoShape', '|Stack|model_A|group_01|model_B_roof_grp|model_B_roof_geoShape'
cur_keytext_in_dict = {'|Stack|model_from_groupA|group_01|model_A_roof_grp|model_A_roof_geoShape':'brick_shader','|Stack|model_from_groupB|group_01|model_B_roof_grp|model_B_roof_geoShape':'brick_shader'}
cur_name_in_scene = ['|Stack|model_A|group_01|model_A_roof_grp|model_A_roof_geoShape', '|Stack|model_B|group_01|model_B_roof_grp|model_B_roof_geoShape']
for split_name in cur_name_in_scene:
split_check = split_name.split("|", 4)[4]
# result :
model_A_roof_grp|model_A_roof_geoShape, model_B_roof_grp|model_B_roof_geoShape--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/00ad98d1-389d-49c0-ab92-a3892e74df0e%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.