(MEL Syntax Help) Testing boundary.

(MEL Syntax Help) Testing boundary.

absoluteKelvin
Collaborator Collaborator
817 Views
9 Replies
Message 1 of 10

(MEL Syntax Help) Testing boundary.

absoluteKelvin
Collaborator
Collaborator

Im trying to figure out how to fix the syntax for this script i have been building for selection UVs within a specified boundary.  First proc is to get the faces of the Objects selected in scene without actually selecting all the faces. Second proc is actually testing the bounds using polyUVCoverage to test the bounds. It is a new maya cmd in 2017+.

The syntax error im getting is


// Error: $remainfaces = `stringArrayRemove($tempStoreShellFaces,$facesList)`; //function for removing the duplicate faces in array
//
// Error: Line 29.57: Syntax error //

 

 

global proc string[] getObjectFaces(){
    string $selOBJs[] = `ls -selection -objectsOnly`;
    string $plylistConOBJs[];
    string $combList[];
    for($i = 0; $i < size($selOBJs); $i++){
    $plylistConOBJs[$i] = ($selOBJs[$i] + ".vtx[*]");
    }
    print $plylistConOBJs;
    string $convertedList[] = `polyListComponentConversion -fv -tf $plylistConOBJs`;
    $combList = $convertedList;
    return $combList;
    //print $combList; //dont use for objects with lots of faces, it will take forever to print.
}


global proc testBoundary(){
    string $combFacesList [] = `getObjectFaces`;
    string $facesList[] = `ls -flatten $combFacesList`;
    string $faceShellList[] = {};
    string $uvShellList[] = {};
    string $tempStoreShellFaces[] = {};
    string $remainfaces[] = {};
    for ($faces in $facesList)
    {
    	
    	$uvShellList[size($uvShellList)] = `polyListComponentConversion -tuv -uvs $faces`; //get uvShells
    	$faceShellList[size($faceShellList)] = `polyListComponentConversion -fuv -tf $uvShellList[size($uvShellList)]`; //convert list to faceShells
		$tempStoreShellFaces = `ls -flatten $faceShellList[size ($faceShellList)]`; //flatten list for removing 
		$remainfaces = `stringArrayRemove($tempStoreShellFaces,$facesList)`; //function for removing the duplicate faces in array
		$facesList = $remainfaces; //update faceList
    	}
    float $statement;
    string $tileFaces[];
    for ($faces in $faceShellList) // for loop for testing boundary
    {
        $statement = (float(floatArrayToString(`polyUVCoverage $faces`,"")));
        if ($statement != 0)
        {
            $tileFaces[size($tileFaces)] = $faces;
        } 
        else{
            continue;
            }
    }
    select -r $tileFaces; //select faces within bounds
    ConvertSelectionToUVShell;
    
}

testBoundary;

any help is appreciated

 

https://www.artstation.com/kelvintam
0 Likes
818 Views
9 Replies
Replies (9)
Message 2 of 10

mspeer
Consultant
Consultant

Hi!

$remainfaces = stringArrayRemove($tempStoreShellFaces,$facesList);
Message 3 of 10

absoluteKelvin
Collaborator
Collaborator

Thanks mspeer. so when is it neccessary to add ` `?

https://www.artstation.com/kelvintam
0 Likes
Message 4 of 10

mspeer
Consultant
Consultant
0 Likes
Message 5 of 10

absoluteKelvin
Collaborator
Collaborator

Thanks again for that.

Can I trouble you some more?

Im getting this error now.

// Error: line 26: Cannot convert data of type string[] to type string. // 

Im not sure why this is a problem. i specifiied the index of the array already?

 

latest version of code

global proc string[] getObjectFaces(){
    string $selOBJs[] = `ls -selection -objectsOnly`;
    string $plylistConOBJs[];
    string $combList[];
    for($i = 0; $i < size($selOBJs); $i++){
    $plylistConOBJs[$i] = ($selOBJs[$i] + ".vtx[*]");
    }
    print $plylistConOBJs;
    string $convertedList[] = `polyListComponentConversion -fv -tf $plylistConOBJs`;
    $combList = $convertedList;
    return $combList;
    //print $combList; //dont use for objects with lots of faces, it will take forever to print.
}


global proc testBoundary(){
    string $combFacesList [] = `getObjectFaces`;
    string $facesList[] = `ls -flatten $combFacesList`;
    string $faceShellList[] = {};
    string $uvShellList[] = {};
    string $tempStoreShellFaces[] = {};
    string $remainfaces[] = {};
    for ($faces in $facesList)
    {
    	
    	$uvShellList[size($uvShellList)] = `polyListComponentConversion -tuv -uvs $faces`; //get uvShells
    	$faceShellList[size($faceShellList)] = `polyListComponentConversion -fuv -tf $uvShellList[size($uvShellList)]`; //convert list to faceShells
		$tempStoreShellFaces = `ls -flatten $faceShellList[size ($faceShellList)]`; //flatten list for removing 
		$remainfaces = stringArrayRemove($tempStoreShellFaces,$facesList); //function for removing the duplicate faces in array
		$facesList = $remainfaces; //update faceList
    	}
    float $statement;
    string $tileFaces[];
    for ($faces in $faceShellList) // for loop for testing boundary
    {
        $statement = (float(floatArrayToString(`polyUVCoverage $faces`,"")));
        if ($statement != 0)
        {
            $tileFaces[size($tileFaces)] = $faces;
        } 
        else{
            continue;
            }
    }
    select -r $tileFaces; //select faces within bounds
    ConvertSelectionToUVShell;
    
}

testBoundary;
https://www.artstation.com/kelvintam
0 Likes
Message 6 of 10

absoluteKelvin
Collaborator
Collaborator

I went back to fiddle with it somemore. I manage to fix the convert type  string[] to string error.

I have 3 simple meshes in the scene a cube, a cylinder and Sphere selected. But now this comes up ??? sigh......

 

Error: line 27: No object matches name:

 

global proc string[] getObjectFaces(){
    string $selOBJs[] = `ls -selection -objectsOnly`;
    string $plylistConOBJs[];
    string $combList[];
    for($i = 0; $i < size($selOBJs); $i++){
    $plylistConOBJs[$i] = ($selOBJs[$i] + ".vtx[*]");
    }
    //print $plylistConOBJs;
    string $convertedList[] = `polyListComponentConversion -fv -tf $plylistConOBJs`;
    $combList = $convertedList;
    return $combList;
    //print $combList; //dont use for objects with lots of faces, it will take forever to print.
}


global proc testBoundary(){
    string $combFacesList [] = `getObjectFaces`;
    string $facesList[] = `ls -flatten $combFacesList`;
    string $faceShellList[] = {};
    string $uvShellList[] = {};
    string $tempStoreShellFaces[] = {};
    string $remainfaces[] = {};
    for ($faces in $facesList)
    {
    	
    	$uvShellList = `polyListComponentConversion -tuv -uvs $faces`; //get uvShells
    	$faceShellList = `polyListComponentConversion -fuv -tf $uvShellList[size($uvShellList)]`; //convert list to faceShells
	$tempStoreShellFaces = `ls -flatten $faceShellList[size ($faceShellList)]`; //flatten list for removing 
	$remainfaces = stringArrayRemove($tempStoreShellFaces,$facesList); //function for removing the duplicate faces in array
	$facesList = $remainfaces; //update faceList
    	}
    	
   	print $faceShellList[1];
    float $statement;
    string $tileFaces[];
    for ($faces in $faceShellList) // for loop for testing boundary
    {
        $statement = (float(floatArrayToString(`polyUVCoverage $faces`,"")));
        if ($statement != 0)
        {
            $tileFaces[size($tileFaces)] = $faces;
        } 
        else{
            continue;
            }
    }
    select -r $tileFaces; //select faces within bounds
    ConvertSelectionToUVShell;
    
}

testBoundary;
https://www.artstation.com/kelvintam
0 Likes
Message 7 of 10

mspeer
Consultant
Consultant

Hi!

Your $uvShellList will become an array with one entry like {pSphere1.map[0:438]}

0 Likes
Message 8 of 10

absoluteKelvin
Collaborator
Collaborator

I see what you mean. Is it possible to turn it into multiple entries in one single index.

Example:

$uvShellList[0] = pSphere1.map[0:5] pSphere1.map[6:23] pCylinder1.map[0:30]

$uvShellList[1] = pCube1.map[4:20] pCylinder1.map[31:40]

..................

I tried using stringArrayToString, but gives me syntax error. I have ideas on how to get code to work, but its the syntax that trips me up most of the time.

 

https://www.artstation.com/kelvintam
0 Likes
Message 9 of 10

mspeer
Consultant
Consultant

Hi!

 

To "flatten" a list you can use:

 

ls -fl

 

I don't understand your current script (i did not read it complete), but multiple lists inside one entry of an array does not look like a good idea, i recommend to use an other approach.

 

But of course you could create something like this:

string $list[] = {"pSphere1.map[0:10] pSphere2.map[20:30]", "pSphere3.map[40:50]"};
0 Likes
Message 10 of 10

absoluteKelvin
Collaborator
Collaborator

the point of populating the array like that is to group the uvs by Shell. Reason for insisting on using shells is it reduces the amount of entries for polyUVCoverage to test. Therefore making the procedure run much faster. 

polyUVCoverage returns the uv coverage within a set boundary (uMin, vMin ,uMax, vMax). the function needs face selection or a list of faces to process.  The main purpose of the procedure is to be able to expand user selection to entire UV/UDIM tile. I have wrote one by using polyEvaluate as the backbone, but it was too slow. So when I discovered polyUVCoverage which seems  to be much faster then polyEvaluate. I decide to pursue this method because of the speed gain is substantial.

 

The only way to get uv Face Shells without actually selecting each individual uvs then convert to polyUVShell, is to use polyListComponentConversion. polyListComponentConversion has a -uvs/-uvShell option, which gives the .map contained within the shell. This due to the fact that iterating over thousands of faces individually will be very slow.

 

I hope this clear things up. Again I would like to thank you for spending time to answer my questions MSPeer.

https://www.artstation.com/kelvintam
0 Likes