mottosso / cmdx

Fast and persistent subset of maya.cmds
https://mottosso.com/cmdx
BSD 2-Clause "Simplified" License
193 stars 36 forks source link

Auto offset group #69

Open mottosso opened 3 years ago

mottosso commented 3 years ago

Zero out translate/rotate channels by adding an intermediate parent group to hold those values. This can be preferable to offsetParentMatrix since that's only supported by Maya 2020+.

Usage

Select one or more nodes with non-zero translate/rotate channels, and run this.

import cmdx

with cmdx.DagModifier() as mod:
    for src in cmdx.selection():
        group = mod.create_node("transform",
                                 name=src.name() + "_parent",
                                 parent=src.parent())
        mod.set_attr(group["translate"], src["translate"])
        mod.set_attr(group["rotate"], src["rotate"])
        mod.set_attr(src["translate"], (0, 0, 0))
        mod.set_attr(src["rotate"], (0, 0, 0))

        mod.parent(src, group)

https://user-images.githubusercontent.com/2152766/137684150-407693ce-76dc-49f6-bbc2-8a84d024fd50.mp4