This version (2012/09/26 11:05) is a Draft.
Silent OBJ Export
Summary
Below is an example demonstrating how you can export a Wavefront Object (*.obj) format geometry file using the standard exporter included with DAZ Studio and through the use of settings, control the exporter without displaying the output options dialog.
API Areas of Interest
Example
Click the name of the example below to save it as a file.
- Silent_OBJ_Export.dsa
// Get the primary selection to use for the file name var oNode = Scene.getPrimarySelection(); // If something is selected if( oNode ){ // Get the node's skeleton var oSkeleton = oNode.getSkeleton(); // If it has a skeleton if( oSkeleton ) { // That is the node we want for the name oNode = oSkeleton; } } // Get the export manager var oExportMgr = App.getExportMgr(); // Define the class name the for Wavefront Object (*.obj) exporter var sClassName = "DzObjExporter"; // Find the exporter var oExporter = oExportMgr.findExporterByClassName( sClassName ); // If the exporter exists if( oExporter ){ // Create a settings object var oSettings = new DzFileIOSettings(); // Fill the settings object with the default options from the exporter //oExporter.getDefaultOptions( oSettings ); // Set the desired settings for the exporter //oSettings.setStringValue( "Preset", "Poser (1 unit = 8ft)" ); // Set the scale to write the data oSettings.setFloatValue( "Scale", 243.84 ); // Set the lateral axis to X oSettings.setStringValue( "LatAxis", "X" ); // Set the vertical axis to Y oSettings.setStringValue( "VertAxis", "Y" ); // Set the depth axis to Z oSettings.setStringValue( "DepthAxis", "Z" ); // Do not invert the lateral axis oSettings.setBoolValue( "InvertLat", false ); // Do not invert the vertical axis oSettings.setBoolValue( "InvertVert", false ); // Do not invert the depth axis oSettings.setBoolValue( "InvertDepth", false ); // Do not ignore the geometry of invisible nodes oSettings.setBoolValue( "IgnoreInvisible", false ); // Do not weld seams between parent and child bones on legacy figures - deprecated oSettings.setBoolValue( "WeldSeams", false ); // Do not remove vertices that are floating, connected to nothing - i.e. LOD oSettings.setBoolValue( "RemoveUnusedVerts", false ); // Write vertex textures - UVs oSettings.setBoolValue( "WriteVT", true ); // Do not write vertex normals oSettings.setBoolValue( "WriteVN", false ); // Do not write object statements for each root node - i.e. figures, props oSettings.setBoolValue( "WriteO", false ); // Write facet groups oSettings.setBoolValue( "WriteG", true ); // Write facet groups according to whatever the geometry already has oSettings.setBoolValue( "GroupGeom", true ); // Do not write facet groups according to the node it is associated with oSettings.setBoolValue( "GroupNodes", false ); // Do not write facet groups according to surface groups oSettings.setBoolValue( "GroupSurfaces", false ); // Do not write one facet group oSettings.setBoolValue( "GroupSingle", false ); // Write surface groups oSettings.setBoolValue( "WriteUsemtl", true ); // Do not write a material library oSettings.setBoolValue( "WriteMtllib", false ); // Do not collect texture maps oSettings.setBoolValue( "CollectMaps", false ); // Do not convert texture maps oSettings.setBoolValue( "ConvertMaps", false ); // Do not limit export to selection - only available in 4.5.x + oSettings.setBoolValue( "SelectedOnly", false ); // Do not limit export to the selected roots - only available in 4.5.x + oSettings.setBoolValue( "SelectedRootsOnly", false ); // Do not limit export to the primary selected root // This setting overrides SelectedRootsOnly - only available in 4.5.x + oSettings.setBoolValue( "PrimaryRootOnly", false ); // Do not export items that are parented to the selection - only available in 4.5.x + oSettings.setBoolValue( "IncludeParented", false ); // Do not display the options dialog oSettings.setIntValue( "RunSilent", 1 ); // If we've got a node, construct the path using the // exporter's last path, the node's name, and the // exporter's extension... // Otherwise, just use the exporter's last path var sInitialPath = ( oNode ? String( "%1/%2.%3" ) .arg( oExportMgr.getExportPath() ) .arg( oNode.name ) .arg( oExporter.getExtension() ) : oExportMgr.getExportPath() ); // Prompt the user to choose a file, // use the exporter to build the title bar caption, // the initial path and the filter var sPath = FileDialog.doFileDialog( false, String( "Custom Export : %1 : %2" ) .arg( oExporter.getDescription() ) .arg( oSettings.getStringValue( "Preset" ) ), sInitialPath, String( "%1 (*.%2)" ) .arg( oExporter.getDescription() ) .arg( oExporter.getExtension() ) ); // If the user didn't cancel and the file doesn't already // exist, or the user wants to overwrite it if( sPath && MainWindow.checkExistingFile( sPath ) ){ // Write the file using the options specified oExporter.writeFile( sPath, oSettings ); } // We didn't find an exporter with the class name we wanted } else { // Inform the user MessageBox.critical(String("An asset filter with the class name \"%1\" " + "could not be found.").arg( sClassName ), "Critical Error", "&OK"); }
