Hi all, I was wondering if someone could kindly direct me on this and perhaps how I should do it?
Say if I have a model (with lots of polygon), and I am trying to grab some specified pieces of geometry that has ‘defaultPaint’ embedded in their naming…
While I can use cmds.ls(‘defaultPaint’) to filter them out, at the same time, I would also like to grab its shaders (each piece of geo has its own shader) in which I will have this UI that shows a list of colors, and as I change the options within a combobox perhaps, eg. from their default red color, and I selected ‘yellow’, it will reflect the changes in their shaders but as well as in the viewport real-time.
How should I approach in doing so?
Currently for my UI, I have a QTableWidget of 2 columns, first column that denotes the models in the scene, and the second column populated by a QComboBox is filled with the color options stemming from a json file that specifically states the different colors given to the model.
So far, I have succedded in populating thses 2 columns, however getting the changes to be in effect in real-time is lacking for me.
I can try using a QPushButton and hardcode it, along with the attributes of the color etc but that is not effective and not really real-time since it can only happens upon a click on the push button.
Any insights?
This is a portion of the code that I have did…
def get_all_mesh():
all_mesh = cmds.listRelatives(cmds.ls(type = 'mesh'), parent=True)
# Result: [u'pCube1', u'pSphere1', u'pPlane1'] #
return all_mesh
def get_color(node_name):
# checks if the node_name exists in the json file
with open('/Desktop/colors.json') as data_file:
data = json.load(data_file)
items = set()
for index, name in enumerate(data):
# if the name is in the json, it will states the color
if node_name in name:
for item in (data[name]):
#print "{0} - {1}".format(name, item)
items.add(item)
return items
class testTableView(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setWindowTitle('Color Test')
self.setModal(False)
self.all_mesh = get_all_mesh()
# Build the GUI
self.init_ui()
self.populate_data()
def init_ui(self):
# Table setup
self.mesh_table = QtGui.QTableWidget()
self.mesh_table.setRowCount(len(self.all_mesh))
self.mesh_table.setColumnCount(3)
self.mesh_table.setHorizontalHeaderLabels(['Mesh Found', 'Color for Mesh'])
self.md_insert_color_btn = QtGui.QPushButton('Apply color')
# Layout
self.layout = QtGui.QVBoxLayout()
self.layout.addWidget(self.mesh_table)
self.layout.addWidget(self.md_insert_color_btn)
self.setLayout(self.layout)
def populate_data(self):
geo_name = self.all_mesh
for row_index, geo_item in enumerate(geo_name):
new_item = QtGui.QTableWidgetItem(geo_item)
# Add in each and every mesh found in scene and append them into rows
self.mesh_table.setItem(row_index, 0, new_item)
geo_exclude_num = ''.join(i for i in geo_item if not i.isdigit())
color_list = get_color(geo_exclude_num)
# Insert in the color
combobox = QtGui.QComboBox()
#color_list = get_color()
combobox.addItems(list(color_list))
self.mesh_table.setCellWidget(row_index, 1, combobox)
# To opent the dialog window
dialog = testTableView()
dialog.show()