def apply(self): directorys = self.get_source_paths(self.gridlayout) comment = '{} {} - preference container'.format( self.lable, self.version) created_date = datetime.now().strftime('%B/%d/%Y - %I:%M:%S:%p') description = 'This data contain information about shader library preference' type = 'preference' valid = True data = directorys tag = 'shader_library' resource_path = resources.getResourceTypes()[type] rw = readWrite.ReadWrite(c=comment, cd=created_date, d=description, t=type, v=valid, data=data, tag=tag, path=resource_path, name='library_preferences', format='json') rw.create() print '\n#result preferences updated ', rw.file_path self.close()
def create(self, assign, selected, fake=False): rw = readWrite.ReadWrite(t='shader_net') rw.file_path = self.path if fake: data = rw.get_info() return data data = rw.get_data() self.undoChunk('open') result = {True: None} maya_objects = [] if assign: # disconnect remove exists shading_engine for index, shader_data in data.items(): for objects in shader_data['geometries'].values(): exists_objects = [ each for each in objects if core.objExists(each)] maya_objects.extend(exists_objects) if selected: selected_objects = core.ls(sl=True) for object in selected_objects: try: shape_nodes = [ each.name() for each in object.getShapes()] except: shape_nodes = [] maya_objects.extend(shape_nodes) if maya_objects: # disconnect remove exists shading_engine self.disconnect_shader(maya_objects) for index, shader_data in data.items(): try: self.create_shader_net(shader_data, maya_objects) except Exception as error: result = {False: error} self.undoChunk('close') OpenMaya.MGlobal.executeCommand('undoInfo -closeChunk;') return result
def __init__(self, parent=platforms.get_qwidget()): super(MainWindow, self).__init__(parent) self.image_object = None self.width, self.height = [500, 500] self.publish_format = 'shader' self.image_format = 'png' self.tool_mode = 'publish' self.currnet_publish = None self.preference = preferences.Preference(parent=None) self.folder = studioFolder.Folder() self.studio_maya = studioMaya.Maya() self.catalogue = catalogue.Catalogue(parent=None) self.model = model.Model(parent=None) self.tool_kit_object, self.tool_kit_name, self.version = platforms.get_tool_kit( ) self.tool_kit_titile = '{} {}'.format(self.tool_kit_name, self.version) # to check the preferencees resource_path = resources.getResourceTypes()['preference'].encode() self.rw = readWrite.ReadWrite(t='preference', path=resource_path, format='json', name='library_preferences', tag='shader_library') self.library_paths = self.rw.get_library_paths() if cmds.dockControl(self.tool_kit_object, q=1, ex=1): cmds.deleteUI(self.tool_kit_object, ctl=1) self.setup_ui() self.set_icons() self.load_library_folders(self.treewidget) self.parent_maya_layout()
def save(self, file_path, name, image, user_comment=None): mobject_arrary = self.getObjectShadingEngine(self.geometry_dag_path) net_data = {} for index in range(mobject_arrary.length()): valid = self.hasValidShadingEngine( mobject_arrary[index], object=self.geometry_dag_path) if not valid: continue shader_data = self.get_shader_net(mobject_arrary[index]) net_data.setdefault(index, shader_data) comment = '%s %s - shader networks' % ( self.tool_kit_name, self.version) if user_comment: comment = '%s %s - shader networks\n%s' % ( self.tool_kit_name, self.version, user_comment) created_date = datetime.now().strftime('%Y/%d/%B - %I:%M:%S:%p') description = 'This data contain information about maya shader networks' type = 'shader_net' valid = True data = net_data tag = self.tool_kit_object rw = readWrite.ReadWrite( c=comment, cd=created_date, d=description, t=type, v=valid, data=data, tag=tag, path=file_path, name=name, format='shader') result, shader_path = rw.create() if False in result: return result studio_image = studioImage.ImageCalibration( path=file_path, name=name, format='png') image_path = studio_image.writeImage(image) print '\nresult', shader_path, image_path return result
def create_preference(self): comment = '{} {} - preference container'.format( self.lable, self.version) created_date = datetime.now().strftime('%B/%d/%Y - %I:%M:%S:%p') description = 'This data contain information about shader library preference' type = 'preference' valid = True data = {} tag = 'shader_library' resource_path = resources.getResourceTypes()[type].encode() rw = readWrite.ReadWrite(c=comment, cd=created_date, d=description, t=type, v=valid, data=data, tag=tag, path=resource_path, name='library_preferences', format='json') self.bundles = rw.get_data() if not self.bundles: rw.create() print '\n#result new preferences created ', rw.file_path
def had_valid(self, publish_file): rw = readWrite.ReadWrite(t='shader_net') rw.file_path = publish_file result = rw.has_valid() return result
def had_file(self, dirname, name): rw = readWrite.ReadWrite( path=dirname, name=name, format='shader', t='shader_net') return rw.has_file()