def setEditable(ctl, state): """ Add an intermediate xform node to a control. The control's editable state can be toggled, and transformation differences to the 'editor' node will be flushed down to the shape level and recorded in the control data @param ctl: the control to make editable @type ctl: str @param state: True or False @type state: bool @return: True if state was changed, else False """ editor = getEditor(ctl) if editor and state: return False elif not editor and not state: return False info = getInfo(ctl) if state: editor = MC.createNode('transform', name='%s_editor' % ctl, parent=None) if nodeTag.hasTag(ctl, '%s_editor' % LOCKS_TAG_NAME): tag = nodeTag.getTag(ctl, '%s_editor' % LOCKS_TAG_NAME) nodeTag.rmTag(ctl, '%s_editor' % LOCKS_TAG_NAME) nodeTag.setTag(editor, LOCKS_TAG_NAME, tag) MC.parent(editor, ctl) MC.setAttr('%s.t' % editor, *info['t'], type='double3') MC.setAttr('%s.r' % editor, *info['r'], type='double3') MC.setAttr('%s.s' % editor, *info['s'], type='double3') MC.setAttr("%s.shear" % editor, 0,0,0, type='double3') utils.parentShape(editor, ctl, deleteChildXform=False) else: if nodeTag.hasTag(editor, LOCKS_TAG_NAME): editorLocks = nodeTag.getTag(editor, LOCKS_TAG_NAME) nodeTag.setTag(ctl, '%s_editor' % LOCKS_TAG_NAME, editorLocks) setInfo(ctl, info) utils.parentShape(ctl, editor, deleteChildXform=True) return True
def makeControl(name, xformType=None, **kwargs): """ Create a control object @param name: the control name @param xformType: if creating a new xform, use this node type. Defaults to transform @keyword t: offset the position of the handle shape. @keyword r: offset the rotation of the handle shape. @keyword s: offset the scale of the handle shape. @note: offsets are applied in the control xform's local space @raise RuntimeError: if the control exists, and xformType is supplied but does not match the current node's xform type """ #see if the object exists, and create it if not editor = None if MC.objExists(name): if xformType and xformType != MC.objectType(name): raise RuntimeError('control exists and is not of type %s' % xformType) editor = getEditor(name) if editor: setEditable(name, False) else: if not xformType: xformType = 'transform' name = MC.createNode(xformType, name=name, parent=None) xform = name #delete any shapes that exist for shape in MC.listRelatives(xform, type='geometryShape', pa=1) or []: MC.delete(shape) #create an attribute to store handle info handleData = _argHandleData(**kwargs) #snap the tmp shape to the xform tmpXform = _importShape(handleData['shape']) utils.snap(xform, tmpXform, scale=True) #apply transformations MC.parent(tmpXform, xform) MC.setAttr('%s.t' % tmpXform, *handleData['t'], type='double3') MC.setAttr('%s.r' % tmpXform, *handleData['r'], type='double3') MC.setAttr('%s.s' % tmpXform, *handleData['s'], type='double3') MC.parent(tmpXform, world=True) utils.parentShape(xform, tmpXform) if handleData.get('type') != 'surface': _setColor(xform, handleData['color']) #set the handle info _logger.debug("handle data: %r" % handleData) setInfo(xform, handleData) if editor: setEditable(xform, True) return xform