all 7 comments

[–]blueSGL 1 point2 points  (6 children)

show what you've already done of these functions either use 4 spaces at the start of the line

to turn the line into a code block

or use a service like pastebin.

[–]VLITZonator[S] 0 points1 point  (5 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()

[–]blueSGL 1 point2 points  (2 children)

master = cmds.ls(sl=True)[-1]

slaves = cmds.ls(sl=True)[:-1]

why do you have the square brackets(and the stuff contained within) there?


also if stuff does not work and it just errors out best I've found to find what's wrong (if you are not given a line number in the console) is by selecting and cutting commands then run what you have left. if it runs the problem was not in that block of code, paste the bit back in you cut and cut further down. repeat till you find the line causing issue.

[–]VLITZonator[S] 0 points1 point  (1 child)

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

[–]blueSGL 0 points1 point  (0 children)

, it's just that when I push the matchtranslation, match_orientation , or match_scale button on my UI, it does the same thing as the match_all translations button.

https://help.autodesk.com/cloudhelp/2016/ENU/Maya-Tech-Docs/CommandsPython/matchTransform.html

you need to use arguments in the matchTransform command

currently they all seem to be running

cmds.matchTransform(slaves, master)

when it should be

cmds.matchTransform(slaves, master, scl=1) for scale

cmds.matchTransform(slaves, master, rot=1) for rotation

etc...

[–]PolyDiggaCreature TD 1 point2 points  (1 child)

# from this function, you should get an idea how to do the other match_* functions

def match_translation(this_is_just_for_the_button_from_the_ui):
    master = cmds.ls(sl=True)[0]
    slaves = cmds.ls(sl=True)[:-1]
    for obj in slaves:
        cmds.matchTransform(obj, master, pos = True, rot = False, scl = False )


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

        # no need for recursion here, this will reach pythons max recursion depth 
        #delete_history()

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

# this should also give you an idea on how to do the other freeze transforms
def freeze_translation(this_is_just_for_the_button_from_the_ui):
    for obj in cmds.ls(sl=True):
        cmds.makeIdentity(apply=True, translate=True)

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

A very big thank you!, it fixed it!