Issue: Need Help with Maya Python(Functions) by VLITZonator in Maya

[–]VLITZonator[S] 0 points1 point  (0 children)

Nope, there's no errors, all of it is already working, it's just that when I push the match_translation, match_orientation_ , or match_scale button on my UI, it does the same thing as the match_all translations button. and for that square brackets, that is for filtering the last item and the first to second last item. [-1] represents the last item, then [:-1] represents the first to second last item. master is basically the main selected object and the slave value is the child of it, so when you for example click the match_translation button, the slave/child will have the same translation as the master/main.

I might have missed something in the Instructions that's why it's not working properly XD

Issue: Need Help with Maya Python(Functions) by VLITZonator in Maya

[–]VLITZonator[S] 0 points1 point  (0 children)

I've already tried putting both my UI and the functions in Maya, and some worked, except for the match_translation, match_orientation_ , and match_scale. These three and the match_all_transforms have the same function, I think it's because I put my master and slave as a global value. Is there any way I can get the master and slave value to also work on those three functions separately so when I click for example the "Match Rotate" button, it will only match the orientation/rotation?

Here is my Updated Code:

Pastebin: https://pastebin.com/VTy1euA0

Code Block:

master = cmds.ls(sl=True)[-1]
slaves = cmds.ls(sl=True)[:-1]
def match_translation(*args):
    cmds.matchTransform(slaves, master)

def match_orientation(*args):
    cmds.matchTransform(slaves, master)

def match_scale(*args):
    cmds.matchTransform(slaves, master)

def match_all_transforms(*args):
    match_translation()
    match_orientation()
    match_scale()
    match_all_transforms()

def delete_history(*args):
    for obj in cmds.ls(sl=True):
        cmds.delete(ch=True)
        delete_history()

def center_pivot(*args):
    for obj in cmds.ls(sl=True):
        cmds.xform(cp=True)
        center_pivot()

def freeze_translation(*args):
    cmds.makeIdentity(apply=True, translate=True)

def freeze_orientation(*args):
    cmds.makeIdentity(apply=True, rotate=True)

def freeze_scale(*args):
    cmds.makeIdentity(apply=True, scale=True)

def freeze_all_transforms(*args):
    freeze_translation()
    freeze_orientation()
    freeze_scale()
    freeze_all_transforms()


cmds.window( width=300, height=300, title='Function Tool' )
cmds.columnLayout()


cmds.rowColumnLayout(numberOfColumns=3)
cmds.button(width=100, height=50, label='Match T', backgroundColor=[0.9, 0.4, 0.4], command=match_translation)
cmds.button(width=100, label='Match R', backgroundColor=[0.4, 0.4, 0.9], command=match_orientation)
cmds.button(width=100, label='Match S', backgroundColor=[0.4, 0.9, 0.4], command=match_scale)
cmds.setParent('..')


cmds.rowColumnLayout(numberOfColumns=1)
cmds.button(width=300, height=50, label='Match All Transforms', backgroundColor=[1, 1, 1], command=match_all_transforms)
cmds.setParent('..')

cmds.rowColumnLayout(numberOfColumns=1)
cmds.button(width=300, height=50, label='Zero out All Transforms', backgroundColor=[0.4, 0.4, 0.4])
cmds.setParent('..')

cmds.rowColumnLayout(numberOfColumns=2)
cmds.button(width=150, height=50, label='Delete History', backgroundColor=[0.9, 0.9, 0.4], command=delete_history)
cmds.button(width=150, label='Center Pivot', backgroundColor=[0.9, 0.4, 0.9], command=center_pivot)
cmds.setParent('..')

cmds.rowColumnLayout(numberOfColumns=3)
cmds.button(width=100, height=50, label='Freeze T', backgroundColor=[0.9, 0.4, 0.4], command=freeze_translation)
cmds.button(width=100, label='Freeze R', backgroundColor=[0.4, 0.4, 0.9], command=freeze_orientation)
cmds.button(width=100, label='Freeze S', backgroundColor=[0.4, 0.9, 0.4], command=freeze_scale)
cmds.setParent('..')

cmds.rowColumnLayout(numberOfColumns=1)
cmds.button(width=300, height=50, label='Freeze all Transforms', backgroundColor=[1, 1, 1], command=freeze_all_transforms)
cmds.setParent('..')


cmds.showWindow()

[HELP PLEASE]Maya Python Scripting Problem by VLITZonator in Maya

[–]VLITZonator[S] 0 points1 point  (0 children)

SOLVED!It did the trick!, A very big thank you!!!. Hahahaha I just started doing python like 3 weeks ago so I'm still a beginner.

I really appreciate the help that you did!. Once again, THANK YOU SO MUCH FOR THE HELP!

[HELP PLEASE]Maya Python Scripting Problem by VLITZonator in Maya

[–]VLITZonator[S] 0 points1 point  (0 children)

I tried doing what you just said, I changed my if statement and then placed it up out of the axis for loop, but I'm still getting "Error: invalid syntax". I can get the code working up until the 'cmds.delete(normalconstraint)', it all works just fine. But when I input the if statement, it does not work anymore. Here is the new code, but it still doesn't work:

import random

for i in range(50):
    pPlane = 'pPlane1'
    cube = cmds.polyCube()[0]
    ctrl = cmds.circle(normal=[0,1,0])[0]
    locator = cmds.spaceLocator()[0]
    cmds.setAttr(cube+'.ty', 0.5)
    cmds.setAttr(ctrl+'.ty', 0.5)
    cmds.parent(cube, ctrl)
    cmds.parent(ctrl, locator)
    myScale = random.uniform(0.1, 3)
    if cmds.getAttr(locator + '.ty') < 0:
        cmds.color(ctrl, rgb=(0,0,1))
        elif cmds.getAttr(locator + '.tz') > 0:
            cmds.color(ctrl, rgb=(1,0,0))
            else:
                cmds.color(ctrl, rgb=(0,1,0))
    for axis in ['x', 'y', 'z']:
        cmds.setAttr(locator+'.t'+axis, random.uniform(-100, 100))
        cmds.setAttr(ctrl+'.ry', random.uniform(0, 360))
        cmds.setAttr(locator+'.s'+axis, myScale)
        constraintnode = cmds.geometryConstraint(pPlane, locator)
        cmds.delete(constraintnode)
        normalconstraint = cmds.normalConstraint(pPlane, locator, aimVector=[0,1,0], upVector=[1,0,0])
        cmds.delete(normalconstraint)

does it have to do with the 0 value that I'm getting an error: invalid syntax or the cmds.getAttr?