Stop Staring Script Fixes for Maya 2013(+)

During last production I discovered that the Pin Script provided with Jason Osipa’s stop staring 3rd edition causes Maya 2013 to crash and that the Invert Weight (blendshape) doesn’t work.
This post is just a note on how to fix them. I apologize if there will be some python formatting issues but i’m still fighting with wordpress to find a proper way to post some code.

The Pin script problem is caused by the asIntPtr function in the MScriptUtil class.
The code should be modified from this:

#[Line 49 of ss3Pin.py]
xp = om.MPoint()
rt = om.MPoint()
pt = om.MScriptUtil().asIntPtr()
ov = om.MIntArray()

for snap in sel:
    pos = mc.xform( snap, q=1,ws=1,t=1 )
    ps = om.MPoint( pos[0], pos[1], pos[2], 0.0 )
    mMesh.getClosestPoint( ps, rt, om.MSpace.kWorld, pt )
    ht = om.MScriptUtil( pt ).asInt()

to this:


#[Line 49 of ss3Pin.py]
xp = om.MPoint()
rt = om.MPoint()
ov = om.MIntArray()
for snap in sel:
    pos = mc.xform( snap, q=1,ws=1,t=1 )
    su=om.MScriptUtil(0)
    pt=su.asIntPtr()
    ps = om.MPoint( pos[0], pos[1], pos[2], 0.0 )
    mMesh.getClosestPoint( ps, rt, om.MSpace.kWorld, pt )
    ht=su.getInt(pt)

About the invert script i’ll paste only the fixed code. The problem is related to the getAttr that shoud return all the weights of the blendshape. I noticed that it returns only the weights that has been modified.


def inverse():
    #doc Inverses the weighting of any blendShape sliders set over 0.5
    sel = mc.ls( sl = True )
    blendShape = utl.getType( 'blendShape' )
    print 'Working with blendShape:',blendShape
    toInverse = [ i for i in range( len( utl.getWeights( blendShape, False ) ) ) ]
    mc.select( mc.ls( mc.listHistory( blendShape, future = True ), type = 'shape' )[0] )
    copyWeightsPrep()
    for ti in toInverse:
        if mc.getAttr( blendShape + '.weight[%d]' % ti ) >= 0.5:
            print 'ss3TargetWgts.inverse: Inversing %s.weight[%d]' % ( blendShape, ti )
            for vtx in range(0,len(mc.ls(mc.polyListComponentConversion(sel,toVertex=1)[0],fl=1))):
            originalValue=mc.getAttr( blendShape + '.inputTarget[0].inputTargetGroup[%d].tw[%d]' % (ti,vtx))
            mc.setAttr(blendShape+'.inputTarget[0].inputTargetGroup[%d].targetWeights[%d]' % (ti,vtx), 1 -originalValue)
        else:
            print 'ss3TargetWgts.inverse: Skipping %s.weight[%d]' % ( blendShape, ti )
    if utl.listLenIf( sel ):
        mc.select( sel )
    else:
        mc.select( clear = True )

14 Responses

  1. Hi don’t know much about python, but when I copy your changes for ss3pin.py and try to run it in Maya 2012, I get this error:

    # Error: IndentationError: unexpected indent

    I’m guessing it a problem with how this site formats text. Any help?

    1. Hi Cal,
      you should check that every line is indented whith a tab. I can imagine the problem is exactly how wordpress formats the code.
      Bozo

  2. First off, thank you SO much for posting this! I am creating an animated short for my thesis that relies on a lot of facial animation and I have my heart set on creating non-additive blend shapes in order to accomplish this.

    I have run into a few strange but seemingly small issues. I am testing this using the square and circle demo that he goes over in the book. Let me run you through some initial steps i am taking to see if you can find where I am going wrong:

    Create the blendshape, set its weight to 1, go into the paint blend shape weights tool options, the default option does not have me painting on the actual blend shape, so i change that section to be the blend shape (the book doesn’t mention this is it a new feature in 2013? I feel like this could be where I am at fault but painting the other object leads to the inverse tool not working at all) I then paint away half of the circle to get to the square base object. The paint tool is a little buggy here leading me to believe that maybe I am painting on the wrong object as mentioned above. It takes a few clicks in order to set the weights to 0, even though my tool options are set to replace and 0. Regardless, I get there eventually, it just takes patience. The next step is to inverse this selection-

    For some reason when I inverse the selection it does flip the weights, however it does not do it evenly. At first I thought it had actually worked but a closer look proved me wrong.

    These are the steps that are confusing me, I seem to be close, and the mirror weights tool that I would have to use down the line seems to work with no problems so I just have to get past these first few issues. Any suggestions would be utterly fantastic and greatly appreciated. Perhaps something that changed in maya 2013 that was not mentioned in the book? Thanks again for sharing your script!

  3. Thanks a TON for this!
    Works in Maya 2016 as well.
    Was banging my head against the wall as I couldn’t find a way to get this to work.

  4. Im trying to fix the Invert script to work in maya 2016 with the above edits, and i get this error
    “# Error: expected an indented block
    # File “”, line 92
    # originalValue=mc.getAttr( blendShape + ‘.inputTarget[0].inputTargetGroup[%d].tw[%d]’ % (ti,vtx))
    # ^
    # IndentationError: expected an indented block # ”

    anyone still around to help?

    thanks

    1. It rather seems Python complaining about the way the code is aligned… don’t have anymore the files to help you but do check the indentation!

  5. Maybe i’m adding you fix wrong.
    I’m i to replace all the lines of code or just the one that is different?
    this line “mc.setAttr(blendShape+’.inputTarget[0].inputTargetGroup[%d].targetWeights[%d]’ % (ti,vtx), 1 -originalValue)”

    is the only one that is different from the original. here is the original
    “[ mc.setAttr(blendShape+’.inputTarget[0].inputTargetGroup[%d].targetWeights[%d]’ % ( ti, i ), 1 – weightVals[ i ] ) for i in range( size ) ]”

    There are a set of brackets and a little more line to the code.

    thanks

    1. I see now there multiple lines that are different.
      thanks for the help, i’ll keep trying to see if i can figure it out.

  6. Hello, I recently purchased this book and came across this issue and have been looking for a solution. I’m new to scripts. Can anyone tell me where I should put the fixed code for the invert script please?

Leave a Reply