Silent Export without showing options AND without showing File Dialog

I have been playing around with the publicly available "Export Selected Object" script. 

http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/file_io/export_obj_silent/start

I use this script in order to export an obj that I later load into blender. 

I need to do this for about 3 to 4 things and really just want to hit the button in DAZ that will eport it as my !!ToBlender filename without asking me via a filedialog.  I know its super lazy to not hit enter and then YES but I figured this has to be possible.  What do I need to change in the FileDialog part in order to get my obj with the settings below to just WriteFile without the file dialog?

 

I have pasted my current script below.

 

 

// DAZ Studio version 4.9.4.117 filetype DAZ Script// Define an anonymous function;// serves as our main loop,// limits the scope of variables(function(){ 	// 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 ); 		// Define whether or not to show options		var bShowOptions = false; 		// Define whether or not to show options before prompting for a path;		// requires 4.9.3.22 or later		var bOptionsBeforeFile = (bShowOptions && App.version64 >= 0x0004000900030016); 		// Get the options for the exporter		if( !oExporter.getOptions( oSettings, bShowOptions && bOptionsBeforeFile, "" ) ){			// We're done...			return;		} 		// Debug		//print( oSettings.toJsonString() ); 		// 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 ); 		// If the version is 4.5.0.114 or newer		if( App.version64 >= 0x0004000500000072 ){			// Do not limit export to selection			oSettings.setBoolValue( "SelectedOnly", true );			// Do not limit export to the selected roots			oSettings.setBoolValue( "SelectedRootsOnly", true );			// Do not limit export to the primary selected root;			// this setting overrides SelectedRootsOnly			oSettings.setBoolValue( "PrimaryRootOnly", false );			// Do not export items that are parented to the selection			oSettings.setBoolValue( "IncludeParented", false );			// Do not triangulate n-gons			oSettings.setBoolValue( "TriangulateNgons", false );		} 		// If the version is 4.9.3.22 or newer		if( App.version64 >= 0x0004000900030016 ){			// Do not collapse UVs Tiles			oSettings.setBoolValue( "CollapseUVTiles", false ); 			// Show individual settings in the dialog			oSettings.setBoolValue( "ShowIndividualSettings", false );		} 		// Define whether or not to show the options after prompting for a file		oSettings.setIntValue( "RunSilent", (bShowOptions && !bOptionsBeforeFile ? 0 : 1) ); 		// Debug		//print( oSettings.toJsonString() ); 		// 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" ) ),			"M:/M_Daz/Blender/!!toBlender",			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 );		} 		// Clean up; don't leak memory		oExporter.deleteLater();	// We didn't find an exporter with the class name we wanted	} else {		// Inform the user		MessageBox.critical( qsTr("An exporter with the class name \"%1\" " +			"could not be found.").arg( sClassName ),			qsTr("Critical Error"), qsTr("&OK") );	} // Finalize the function and invoke})();

 

 

Thanks so much

Comments

  • Richard HaseltineRichard Haseltine Posts: 97,254
    edited February 2018

    Comment out the whole file dialogue section and then in the immeditely preceeding section change

    .arg( oExportMgr.getExportPath() ).arg( oNode.name ) 

    to

    .arg( "MYPath" ).arg( "!!ToBlender" )

    though if you are going to export multiple items you will need to add an index to that.

    Post edited by Richard Haseltine on
  • The master answers again!  I appreciate the quick reply however I am not quite able to get this to work.  When I comment out the file dialog it seems to be part of an entire statement.  It all ends on the line with a ; at the end.

    Exactly which line do I comment out? Can you show me a bit more of the edited script so I know what to do.  I tried a couple things with your instructions and keep getting compile errors.

     

    Thanks

     

  • Sorry, I misread the script - you need to set sPath (using the code to set sInitialPath above, or just hard-coding your desired path of course) to the fiel you want to save.

  • jerickson_jeljerickson_jel Posts: 52
    edited February 2018

    No worries at all.  I understand what you meant now.  I have adjusted the script above and it works. 

    // DAZ Studio version 4.9.4.117 filetype DAZ Script// Define an anonymous function;// serves as our main loop,// limits the scope of variables(function(){ 	// 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 ); 		// Define whether or not to show options		var bShowOptions = false; 		// Define whether or not to show options before prompting for a path;		// requires 4.9.3.22 or later		var bOptionsBeforeFile = (bShowOptions && App.version64 >= 0x0004000900030016); 		// Get the options for the exporter		if( !oExporter.getOptions( oSettings, bShowOptions && bOptionsBeforeFile, "" ) ){			// We're done...			return;		} 		// Debug		//print( oSettings.toJsonString() ); 		// 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 ); 		// If the version is 4.5.0.114 or newer		if( App.version64 >= 0x0004000500000072 ){			// Do not limit export to selection			oSettings.setBoolValue( "SelectedOnly", true );			// Do not limit export to the selected roots			oSettings.setBoolValue( "SelectedRootsOnly", true );			// Do not limit export to the primary selected root;			// this setting overrides SelectedRootsOnly			oSettings.setBoolValue( "PrimaryRootOnly", false );			// Do not export items that are parented to the selection			oSettings.setBoolValue( "IncludeParented", false );			// Do not triangulate n-gons			oSettings.setBoolValue( "TriangulateNgons", false );		} 		// If the version is 4.9.3.22 or newer		if( App.version64 >= 0x0004000900030016 ){			// Do not collapse UVs Tiles			oSettings.setBoolValue( "CollapseUVTiles", false ); 			// Show individual settings in the dialog			oSettings.setBoolValue( "ShowIndividualSettings", false );		} 		// Define whether or not to show the options after prompting for a file		oSettings.setIntValue( "RunSilent", (bShowOptions && !bOptionsBeforeFile ? 0 : 1) ); 		// Debug		//print( oSettings.toJsonString() ); 		// 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() ); 		//This contains the main change.  Hardcode the path and name.		var sPath = String("M:/M_Daz/Blender/!!ToBlender4.obj"); 		// comment out the file exists check.		//if( sPath && MainWindow.checkExistingFile( sPath ) ){			// Write the file using the options specified			oExporter.writeFile( sPath, oSettings ); //write the file		//} 		// Clean up; don't leak memory		oExporter.deleteLater();	// We didn't find an exporter with the class name we wanted	} else {		// Inform the user		MessageBox.critical( qsTr("An exporter with the class name \"%1\" " +			"could not be found.").arg( sClassName ),			qsTr("Critical Error"), qsTr("&OK") );	} // Finalize the function and invoke})();

     

     

    Thanks again so much.  You are so very helpful.

     

    Post edited by jerickson_jel on
  • Not sure why my code snippet is not formatting but there it is either way.

  • You're welcome.

    The code displays oddly after you post, the page doesn't seem to load in quite the same way - other things, such as post count, also behave oddly until the page is refreshed. The code looks OK now.

Sign In or Register to comment.