Example #1
0
def moveObjectToOrigin(objectName=""):
    if not objectName:
        MGlobal.displayError("Please provide ObjectName")
        return False

    localPivot = cmds.xform(objectName , q=True, rotatePivot=True)
    worldPivot = cmds.xform(objectName , q=True, rotatePivot=True, worldSpace=True)
    posx = 0.0
    posy = 0.0
    posz = 0.0
    if  worldPivot[0] == localPivot[0]:
        posx = worldPivot[0]
    else:
        posx = worldPivot[0] - localPivot[0]

    if  worldPivot[1] == localPivot[1]:
        posy = worldPivot[1]
    else:
        posy = worldPivot[1] - localPivot[1]

    if  worldPivot[2] == localPivot[2]:
        posz = worldPivot[2]
    else:
        posz = worldPivot[2] - localPivot[2]


    cmds.move(-posx, -posy, -posz, objectName, absolute=True)
Example #2
0
def update_xforms(abcfile, parent_under):
    """Update previously imported transforms"""

    cmd = 'AbcImport "%s" -d -rpr "%s" -ct "%s" -eft "Shape"' % (
        abcfile, parent_under, parent_under)
    try:
        mel.eval(cmd)
        MGlobal.displayInfo(cmd)
    except Exception as e:
        message = "Error running update transforms : %s" % e
        MGlobal.displayError(message)
Example #3
0
def uninitializePlugin(mobject):
    mplugin = OpenMayaMPx.MFnPlugin(mobject)

    try:
        mplugin.deregisterNode(MirrorNode.NODE_ID)
        mplugin.deregisterNode(ControlPairNode.NODE_ID)

        mplugin.deregisterCommand(CreateMirrorNode.CMD_NAME)
        mplugin.deregisterCommand(CreateMirrorNode.CMD_NAME.lower())
    except:
        MGlobal.displayError("Failed to unload zooMirror plugin:")
        raise
Example #4
0
def uninitializePlugin( mobject ):
	mplugin = OpenMayaMPx.MFnPlugin( mobject )

	try:
		mplugin.deregisterNode( MirrorNode.NODE_ID )
		mplugin.deregisterNode( ControlPairNode.NODE_ID )

		mplugin.deregisterCommand( CreateMirrorNode.CMD_NAME )
		mplugin.deregisterCommand( CreateMirrorNode.CMD_NAME.lower() )
	except:
		MGlobal.displayError( "Failed to unload zooMirror plugin:" )
		raise
Example #5
0
def initializePlugin( mobject ):
	mplugin = OpenMayaMPx.MFnPlugin( mobject, 'macaronikazoo', '1' )

	try:
		mplugin.registerNode( MirrorNode.NODE_TYPE_NAME, MirrorNode.NODE_ID, MirrorNode.Creator, MirrorNode.Init )
		mplugin.registerNode( ControlPairNode.NODE_TYPE_NAME, ControlPairNode.NODE_ID, ControlPairNode.Creator, ControlPairNode.Init )

		mplugin.registerCommand( CreateMirrorNode.CMD_NAME, CreateMirrorNode.Creator, CreateMirrorNode.SyntaxCreator )
		mplugin.registerCommand( CreateMirrorNode.CMD_NAME.lower(), CreateMirrorNode.Creator, CreateMirrorNode.SyntaxCreator )
	except:
		MGlobal.displayError( "Failed to load zooMirror plugin:" )
		raise
Example #6
0
 def _select_target(self):
     self.scatter.set_scatter_targets()
     full_targets = self.scatter.target_objs + self.scatter.target_verts
     if len(full_targets) > 0:
         display_str = self._create_list_string(full_targets)
         self.target_le.setText(display_str)
     else:
         self.target_le.clear()
         MGlobal.displayError(
             "Failed to get scatter targets. Select one or more shapes in "
             "Object Mode and press \"Get From Selection\"")
     self._update_scatter_btn_state()
Example #7
0
def import_xforms(abcfile, transform_names, parent_under, update):
    """
    Imports and optionally, updates transforms from an alembic file.

    Params:
        abcfile : (str) the filepath of the alembic file
        transform_names : (list) a list of transform names to import / update
        parent_under : (str) the dag path to alembicHolder
        update : (bool) update previously imported transforms
    """
    archive = cask.Archive(abcfile)
    update_data = []

    for tr in transform_names:

        data = {}
        data['transform'] = tr
        data['dag_path'] = get_future_dag_path(tr, parent_under, archive)
        data['exists'] = cmds.objExists(data['dag_path'])

        if not data['exists']:
            update_data.append(data)
        elif data['exists'] and update:
            update_data.append(data)

    if get_previously_imported_transforms(abcfile, parent_under) == []:

        # this doesnt use the -ct and -crt flags, which will cause the import to fail if root nodes are not present
        if update and update_data != []:
            cmd = 'AbcImport "%s" -d -rpr "%s" -ft "%s" -eft "Shape"' % (
                abcfile, parent_under, ' '.join(
                    [i['transform'] for i in update_data]))

            try:
                mel.eval(cmd)
                MGlobal.displayInfo(cmd)
            except Exception as e:
                message = "Error running import transforms : %s" % e
                MGlobal.displayError(message)
        return

    # conntect type AbcImport
    if update and update_data != []:
        cmd = 'AbcImport "%s" -d -rpr "%s" -ft "%s" -ct "%s" -crt -eft "Shape"' % (
            abcfile, parent_under, ' '.join(
                [i['transform'] for i in update_data]), parent_under)

        try:
            mel.eval(cmd)
            MGlobal.displayInfo(cmd)
        except Exception as e:
            message = "Error running import transforms : %s" % e
            MGlobal.displayError(message)
Example #8
0
def initializePlugin( mobject ):
	mplugin = OpenMayaMPx.MFnPlugin( mobject, 'macaronikazoo', '1' )

	try:
		mplugin.registerNode( MirrorNode.NODE_TYPE_NAME, MirrorNode.NODE_ID, MirrorNode.Creator, MirrorNode.Init )
		mplugin.registerNode( ControlPairNode.NODE_TYPE_NAME, ControlPairNode.NODE_ID, ControlPairNode.Creator, ControlPairNode.Init )

		mplugin.registerCommand( CreateMirrorNode.CMD_NAME, CreateMirrorNode.Creator, CreateMirrorNode.SyntaxCreator )
		mplugin.registerCommand( CreateMirrorNode.CMD_NAME.lower(), CreateMirrorNode.Creator, CreateMirrorNode.SyntaxCreator )
	except:
		MGlobal.displayError( "Failed to load zooMirror plugin:" )
		raise
Example #9
0
 def _select_obj(self):
     self.scatter.set_scatter_obj()
     if 0 < len(self.scatter.scatter_objs) < 4:
         display_str = self._create_list_string(self.scatter.scatter_objs)
         self.obj_le.setText(display_str)
         self._update_proportion_controls()
     else:
         self.obj_le.clear()
         MGlobal.displayError(
             "Failed to get scatter object. Select up to three objects in "
             "Object Mode and press \"Get From Selection\"")
         self._reset_proportion_controls()
     self._update_scatter_btn_state()
Example #10
0
def movePivotToBottomCenter(objectName=""):
    if not objectName:
        MGlobal.displayError("Please provide ObjectName")
        return False

    boxMin = cmds.getAttr(objectName + ".boundingBoxMin")[0]
    boxMax = cmds.getAttr(objectName + ".boundingBoxMax")[0]

    posx = (boxMax[0] + boxMin[0]) / 2
    posy = boxMin[1]
    posz = (boxMax[2] + boxMin[2]) / 2
    bottomCenter = [posx, posy, posz]
    cmds.xform(objectName, piv=bottomCenter, ws=True)

    return True
Example #11
0
 def _scatter(self):
     """Tests for scatter objects and then applies scatter."""
     if not cmds.objExists(self.scatter.scatter_objs[0]):
         MGlobal.displayError("One or more specified scatter objects do  "
                              "not exist. Please reselect.")
         self.obj_le.clear()
         self._update_scatter_btn_state()
         return
     for target in self.scatter.target_objs + self.scatter.target_verts:
         if not cmds.objExists(target):
             MGlobal.displayError("One or more of the scatter targets does "
                                  "not exist. Please reselect.")
             self.target_le.clear()
             self._update_scatter_btn_state()
             return
     self._set_scatter_properties_from_ui()
     self.scatter.scatter()
Example #12
0
def checkAndLoadPlugin(pluginName=""):
    """
    load plugin if not loaded.
    :param pluginName:
    :return:
    """
    if not cmds.pluginInfo(pluginName, query=True, loaded=True):
        load_result = cmds.loadPlugin(pluginName)
        if load_result:
            MGlobal.displayInfo("plugin " + pluginName + " loaded success")
            return True
        else:
            MGlobal.displayError("Can find and load plugin:%s" % pluginName)
            return False
    else:
        MGlobal.displayInfo("Plugin already loaded:%s" % pluginName)
        return True
Example #13
0
SPACE_LOCAL = rigUtils.SPACE_LOCAL
SPACE_OBJECT = rigUtils.SPACE_OBJECT

Axis = rigUtils.Axis
CONTROL_DIRECTORY = None

if CONTROL_DIRECTORY is None:
	#try to determine the directory that contains the control macros
	for f in Path( __file__ ).up().files( recursive=True ):
		if f.hasExtension( 'shape' ):
			if f.name().startswith( 'control' ):
				CONTROL_DIRECTORY = f.up()
				break

if CONTROL_DIRECTORY is None:
	MGlobal.displayError( "WARNING: Cannot determine the directory that contains the .control files - please open '%s' and set the CONTROL_DIRECTORY variable appropriately" % __file__ )

AX_X, AX_Y, AX_Z, AX_X_NEG, AX_Y_NEG, AX_Z_NEG = map( Axis, range( 6 ) )
DEFAULT_AXIS = AX_X

AXIS_ROTATIONS = { AX_X: (0, 0, -90),
                   AX_Y: (0, 0, 0),
                   AX_Z: (90, 0, 0),
                   AX_X_NEG: (0, 0, 90),
                   AX_Y_NEG: (180, 0, 0),
                   AX_Z_NEG: (-90, 0, 0) }


class ShapeDesc(object):
	'''
	store shape preferences about a control
Example #14
0
def error(msg, showLineNumber=False):
    #return mel.error(msg, showLineNumber)
    return MGlobal.displayError(msg)
Example #15
0
SPACE_LOCAL = rigUtils.SPACE_LOCAL
SPACE_OBJECT = rigUtils.SPACE_OBJECT

Axis = rigUtils.Axis
CONTROL_DIRECTORY = None

if CONTROL_DIRECTORY is None:
	#try to determine the directory that contains the control macros
	for f in Path( __file__ ).up().files( recursive=True ):
		if f.hasExtension( 'shape' ):
			if f.name().startswith( 'control' ):
				CONTROL_DIRECTORY = f.up()
				break

if CONTROL_DIRECTORY is None:
	MGlobal.displayError( "WARNING: Cannot determine the directory that contains the .control files - please open '%s' and set the CONTROL_DIRECTORY variable appropriately" % __file__ )

AX_X, AX_Y, AX_Z, AX_X_NEG, AX_Y_NEG, AX_Z_NEG = map( Axis, range( 6 ) )
DEFAULT_AXIS = AX_X

AXIS_ROTATIONS = { AX_X: (0, 0, -90),
                   AX_Y: (0, 0, 0),
                   AX_Z: (90, 0, 0),
                   AX_X_NEG: (0, 0, 90),
                   AX_Y_NEG: (180, 0, 0),
                   AX_Z_NEG: (-90, 0, 0) }


class ShapeDesc(object):
	'''
	store shape preferences about a control
Example #16
0
def error(msg, showLineNumber=False):
	#return mel.error(msg, showLineNumber)
	return MGlobal.displayError(msg)