parameters: (lstShadingEngines=None)
return_statement: return True
docstring: Workaround for Maya 2014/2015 bug.
      Ensures that ShadingEngines contain only faces, rather than full shapes.
      Alembic 1.1.5 contains a bug, so that it doesn't export FaceSets
      for objects where the entire shape is in the ShadingEngine.
docstring_summary: Workaround for Maya 2014/2015 bug.
      Ensures that ShadingEngines contain only faces, rather than full shapes.
      Alembic 1.1.5 contains a bug, so that it doesn't export FaceSets
      for objects where the entire shape is in the ShadingEngine.
docstring_tokens: Workaround for Maya 2014 / 2015 bug . Ensures that ShadingEngines contain only faces rather than full shapes . Alembic 1 . 1 . 5 contains a bug so that it doesn t export FaceSets for objects where the entire shape is in the ShadingEngine .
function: def enforcePerFaceAssignment(lstShadingEngines=None):
      '''
      Workaround for Maya 2014/2015 bug.
      Ensures that ShadingEngines contain only faces, rather than full shapes.
      Alembic 1.1.5 contains a bug, so that it doesn't export FaceSets
      for objects where the entire shape is in the ShadingEngine.
      '''
      if lstShadingEngines is None:
          lstShadingEngines = cmds.ls(type="shadingEngine")
      else:
          if isinstance(lstShadingEngines, basestring):
              lstShadingEngines = [lstShadingEngines]
      
      # cant apply per face assignment on standardSGs 
      lstShadingEngines = set(lstShadingEngines) - standardSGs
      
      if not lstShadingEngines:
          return False
      
      log.info("Enforcing per-face material assignment ...")
      
      for dgShadingEngine in lstShadingEngines:
          log.debug("  shadingEngine: " + dgShadingEngine)
          
          lstSetMembers = cmds.sets(dgShadingEngine, q=True)
          if not lstSetMembers:
              continue
          
          for sSetMember in lstSetMembers:
              if ".f[" not in sSetMember:
                  log.debug("  Converting shape-assignment to face-assignment: " + sSetMember)
                  # make sure sSetMember is a mesh!
                  meshMember = cmds.ls(cmds.listHistory(sSetMember), type='mesh')
                  if not meshMember:
                      log.debug('SetMember "%s" (from %s) did not yield a mesh!' % sSetMember, dgShadingEngine)
                      continue
                  meshMember = meshMember[0]
                  try:
                      #iFaceCount = cmds.polyEvaluate(meshMember, f=True)
                      #sFaces = meshMember + ".f[0:" + str(iFaceCount - 1) + "]"
                      sFaces = "%s.f[*]" % meshMember
                      # nasty hack: temporarily apply default material
                      # to generate objectGroup datastructures
                      if dgShadingEngine not in standardSGs:
                          cmds.sets("%s.f[0]" % meshMember, e=True, fe="initialShadingGroup")
                      cmds.sets(sFaces, e=1, fe=dgShadingEngine)
                      # remove original member from that we added all faces if still in
                      if cmds.sets(sSetMember, isMember=dgShadingEngine):
                          cmds.sets(sSetMember, rm=dgShadingEngine)
                  except StandardError, error:
                      log.error(error)
                      log.debug("Failed to all faces to material for object: " + sSetMember + "!")
                      log.debug(sys.exc_info())
  
          # fix for abc import which throws per face warnings if you have 
          # get connected visible shapes
          connMesh = set(cmds.ls(cmds.listConnections('%s.dagSetMembers' % dgShadingEngine, shapes=True), type='mesh'))
          connMesh = set([m for m in connMesh if not cmds.getAttr('%s.intermediateObject' % m)])
          shapeMembers = set(cmds.ls(lstSetMembers, s=True, dag=True, o=True))
          # find nodes connected to dagSetMembers but are not members
          nonMemberShapes = list(connMesh - shapeMembers)
          if nonMemberShapes:
              log.debug('ShadingEngine "%s" has false member connection to mesh shape: %s'
                        % (dgShadingEngine, ', '.join(nonMemberShapes)))
              # find out exact connection and disconnect
              for shape in nonMemberShapes:
                  conns = cmds.listConnections(shape, type='shadingEngine', c=True, p=True)
                  for i in range(1, len(conns), 2):
                      if conns[i].startswith('%s.dagSetMembers' % dgShadingEngine):
                          log.debug('unplugging "%s" from "%s"' % (conns[i - 1], conns[i]))
                          cmds.disconnectAttr(conns[i - 1], conns[i])
  
      return True
function_tokens: def enforcePerFaceAssignment ( lstShadingEngines = None ) : if lstShadingEngines is None : lstShadingEngines = cmds . ls ( type = "shadingEngine" ) else : if isinstance ( lstShadingEngines , basestring ) : lstShadingEngines = [ lstShadingEngines ] # cant apply per face assignment on standardSGs  lstShadingEngines = set ( lstShadingEngines ) - standardSGs if not lstShadingEngines : return False log . info ( "Enforcing per-face material assignment ..." ) for dgShadingEngine in lstShadingEngines : log . debug ( "  shadingEngine: " + dgShadingEngine ) lstSetMembers = cmds . sets ( dgShadingEngine , q = True ) if not lstSetMembers : continue for sSetMember in lstSetMembers : if ".f[" not in sSetMember : log . debug ( "  Converting shape-assignment to face-assignment: " + sSetMember ) # make sure sSetMember is a mesh! meshMember = cmds . ls ( cmds . listHistory ( sSetMember ) , type = 'mesh' ) if not meshMember : log . debug ( 'SetMember "%s" (from %s) did not yield a mesh!' % sSetMember , dgShadingEngine ) continue meshMember = meshMember [ 0 ] try : #iFaceCount = cmds.polyEvaluate(meshMember, f=True) #sFaces = meshMember + ".f[0:" + str(iFaceCount - 1) + "]" sFaces = "%s.f[*]" % meshMember # nasty hack: temporarily apply default material # to generate objectGroup datastructures if dgShadingEngine not in standardSGs : cmds . sets ( "%s.f[0]" % meshMember , e = True , fe = "initialShadingGroup" ) cmds . sets ( sFaces , e = 1 , fe = dgShadingEngine ) # remove original member from that we added all faces if still in if cmds . sets ( sSetMember , isMember = dgShadingEngine ) : cmds . sets ( sSetMember , rm = dgShadingEngine ) except StandardError , error : log . error ( error ) log . debug ( "Failed to all faces to material for object: " + sSetMember + "!" ) log . debug ( sys . exc_info ( ) ) # fix for abc import which throws per face warnings if you have  # get connected visible shapes connMesh = set ( cmds . ls ( cmds . listConnections ( '%s.dagSetMembers' % dgShadingEngine , shapes = True ) , type = 'mesh' ) ) connMesh = set ( [ m for m in connMesh if not cmds . getAttr ( '%s.intermediateObject' % m ) ] ) shapeMembers = set ( cmds . ls ( lstSetMembers , s = True , dag = True , o = True ) ) # find nodes connected to dagSetMembers but are not members nonMemberShapes = list ( connMesh - shapeMembers ) if nonMemberShapes : log . debug ( 'ShadingEngine "%s" has false member connection to mesh shape: %s' % ( dgShadingEngine , ', ' . join ( nonMemberShapes ) ) ) # find out exact connection and disconnect for shape in nonMemberShapes : conns = cmds . listConnections ( shape , type = 'shadingEngine' , c = True , p = True ) for i in range ( 1 , len ( conns ) , 2 ) : if conns [ i ] . startswith ( '%s.dagSetMembers' % dgShadingEngine ) : log . debug ( 'unplugging "%s" from "%s"' % ( conns [ i - 1 ] , conns [ i ] ) ) cmds . disconnectAttr ( conns [ i - 1 ] , conns [ i ] ) return True