is there a pyMel or python solution akin to the mel script "findRelatedSkinCluster"

842 views
Skip to first unread message

GerardVOK

unread,
Feb 3, 2011, 1:41:41 AM2/3/11
to python_inside_maya
Hi. I am looking for a way to determine the skinCluster that is
related to a mesh. Maya came with a "findRelatedSkinCluster" mel
script, but doesnt have this as a py script. I will end up writing my
own procedure but unlike my Mel experience, I am very new to python
and this will take some time. I guess I could always run the mel
script in the python script but that just seems dirty..

If there is anyone out there who may have a solution, I would
appreciate your help.

Thanks
Gerard Van Ommen
Australia

Leonid Onokhov

unread,
Feb 3, 2011, 1:49:41 AM2/3/11
to python_in...@googlegroups.com
You can run mel from python:
import maya.mel as mel
mel.eval('findRelatedSkinCluster '+name_of_mesh)


Gerard van Ommen Kloeke

unread,
Feb 3, 2011, 1:52:51 AM2/3/11
to python_in...@googlegroups.com
I'll probably go that route due to time and experience, but I will write something in py eventually (and post)
Thanks for the help

Ted Charlton

unread,
Feb 3, 2011, 2:36:15 AM2/3/11
to python_in...@googlegroups.com
shps = mc_.listRelatives(s=True, ni=True)
for sh in shps:
    scs = mc_.ls(type='skinCluster')
    for sc in scs:
        mesh = mc_.skinCluster(sc, q=True, g=True)
        if mesh[0] == shps[0]:
            relatedSkinCluster = sc
            print relatedSkinCluster

GVOK,

Maybe this can help.
Cheers.


Ted Charlton

unread,
Feb 3, 2011, 2:40:21 AM2/3/11
to python_in...@googlegroups.com
little weak...


shps = mc_.listRelatives(s=True, ni=True)
for sh in shps:
    scs = mc_.ls(type='skinCluster')
    for sc in scs:
        mesh = mc_.skinCluster(sc, q=True, g=True)
        if mesh[0] == sh:

            relatedSkinCluster = sc
            print relatedSkinCluster

Better.

Paul Molodowitch

unread,
Feb 3, 2011, 3:57:00 AM2/3/11
to python_in...@googlegroups.com
Unless there's a reason why the mel function doesn't fit your needs (ie, it doesn't return unique names, or you need to customize it in some way), or you're using it as a learning exercise, I'd advise just using the mel.  Whether it's "dirty" is a matter of opinion, but using mel in python is something you'll have to get used to.  A lot of maya is built on mel, and I don't see that changing anytime soon; and as long as that is the case, there will always be situations where you'll need to call out to mel scripts.
If you're worried about things looking untidy, pymel can handle some of the string processing to make mel functions seem more pythonic:

import pymel.core as pm
res = pm.mel.findRelatedSkinCluster()

That's a pretty simplistic example, since there's no args, but it will also automatically convert args, keyword args, lists, and other things - see the docs for more info:


Of course, under the hood, it's still doing string processing, then calling mel.eval, so the 'dirtiness' is still there; it's just sort of swept under the carpet. =)

- Paul

PS - Oh, and if you need access to mel global variables, there's also a melGlobals dictionary-like object:


Gerard Van Ommen

unread,
Feb 3, 2011, 6:16:44 PM2/3/11
to python_in...@googlegroups.com
Hi Ted. Thanks for the help. your version is similar but more succinct than the mel script version. I was stuck in the 'parse through the connections', but matching the list of skinclusters to the shape in question is the way to go. This will do perfectly.

BTW are you Ted Charlton formerly of Alias? If so then, how are things? Its been years!  Tim R is here in Sydney also.

Gerard (Gerry) van Ommen Kloeke

Gerard Van Ommen

unread,
Feb 3, 2011, 6:19:17 PM2/3/11
to python_in...@googlegroups.com
Thanks for the info Paul. Yeah this mel script is too simplistic to use through pyMel, and warrants writing in pymel (as Ted has kindly done) but I will certainly keep it in mind for situations where I need to eval a mel script in pymel.


stephenkmann

unread,
Feb 3, 2011, 7:31:50 PM2/3/11
to python_in...@googlegroups.com
I'm barely starting to dip my toes into python, but I thought I'd throw this out there. you might be able to get what you want using the python equivalent of  listConnections.

MEL:
listConnections -type "skinCluster" boundObjectShape;


( there is a python equivalent to "listConnections"  right? )

hth

-=smann




Count Zer0

unread,
Feb 5, 2011, 2:29:27 PM2/5/11
to python_inside_maya
PyMEL's listHistory method works well:

PyNode('myMesh').listHistory(type="skinCluster")

-jason


On Feb 3, 4:31 pm, stephenkmann <stephenkm...@gmail.com> wrote:
> I'm barely starting to dip my toes into python, but I thought I'd throw this
> out there. you might be able to get what you want using the python
> equivalent of  listConnections.
>
> MEL:
> listConnections -type "skinCluster" boundObjectShape;
>
> ( there is a python equivalent to "listConnections"  right? )
>
> hth
>
> -=smann
>
> On Thu, Feb 3, 2011 at 6:19 PM, Gerard Van Ommen <gerard...@gmail.com>wrote:
>
>
>
>
>
>
>
> > Thanks for the info Paul. Yeah this mel script is too simplistic to use
> > through pyMel, and warrants writing in pymel (as Ted has kindly done) but I
> > will certainly keep it in mind for situations where I need to eval a mel
> > script in pymel.
>
> > On Thu, Feb 3, 2011 at 7:57 PM, Paul Molodowitch <elron...@gmail.com>wrote:
>
> >> Unless there's a reason why the mel function doesn't fit your needs (ie,
> >> it doesn't return unique names, or you need to customize it in some way), or
> >> you're using it as a learning exercise, I'd advise just using the mel.
> >>  Whether it's "dirty" is a matter of opinion, but using mel in python is
> >> something you'll have to get used to.  A lot of maya is built on mel, and I
> >> don't see that changing anytime soon; and as long as that is the case, there
> >> will always be situations where you'll need to call out to mel scripts.
> >> If you're worried about things looking untidy, pymel can handle some of
> >> the string processing to make mel functions seem more pythonic:
>
> >> import pymel.core as pm
> >> res = pm.mel.findRelatedSkinCluster()
>
> >> That's a pretty simplistic example, since there's no args, but it will
> >> also automatically convert args, keyword args, lists, and other things - see
> >> the docs for more info:
>
> >>http://www.luma-pictures.com/tools/pymel/docs/1.0/generated/classes/p...
>
> >> <http://www.luma-pictures.com/tools/pymel/docs/1.0/generated/classes/p...>Of
> >> course, under the hood, it's still doing string processing, then calling
> >> mel.eval, so the 'dirtiness' is still there; it's just sort of swept under
> >> the carpet. =)
>
> >> - Paul
>
> >> PS - Oh, and if you need access to mel global variables, there's also a
> >> melGlobals dictionary-like object:
>
> >>http://www.luma-pictures.com/tools/pymel/docs/1.0/generated/classes/p...
>
> >> On Wed, Feb 2, 2011 at 11:40 PM, Ted Charlton <ted.charl...@gmail.com>wrote:
>
> >>> little weak...
>
> >>> shps = mc_.listRelatives(s=True, ni=True)
> >>> for sh in shps:
> >>>     scs = mc_.ls(type='skinCluster')
> >>>     for sc in scs:
> >>>         mesh = mc_.skinCluster(sc, q=True, g=True)
> >>>         if mesh[0] == sh:
> >>>             relatedSkinCluster = sc
> >>>             print relatedSkinCluster
>
> >>> Better.
>
> >>> On Wed, Feb 2, 2011 at 11:36 PM, Ted Charlton <ted.charl...@gmail.com>wrote:
>
> >>>> shps = mc_.listRelatives(s=True, ni=True)
> >>>> for sh in shps:
> >>>>     scs = mc_.ls(type='skinCluster')
> >>>>     for sc in scs:
> >>>>         mesh = mc_.skinCluster(sc, q=True, g=True)
> >>>>         if mesh[0] == shps[0]:
> >>>>             relatedSkinCluster = sc
> >>>>             print relatedSkinCluster
>
> >>>> GVOK,
>
> >>>> Maybe this can help.
> >>>> Cheers.
>
> >>>> On Wed, Feb 2, 2011 at 10:52 PM, Gerard van Ommen Kloeke <
> >>>> gerard...@gmail.com> wrote:
>
> >>>>>  I'll probably go that route due to time and experience, but I will
> >>>>> write something in py eventually (and post)
> >>>>> Thanks for the help
>
> >>>>> You can run mel from python:
> >>>>> import maya.mel as mel
> >>>>> mel.eval('findRelatedSkinCluster '+name_of_mesh)
>

Juan Pablo

unread,
Oct 30, 2016, 9:17:49 PM10/30/16
to Python Programming for Autodesk Maya
Hi Gerard,

This is Juan Pablo,  one of your students at UTS in Animation. I'm looking for some help with Python or MEL script to automate a process in Maya and I'm wonder if you could help me. 



Please let me know.


Thanks
Reply all
Reply to author
Forward
0 new messages