Posted on Oct 29, 2010

Row 1 Not Found, List Deformer Dialog Alternative

I'm not sure what causes it, but often when trying to produce the List Deformer Dialog Box in Maya, I get this

// Error: file: C:/Program Files/Autodesk/Maya2011/scripts/others/detachHistoryTable.mel line 369: Object 'row1' not found.

So I decided to write an alternative, using my jd_listOfOrderedDeformers as base.

// this procedure will return a list of deformers ordered
global proc string[] jd_listOfOrderedDeformers () {
    // initialize
    $sel = `ls -sl`;
    if (`size $sel` != 1) {
        warning -sl 0 "listOfOrderedDeformers requires you to have one (1) object selected!";
        return {};
    }
    $selobj = $sel[0];
    $shapeList = `listRelatives -type shape`;
    if (`size $shapeList` < 1) {
        warning -sl 0 "listOfOrderedDeformers requires you to have one (1) object with a mesh selected!";
        return {};
    }

    // get shape name
    $shape = $shapeList[0];

    // get list of deformers for a the shape
    string $listOfDefs[];
    $globallistofdeformers = `ls -type geometryFilter`;
    for ($each in $globallistofdeformers) {
        $geo = `deformer -q -g $each`;
        for ($gtry in $geo) {
             if ($gtry == $shape) {
		        $listOfDefs[size($listOfDefs)] = $gtry;
             }
	    }
    }

    // check if there are deformers after all...
    if (`size $listOfDefs` < 1) {
        warning -sl 0 "listOfOrderedDeformers found no deformer on the object selected!";
        return {};
    }

    $lisofdefssize = `size $listOfDefs`;
    $listOfGroupIDs = `listConnections -d 0 -t "groupId" $shape`;

    // initialize return variable
    string $orderedDeformers[];
    $temp = `listConnections -c 0 -p 0 -s 1 -scn 1 -type geometryFilter ($shape+".inMesh")`;
    $orderedDeformers[0] = $temp[0];

    // loop and spider through each deformer to find which ones next
    for ($i = 1;$i<$lisofdefssize;$i++) {
        $listofgroups = `listConnections -d 0 -t "groupParts" $orderedDeformers[$i-1] `;
        if (`size $listofgroups`>0) {
            string $connected;
            for ($group in $listofgroups) {
                int $itDeforms = 0;
                while ($itDeforms < 1) {
                    $connectedTMP = `listConnections ($group+".inputGeometry")`;
                    $connected = $connectedTMP[0];
                    if (`stringArrayContains $connected $globallistofdeformers`) {
                        $itDeforms = 1;
                    } else {
                        $group = $connected;
                    }

                }
                $connectedGroupIDTMP = `listConnections ($group+".groupId")`;
                $connectedGroupID = $connectedGroupIDTMP[0];
                if (`stringArrayContains $connectedGroupID $listOfGroupIDs`) {
                    $orderedDeformers[$i] = $connected;
                }

            }
        } else {
            $connectedToInputGeometry = `listConnections  -type geometryFilter -d 0 ($orderedDeformers[$i-1]+".input[0].inputGeometry")`;
            $orderedDeformers[$i] = $connectedToInputGeometry[0];
        }
    }
    return $orderedDeformers;
}

// this will pop a gui that will help you reorder deformers
global proc int jd_reorderDeformersGUI () {
    if (`waitCursor -q -state` == 1) waitCursor -state 0;
    // initialize variables
    global int $jd_reorderDeformersScriptJobIndex;
    global string $jd_reorderDeformersGUI;
    $objsel = `ls -sl`;
    $obj = $objsel[0];

    // make sure you have something selected
    if (`size $objsel` >0) $shape = `listRelatives -s $obj`;

    // initialize window
    if (`window -exists $jd_reorderDeformersGUI`) deleteUI $jd_reorderDeformersGUI;
    $jd_reorderDeformersGUI = `window -t ("[JD] Reorder Deformer's on "+$obj)`;

    // list deformers on mesh
    $list = `jd_listOfOrderedDeformers`;
    $slist = `size $list`;
    if ($slist < 2) {
        print ("[JD]Reorder Deformer: Less than two deformers found on selected object: "+$obj+"\n");
    }
    // create numbered arrays for text labels and up and down buttons
    string $thisFrame[];
    string $thisForm[];
    string $textArray[];
    string $upButArray[];
    string $downButArray[];
    $hmargin = 5;
    $fmargin = 0;
    $butmargin = 1;

    if ($slist > 0) {
        // initialize form layout and its elements
        $form = `formLayout -numberOfDivisions ($slist)`;

        for ($i=0;$i<$slist;$i++) {
            //commands to assign
            string $upC, $downC;
            if ($i>0) $upC = ("reorderDeformers "+$list[$i]+" "+$list[$i-1]+" "+$shape[0]+" ; waitCursor -state 1; jd_reorderDeformer; ");
            if ($i<($slist-1)) $downC = ("reorderDeformers "+$list[$i+1]+" "+$list[$i]+" "+$shape[0]+" ;  waitCursor -state 1; jd_reorderDeformer; ");

            $thisFrame[$i] = `frameLayout -bv 0 -lv 0 -p $form `;
            $thisForm[$i] = `formLayout -p $thisFrame[$i] -numberOfDivisions 4`;
            $textArray[$i] = `text -p $thisForm[$i] -label (($i+1)+". "+$list[$i])`;
            $upButArray[$i] = `button -p $thisForm[$i] -label  "up" -c $upC`;
            $downButArray[$i] = `button -p $thisForm[$i] -label "down" -c $downC`;

            // turn off buttons that are on top or below everything
            if ($i == 0) button -e -l "" -en 0 $upButArray[$i];
            if ($i == ($slist-1)) button -e -l "" -en 0 $downButArray[$i];

            formLayout -e
                -attachForm     $downButArray[$i] "bottom" $hmargin
                -attachPosition $downButArray[$i] "top" $butmargin 2
                -attachOppositeForm  $downButArray[$i] "left" -50
                -attachForm     $downButArray[$i] "right" $hmargin

                -attachForm     $upButArray[$i] "top" $hmargin
                -attachPosition $upButArray[$i] "bottom" $butmargin 2
                -attachOppositeForm  $upButArray[$i] "left" -50
                -attachForm     $upButArray[$i] "right" $hmargin

                -attachForm     $textArray[$i] "top" $hmargin
                -attachForm     $textArray[$i] "bottom" $hmargin
                -attachForm     $textArray[$i] "left" $hmargin
                -attachControl  $textArray[$i] "right" $hmargin $upButArray[$i]

                $thisForm[$i];

        }

        formLayout -e
            -attachForm $thisFrame[0] "top" $fmargin
            -attachForm $thisFrame[0] "left" 0
            -attachForm $thisFrame[0] "right" 0
            -attachPosition $thisFrame[0] "bottom" $fmargin 1
            $form;

        for ($i=1;$i<$slist;$i++) {
                formLayout -e
                    -attachPosition $thisFrame[$i] "top" $fmargin ($i)
                    -attachForm $thisFrame[$i] "left" 0
                    -attachForm $thisFrame[$i] "right" 0
                    -attachPosition $thisFrame[$i] "bottom" $fmargin ($i+1)
                    $form;
        }
    } else {
        $closeCommand = ("deleteUI "+$jd_reorderDeformersGUI);
        $closeForm = `formLayout -p $jd_reorderDeformersGUI -numberOfDivisions 5`;
        $closeText = `text -w 350 -label "Must have at least one object with at least two deformers selected." -p $closeForm`;
        $closeButton = `button -w 350 -l "close" -p $closeForm -c $closeCommand`;
        formLayout -e
            -attachForm $closeText "top" 5
            -attachForm $closeText "left" 5
            -attachForm $closeText "right" 5

            -attachControl $closeButton "top" 5 $closeText
            -attachForm $closeButton "left" 5
            -attachForm $closeButton "right" 5
            -attachForm $closeButton "bottom" 5

            $closeForm;
    }
    showWindow $jd_reorderDeformersGUI;
    if ($slist == 0) {
        window -e -topLeftCorner 200 200 -h 100 -w 360 $jd_reorderDeformersGUI;
    } else {
        window -e -topLeftCorner 200 200 -w 1 -h (clamp(1,$slist,$slist) * 25) $jd_reorderDeformersGUI;
    }

    return 1;
}

global proc jd_reorderDeformer () {
    global int $jd_reorderDeformerScriptJobIndex;
    global int $jd_reorderDeformerScriptJobIndex2;
    global string $jd_reorderDeformersGUI;
    jd_reorderDeformersGUI;
    $jd_reorderDeformerScriptJobIndex = `scriptJob -p $jd_reorderDeformersGUI -runOnce 1 -e "SelectionChanged" "jd_reorderDeformer"`;
}

jd_reorderDeformer;

3 Comments

52 SQL queries have been executed to show this page