Question

I just want to know how I can add multiple proxies to referenced files in my Maya scene.

Scenario : We select objects which contain "_v001" :

select -r "*_v001";

We create the function to add proxies for each referenced files :

global proc proxyAddition() {

    string $selectionList[] = `ls -sl`;

    if(size($selectionList)) {

        string $object = $selectionList[0];
        string $currentRN = `referenceQuery -rfn $object`;
        string $currentFilePath = `referenceQuery -filename $object`;
        string $currentNamespace = `referenceQuery -namespace $object`;

        if(endsWith($currentRN, "v001RN") == 1) {

            string $newRN = `substitute "v001RN" $currentRN "v002"`;
            string $newFilePath = `substitute "v001" $currentFilePath "v002"`;
            string $newNamespace = `substitute "v001" $currentNamespace "v002"`;
            proxyAdd $currentRN $newFilePath "HD";
            print "Opération effectuée avec succès.";
        }
    } else {
        warning "Aucun objet de type v001 dans la scène.";
    }
}
proxyAddition;

What I want is find the piece of string "v001" in each referenced files and change it to "v002" (for the proxyName, the namespace and the file path).

Thank you.

Was it helpful?

Solution

Finally I succeed to finish it :

select -r "*_v001:*";

global proc proxyAddition() {

    string $selectionList[] = `ls -sl -type "mesh"`;

    if(size($selectionList)) {

        for($object in $selectionList) {

            string $currentRN = `referenceQuery -rfn $object`;
            string $currentFilePath = `referenceQuery -filename $object`;
            string $currentNamespace = `referenceQuery -namespace $object`;

            if(endsWith($currentRN, "v001RN") == 1) {

                string $newRN = `substitute "v001RN" $currentRN "v002"`;
                string $newFilePath = `substitute "v001" $currentFilePath "v002"`;
                string $newNamespace = `substitute "v001" $currentNamespace "v002"`;
                proxyAdd $currentRN $newFilePath "HD";
                print "Opération effectuée avec succès.";               
            }
        }
    } else {
        warning "Aucun objet de type v001 dans la scène.";
    }
}
proxyAddition;

The script selects object which name contain "_v001", then filters it to keep mesh objects only. After that, we use referenceQuery method to store our current reference variables. Then we substitute variable which contain "v001" string value to "v002" in new variables. This substitute method is used for the filepath, the namespace and the ReferenceNode of our current reference object(s). With these new variables, we can add our new proxy/proxies using "proxyAdd".

This process could work only if you have reference files in the same folder. If it's not the case, use the substitute method to your filepath var with more options. You can also change "v001" and "v002" by your own values which differentiate your references files versions.

The "HD" argument is used for proxyTag of your reference file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top