Hello Chadrik,

Yes absolutely.

The certain shaders I mention are CGFX shaders and for some reason Maya 
crashes when trying to apply said shader in Batch although I may be using 
the wrong call to apply them. The full function below illustrates use-age 
of both the hypershade command and the CGFX application:

def createReplacementCgfx(material='', texturePaths={}, cgfxChannels={}, 
cgfxShaderPath=''):
        """ If we find a shaderFxShader type material we need to replace wiuth 
CGFX for export purposes """
        print 'Replacing shader with CGFX'
        #mel.eval('cgfxShader -fx "%s" ' %cgfxShaderPath)
        matName = str(material)
        shader = pm.listConnections(material, type='shadingEngine')[0]
        members = list(set(shader.members(flatten=True)))
        pm.delete(matName)
        print 'got members'

        if 'diffuse_layer0_texture' in texturePaths:
                newMat = pm.shadingNode('cgfxShader', asShader=True, 
name=matName)
                mel.eval('cgfxShader -e -fx "%s" %s;' %(cgfxShaderPath,newMat))

        for key in texturePaths:
                slot = cgfxChannels[key]
                texture = texturePaths[key]
                newFileNode = createFileNode()
                pm.setAttr('%s.fileTextureName' %newFileNode, texture, 
type='string')

                pm.connectAttr('%s.outColor'%newFileNode, 
'%s.%s'%(newMat,slot), force=True)
                print 'connected', newMat

        pm.select(members)
        pm.hyperShade(assign=newMat)
        print 'CGFX function complete'


Cheers,

Ben

On Tuesday, 1 December 2015 01:58:57 UTC+1, Chadrik wrote:
>
> Hi Ben,
> I just thought I'd mention that there are very few situations that I have 
> encountered where you need a maya gui session instead of a batch session 
> (you can even do openGL playblasts from a batch session).  You said that 
> you are using "certain shaders and the Hypershade functions which need 
> the maya GUI window open".  Can you tell us exactly what those are?  In 
> some cases there will be more direct routes than using hypershade functions 
> (for example, there is a hypershade proc for assigning shaders, but the 
> 'sets' command will also work), and in other cases you simply need to 
> source the appropriate hypershade mel script to ensure that the mel proc is 
> available.  Just a thought.
>
> -chad
>
>
>
>
> On Wed, Nov 25, 2015 at 6:42 AM Ben Hearn <[email protected] 
> <javascript:>> wrote:
>
>> Hey Marcus,
>>
>> Sorry to keep code from you guys. I am not sure how much I generally 
>> should post online since it is for work and the code is split up into 
>> serveal chunks in batch and separate files, but I will make it a bit 
>> clearer for you guys :) Hope it is a bit clearer now
>>
>> Also, my reply about sketchy file nodes, things like this happen a lot 
>> during development when people throw things around quickly or carelessly 
>> but being able to open it individually and not have it crash really threw 
>> me on it...
>>
>>
>> *set BATCH_CONVERT=%CGROOT%folder\export_units_wrapper.melset 
>> MAYA_EXE=C:\Program Files\Autodesk\Maya%MAYA_VERSION%\bin\maya.exe*
>>
>> The *MAYA_EXE *variable is simply the executable path to Maya2015
>> The *BATCH_CONVERT *variable is a mel wrapper that I pass into Maya when 
>> it boots that runs the python code I want it to :)
>>
>> mel code:
>> *python("import maya_run");*
>> *python("maya_run.main()");*
>>
>> *d is the result of splitting my dictionary up into chunks to process 
>> each bit individually:*
>>
>> def linch_dict_divider(raw_dict, num):
>>
>>      list_result = []
>>      len_raw_dict = len(raw_dict)
>>      if len_raw_dict > num:
>>              base_num = len_raw_dict / num
>>              addr_num = len_raw_dict % num
>>              for i in range(num):
>>                      this_dict = dict()
>>                      keys = list()
>>                      if addr_num > 0:
>>                              keys = raw_dict.keys()[:base_num + 1]
>>                              addr_num -= 1
>>                      else:
>>                              keys = raw_dict.keys()[:base_num]
>>                      for key in keys:
>>                              this_dict[key] = raw_dict[key]
>>                              del raw_dict[key]
>>                      list_result.append(this_dict)
>>
>>      else:
>>              for d in raw_dict:
>>                      this_dict = dict()
>>                      this_dict[d] = raw_dict[d]
>>                      list_result.append(this_dict)
>>
>>      return list_result
>>
>> -- 
>> 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] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkUa3AVtweJkHCkxOVP683y4t_ba6BHBTDEtr22%3DoVM9pQ%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkUa3AVtweJkHCkxOVP683y4t_ba6BHBTDEtr22%3DoVM9pQ%40mail.gmail.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/e8f82c8e-a92e-465a-b838-52b18219f72d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to