If you saw my last post on MEL syntax highlighting then you may have guessed that I’ve been doing some MEL scripting lately. Here’s my first mini-gem, a batch exporter for a group of objects. To use it, simply run the script with a group selected.

Note: This currently requires the OpenCOLLADA exporter, I’ll work up a small post for changing the exporter to use in the near future.

// group_export.mel - Individually export all children of a selected group
// Note: Requres OpenCollada - http://opencollada.org/
// Copyright (c) 2011 Skye Book <skye.book@gmail.com>
// Released under GPL v3

// get the relatives of the selected group (listRelatives gets only children by default)
string $children[] = `listRelatives`;

int $fileCounter=0;
for($child in $children){
	select -r $child;
	file -force -options "bakeTransforms=0;relativePaths=0;copyTextures=1;exportTriangles=1;cgfxFileReferences=1;isSampling=0;curveConstrainSampling=0;removeStaticCurves=1;exportPolygonMeshes=1;exportLights=1;exportCameras=1;exportJointsAndSkin=1;exportAnimations=1;exportInvisibleNodes=0;exportDefaultCameras=0;exportTexCoords=1;exportNormals=1;exportNormalsPerVertex=1;exportVertexColors=1;exportVertexColorsPerVertex=1;exportTexTangents=0;exportTangents=0;exportReferencedMaterials=0;exportMaterialsOnly=0;exportXRefs=1;dereferenceXRefs=1;exportCameraAsLookat=0;cameraXFov=0;cameraYFov=1;doublePrecision=0;" -typ "OpenCOLLADA exporter" -pr -es (`workspace -fn`+"/"+$child+".dae");
	print $child;
	print " exported\n";
	$fileCounter++;
};

// provide results to console
print $fileCounter;
print " files saved to ";
print `workspace -fn`;