help with this small mel script "AnyOne ???"


#1

Hello
I open a similar subject to this but it was in the wrong place so this is my problem.
I have a textScrollList contain the name of some selected object from my scene. i want to export the selection into a text or ma file. this is what i write. it seem to be working but my problem is that i got in the exported file the name of the first object in my textScrollList. i can specify if i want the first or the second name … but i want all the name in my exported file.


global proc ExportSmartSelected()
{
fileBrowserDialog -m 1 -fc "SaveList" -ft "mayaAscii" -an "Save Text File" -om "SaveAs";

}

global proc int SaveList( string $filename, string $fileType )
{
     
            $fileId=`fopen $filename "w"`;
            string $SmartNameSel [] = `textScrollList -q -si SmartWindow`;
            $SmartNameSelOne = $SmartNameSel [0] ;
            fprint $fileId $SmartNameSelOne;
            fclose $fileId;
            return 1;

}

when i change $SmartNameSel [0] to $SmartNameSel [1] for exemple i got the name of the second element in my textScrollList. and this is not what i want. i look to have all the name.


#2

You can loop over the string array like this:

string $someArray[] = {"a", "b", "c"};
string $a;
for( string $a in $someArray)
{
   print($a + "
");
}

#3

Thank you haggi you are the man really

i try this one and now i can print all the name in my textScrollList. but when i try print them to my file i got the famous error
Invalid call to “fprint”. Check number and types of arguments expected by the procedure

this is the script i have now. the command print work fine now .


global proc ExportSmartSelected()
{
fileBrowserDialog -m 1 -fc "SaveList" -ft "mayaAscii" -an "Save Text File" -om "SaveAs";

}

global proc int SaveList( string $filename, string $fileType )
{
     
            $fileId=`fopen $filename "w"`;
            string $SmartNameSel [] = `textScrollList -q -si SmartWindow`;
            string $from [] = {""};
            appendStringArray($SmartNameSel, $from, 2);
            print $SmartNameSel ;
            fprint $fileId $SmartNameSel ;
            fclose $fileId;
             return 1;  
            

}


#4

If you read the docs for fprint carefully, it does not supports:

fprint int int|float|string|vector 

but you have a string array. You can convert your array to a string with the command: stringArrayToString()


#5

thank you that’s working now. i got all my name in the exported file. one last problem i will try to solve it. all the name appear in one line. i will try to find how to have a name on each line. this is the working code for now and thank you again haggi



global proc int SaveList( string $filename, string $fileType )
{
     
            $fileId=`fopen $filename "w"`;
            string $SmartNameSel [] = `textScrollList -q -si SmartWindow`;
            $array = stringArrayToString( $SmartNameSel, "");
            fprint $fileId $array ;
            fclose $fileId;
            return 1;  
            

}


#6

You can use a new line seperator to combine the string array:

stringArrayToString($array, "
");

#7

thank you haggi so much for all your effort

i foudn this solution i write this for save


$fileId=`fopen $filename "w"`;
            string $SmartNameSel [] = `textScrollList -q -si SmartWindow`;
            $array = stringArrayToString( $SmartNameSel, "
");
            fprint $fileId ( $array +"
" ) ;
            fclose $fileId;
            return 1;  

and it’s work fine now. it save a file with all the name in a single line but when i load it back to my textScrollList it come as i want every object name in a seperated line. problem solved :keenly: