MEL: Detach Face Vertex

This script/tool gets a vertex and a face and detaches the vertex for that face. See below:

//gets the face and vertex and split the vertex, selecting the result in the end
global proc fnProc_detachFaceVertex(string $sPolyFace, string $sVertex) {
    //check if the verex is part of the face
    string $szTmp[] = `polyListComponentConversion -fromFace -toVertex $sPolyFace`;
    string $szFaceVertices[] = `ls -flatten $szTmp`;
    if ( ! fnUtils_searchStringArray($sVertex, $szFaceVertices) )
        error("Selected vertex mus be part of the selected face to be detached for that face");

	//finds the polynamse
    string $sPolyObject[] = `listRelatives -p $sVertex`;
    $sPolyObject = `listRelatives -p $sPolyObject[0]`;

	//split the vertex and find out how many vertices have been added
    int $iTotalVertex[] = `polyEvaluate -v $sPolyObject`;
    polySplitVertex $sVertex;
    int $iTotalVertexNew[] = `polyEvaluate -v $sPolyObject`;

	//make the list of vertices resulted from split command
    string $szVertices[];
    $szVertices[0] = $sVertex;
    for($i=0; $i < ($iTotalVertexNew[0] - $iTotalVertex[0]); $i++)
        $szVertices[$i+1] = $sPolyObject[0] + ".vtx[" + ($iTotalVertex[0]+$i) + "]";

	//find which vertices to merge again and make the command string
    string $sMergeCommand = "polyMergeVertex ";
    int $iSameVertex;

    $szTmp = `polyListComponentConversion -fromFace -toVertex $sPolyFace`;
    $szTmp = `ls -flatten $szTmp`;

    for($sV in $szVertices) {
        if ( fnUtils_searchStringArray($sV, $szTmp) ) {
            if($sV == $sVertex) $iSameVertex = 1;
            continue;
        }
        $sMergeCommand += ($sV + " ");
    }

	//merge vertices
    eval($sMergeCommand);

	//select the split vertex, will check if the verte is a new one or not.
    $szTmp = `polyListComponentConversion -fromFace -toVertex $sPolyFace`;
    $szTmp = `ls -flatten $szTmp`;
    if($iSameVertex == 1) select -r $sVertex;
    else {
        for($sV in $szTmp) {
            if ( fnUtils_searchStringArray($sV, $szFaceVertices) ) continue;
            else select -r $sV;
        }
    }

}

//creates the tool Ctx
global proc fnTools_detachFaceVertex() {
    if(!`contextInfo -exists detachFaceVertexTool`) {
        scriptCtx
            -baseClassName "detachFaceVertex"
            -title "Detach Face Vertex"
            -totalSelectionSets 2
            -expandSelectionList true
            -cumulativeLists false
            -toolStart "select -cl;"
            -finalCommandScript "fnProc_detachFaceVertex($Selection2[0], $Selection1[0]);"

            -setNoSelectionPrompt "Select the vertex you want to detach"
            -setSelectionPrompt ""
            -setAutoToggleSelection true
            -setAutoComplete true
            -setSelectionCount 0
            -polymeshFace false
            -polymeshVertex true

            -setNoSelectionPrompt "Now Select the connected polyFace you want to detach the vertex for."
            -setSelectionPrompt "Now Press ENTER to detach the vertex"
            -setAutoToggleSelection true
            -setAutoComplete false
            -setSelectionCount 0
            -polymeshFace true
            -polymeshVertex false

            detachFaceVertexTool;
    }

    setToolTo detachFaceVertexTool;
}

Discuss - No Comments

No comments yet. Why not add one below?

Add a Comment

Your email address will not be published. Note marked required (*) fields.

*