Copy and paste into a .mel file or download it here.
//=========================== SDS Exporter ===============================//
//
// SDS Exporter v2
// GTProductions.net
// Created by Alex Schwartz 2009 Copyright
//
// To be used freely with the acknowledgement that the author is not responsible
// for any perceived damage this script may directly (or indirectly) cause.
// Please contact the author if you plan to use this script in a commercial project.
//
// Simple script to export to the .sds format
// Features: Custom file naming, auto-triangulation, n-Gon detection, cross-platform
// file browser for saving in custom directories.
//
// Installation: Place the script in the scripts folder under the version number
// ie. ../maya/2008/scripts , or copy and paste the contents of the .mel script into
// the script editor dialog and execute using Ctrl-Enter.
// Tip: You might want to make a shelf button for easy retrieval.
//
// Version 1 - release version
// Version 2 - GUI added, ngon prevention, triangulation, path browsing, minor fixes
//
//=========================== SDS Exporter ===============================//
global string $fileName;
global string $path;
int $numtoken;
string $abuffer[];
global int $triang = 0;
global string $slash = "/";
if (`about -nt`) $slash = "\\";
proc exportSDS(){
global string $slash;
print("\nslash = " + $slash + "\n");
global string $fileName;
global int $triang;
global string $path;
global string $fileName = "";
string $themesh[] = `ls -sl`;
if($triang){polyTriangulate -ch 1 $themesh[0];select -r $themesh[0];}
int $alltris[] = `polyEvaluate -t $themesh[0]`; //get all the triangles of the mesh
int $allverts[] = `polyEvaluate -v $themesh[0]`; //get all the vertices of the mesh
int $numverts = $allverts[0];
int $numtris = $alltris[0];
fileBrowser "setPath" "Select Directory" "" 4;
// open the file for writing
if($fileName == "")$fileName = "untitled";
string $fulldir = $path + $slash + $fileName + ".sds";
if(`about -nt`){
string $fulldirwin = substituteAllString($fulldir, "/", "\\");
$fulldir = $fulldirwin;
}
$file = `fopen $fulldir "w"`;
//print header info
fprint $file ("// SDS format by Jake Haas");
fprint $file ("\n// Exported with Maya" + getApplicationVersionAsFloat());
fprint $file ("\n// Maya Exporter by Alex Schwartz - gtproductions.net");
//First list the total number of vertices in selected object
fprint $file ("\nVertices [" + $numverts + "]");
//Next list the total number of faces in selected object
fprint $file ("\nTriangles [" + $numtris + "]\n");
string $obj;
int $objCount = `size $themesh`;
if ($objCount == 0) fprint $file ("\nNothing selected\n");
if ($objCount > 2) fprint $file ("\nToo many objects selected!\n");
// write model data out
if ($objCount == 1)
for ( $obj in $themesh )
{
// write arrays
int $faceVertices[];
float $vertexData[];
//start section for vertex info
$size = $allverts[0];
int $numVertices = $size;
$iter = 0;
fprint $file ("\nvertices [");
while ($iter<$size)
{
string $x = $obj+".vtx["+$iter+"]";
float $vtx[] = `pointPosition -l $x`;
fprint $file ("\n" + $iter + " [" + $vtx[0] +","+ $vtx[1] +","+ $vtx[2] + "]");
$vertexData[$iter] = $vtx[0];
$vertexData[$iter+1] = $vtx[1];
$vertexData[$iter+2] = $vtx[2];
$iter++;
}
fprint $file ("\n]");
//Start section for face info
string $faceToVertex[] = `polyInfo -faceToVertex`;
int $size = `size $faceToVertex`;
int $faces = $size;
int $iter = 0;
fprint $file ("\nobject [");
while ($iter<$faces)
{
string $onefaceToVertex[];
tokenize($faceToVertex[$iter],$onefaceToVertex);
string $firstchopped = `substitute ":" $onefaceToVertex[1] ""`;
$onefaceToVertex[1] = $firstchopped;
int $x = (int) $onefaceToVertex[2];
$faceVertices[$iter] = $x;
$x = (int) $onefaceToVertex[3];
$faceVertices[$iter+1] = $x;
$x = (int) $onefaceToVertex[4];
$faceVertices[$iter+2] = $x;
//if there is no 4th vertex, we have a triangle
if ($onefaceToVertex[5] == ""){
//for triangles
fprint $file ("\nface " + $onefaceToVertex[1] + " [" + $onefaceToVertex[2] +","+ $onefaceToVertex[3] +","+ $onefaceToVertex[4] + "]");
} else if($onefaceToVertex[6] == "" && $onefaceToVertex[5] != "") {
$x = (int) $onefaceToVertex[5];
$faceVertices[$iter+3] = $x;
//for faces
fprint $file ("\nface " + $onefaceToVertex[1] + " [" + $onefaceToVertex[2] +","+ $onefaceToVertex[3] +","+ $onefaceToVertex[4] + "," + $onefaceToVertex[5] + "]");
}
if($onefaceToVertex[6] != ""){
print("Warning: you have ngons!\n");
confirmDialog -title "N-gons Error" -message "You have N-gons in your mesh. \nPlease clean them up before exporting or select the triangulate checkbox." -button "Okay";
$iter = $faces;
}
$iter++;
}
fprint $file ("\n]");
}
// close the file
fclose $file;
//if($triang)polyQuad -ch 1 $themesh[0];
if($triang){undo;undo;}
string $msgDialogText = "";
if(`about -nt`){
$msgDialogText = "SDS file successfully exported!\n" + "File path: " + $path + $slash + $fileName + ".sds\n";
}else{
$msgDialogText = "SDS file successfully exported!\n" + "File path: " + $path + $fileName + ".sds\n";
}
confirmDialog -title "Successful Save" -message $msgDialogText -button "Okay";
if ( `window -exists theWindow` ) {deleteUI theWindow;}
}
// GUI creation
if ( `window -exists theWindow` ) {deleteUI theWindow;}
if (`windowPref -exists theWindow`) windowPref -remove theWindow;
window -title "SDS Exporter" -widthHeight 220 170 theWindow;
columnLayout -rowSpacing 8 -columnAttach "left" 10;
text -label "SDS Exporter v1.1";
checkBox -label "Triangulate on export" -onCommand "triangulateSDS(on)" -offCommand "triangulateSDS(off)" myCheckBox;
rowLayout -numberOfColumns 2 Row2;
columnLayout -rowSpacing 4 -columnWidth 80 -parent Row2 ColumnA;
textField -w 100 -text "filename" -changeCommand ("setFileName") fileName;
columnLayout -rowSpacing 4 -columnWidth 80 -parent Row2 ColumnB;
text -l "File name";
setParent ..;
setParent..;
button -label "Export Selected" -command "exportSDS()";
showWindow;
proc setPath(string $pathinput, string $type){
global string $path;
if($type != "directory"){
confirmDialog -title "Directory Error" -message "Error processing selection. Please choose a directory to save the output file" -button "Okay";
}else{
$path = $pathinput;
}
}
proc setFileName(){
global string $fileName = "";
$fileName = `textField -q -text fileName`;
setAttr -type "string" defaultRenderGlobals.imageFilePrefix $fileName;
print("\nFile name changed to: " + $fileName + "\n");
}
proc triangulateSDS(string $status){
global int $triang;
if($status == "0") {$triang = 0; print("\ntriangulation off");}
if($status == "1") {$triang = 1; print("\ntriangulation on");}
}
//end script
//-----------------