Home Coding, Scripting, Shaders

Needing some help with MEL Script~

polycounter lvl 4
Offline / Send Message
Zunabi polycounter lvl 4
Hello lovely peeps,
  I'm very new to writing scripts but have always wanted to get more into it!
I'm currently trying to write a MEL script that selects all objects with the suffix of hg in the mesh name, adds the existing lambert to all, polySoftEdges everything, deletes input history, and cleans up the scene. I've added the lambert mat part specifically due to work reasons heh-

I'm having problems with trying to figure out a way to get polySoftEdge to work. Currently when I run this script:
select -r "hg*";
sets -e -forceElement initialShadingGroup;
polySoftEdge -a 180 -ch 1;
delete -ch;
performCleanUpScene()

it gives me the Error of how line 3 Doesn't work with multiple objects selected.

Is there a way to get around this?

Much appreciated and thank you for your time~
  Zuna

Replies

  • Zunabi
    Options
    Offline / Send Message
    Zunabi polycounter lvl 4
    Or better yet, if easier to do in python (tho I haven't figured out how to translate sets -e -forceElement initialShadingGroup into python yet..)
    import maya.cmds as cmds
    import maya.mel as mel
    cmds.select("*hg*");
    models = cmds.ls(sl=True)
    for m in models:
        cmds.polySoftEdge( a=180 );
    cmds.delete(all=True, ch=True);
    mel.eval("cleanUpScene 3")

    It still does the same thing with the error of doesn't work with multiple objects selected.
    Either response in MEL or Python would be much appreciated~
  • neilberard
    Options
    Online / Send Message
    neilberard polycounter lvl 17
    (Don't have access to Maya atm to test) but you can just select each mesh in your for loop. Also, you don't need semicolons in Python, FYI.
    for m in models:
        cmds.select(m)
        cmds.polySoftEdge(a=180)

  • ylke
    Options
    Offline / Send Message
    ylke polycounter lvl 6
    Try this
    import maya.cmds as cmds
    import maya.mel as mel
    
    #Get all the transform nodes that have hg in it's name
    geo_list = cmds.ls('*hg*',type='transform')
    
    #run through all the geometry
    for geo in geo_list:
        
        #Ch=0 so that the soft edge won't end up in history
        cmds.polySoftEdge(geo,a=180,ch=0)
        
        #Get shapes to assign material to
        geo_shp = cmds.listRelatives(geo,s=1)[0]
        cmds.sets(geo_shp, e=True, forceElement='initialShadingGroup')
    
    cmds.select(cl=1)
    mel.eval("cleanUpScene 3")


Sign In or Register to comment.