scriptJob to assign material

477 views
Skip to first unread message

Aren Voorhees

unread,
Oct 7, 2014, 3:32:32 PM10/7/14
to python_in...@googlegroups.com
Hey All, I'm trying to use pymel to create a scriptJob that will assign a particular material to whatever object(s) you have selected.  When you select something else, I need the previously selected objects to switch back their original material.  Making it assign a material based on selection was not too hard, but I haven't been able to figure out how to re-assign the original material once the object is no longer selected.  Thanks for any help!

from pymel.core import *

def assignBlueMatFn():
    
    curSel = ls(sl=True)
    
    for i in curSel:
        hyperShade(i, assign='Blue_MAT')
        
scriptJob(event=['SelectionChanged', 'assignBlueMatFn()']) 

Justin Israel

unread,
Oct 7, 2014, 8:21:19 PM10/7/14
to python_in...@googlegroups.com

Maybe you would need to keep a record of the last objects you had changed and their previous setting. Then each time the condition fires, you would reset all of the last objects that aren't in the current selection.

--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/cb1e5b7e-b8a7-45fe-ae71-1e6af723ce11%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Oct 8, 2014, 2:19:46 AM10/8/14
to python_in...@googlegroups.com
Is this for a rig? E.g. animators select part of the mesh for visual feedback? It's actually quite cool, but sadly I've only seen this used once before. 8 years ago, in The Art Of Rigging by Cg Toolkit.

Their site is down, but they go through how they do it on one of their dvd, possibly vol 1. Maybe that could help. And if not, the series is amazing and should be viewed anyway.


For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Aren Voorhees

unread,
Oct 11, 2014, 9:55:33 PM10/11/14
to python_in...@googlegroups.com
Thanks Justin and Marcus - 

Yep, that's exactly what I'm planning to use it for.  I actually have The Art Of Rigging book laying right in front of me right now - I was lucky enough that someone happened to lend it to me a few months ago, although I hadn't had the chance to look through it yet.  I'll definitely check it out and report back if I find a good way of doing it.   

My quick and dirty way so far was to create a list of all the objects I'll be using as selectable meshes and assigning a transparent material to them all via scriptJob, then assigning a different visible material to any selected objects using the same scriptJob.  I bet that's pretty inefficient though.   


On Wednesday, October 8, 2014 1:19:46 AM UTC-5, Marcus Ottosson wrote:
Is this for a rig? E.g. animators select part of the mesh for visual feedback? It's actually quite cool, but sadly I've only seen this used once before. 8 years ago, in The Art Of Rigging by Cg Toolkit.

Their site is down, but they go through how they do it on one of their dvd, possibly vol 1. Maybe that could help. And if not, the series is amazing and should be viewed anyway.
On 8 October 2014 01:21, Justin Israel <justin...@gmail.com> wrote:

Maybe you would need to keep a record of the last objects you had changed and their previous setting. Then each time the condition fires, you would reset all of the last objects that aren't in the current selection.

On 8/10/2014 8:32 AM, "Aren Voorhees" <are...@gmail.com> wrote:
Hey All, I'm trying to use pymel to create a scriptJob that will assign a particular material to whatever object(s) you have selected.  When you select something else, I need the previously selected objects to switch back their original material.  Making it assign a material based on selection was not too hard, but I haven't been able to figure out how to re-assign the original material once the object is no longer selected.  Thanks for any help!

from pymel.core import *

def assignBlueMatFn():
    
    curSel = ls(sl=True)
    
    for i in curSel:
        hyperShade(i, assign='Blue_MAT')
        
scriptJob(event=['SelectionChanged', 'assignBlueMatFn()']) 

--
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 python_inside_maya+unsub...@googlegroups.com.

--
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 python_inside_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Reply all
Reply to author
Forward
0 new messages