How to load a preset file?
Hi community
Forgive me - I'm new at this :-)
I'm trying to write a DAZ script that will open a scene from a file, apply some presets, and then save the updated file. The reason for this is that I have several hundreds scenes that I want to update, and it's very time consuming.
What I'm hoping to do is to add material and shaping presets to a specific node in the scenes as well as render settings to the scene in general. As I have 0 experience in Daz scripting I have relied on GPT to help me make a script, but there's just not enough material out there for GPT to make a solid suggestion.
What I do have working so far is opening a scene and saving it again inside a loop of several scenes, but I have not been able to find a command that will succesfully load a preset and apply it to a specific node. Whatever GPT suggests results in an error when executing the script.
This is what I have:
// DAZ Studio version 4.23.0.1 filetype DAZ Script
var sceneFiles = [
"C:/Users/xxx/Documents/DAZ 3D/Tests/Test_Script.duf",
"C:/Users/xxx/Documents/DAZ 3D/Tests/Test_Script2.duf"
];
var presetFilePath = "C:/Users/xxx/Documents/DAZ 3D/Presets/Material.duf";
var outputDirectory = "C:/Users/xxx/Documents/DAZ 3D/Tests/Processed/";
var targetNodeName = "Genesis8Male";
for (var i = 0; i < sceneFiles.length; i++) {
var sceneFilePath = sceneFiles[i];
App.getContentMgr().openNativeFile( sceneFilePath, false ); // Load the current scene (false = Clear previous scene)
Scene.Clear; // Resets the scene to its initial, clean state
// Handle presets
var targetNode = Scene.findNodeByLabel(targetNodeName);
var mergeResult = targetNode.applyPreset(presetFilePath);
Scene.Update;
// Save file
var saveFileName = DzFileInfo(sceneFilePath).baseName() + "_updated.duf"; // Set new filename
var saveFilePath = outputDirectory + saveFileName; // Set new file path
var saveResult = Scene.saveScene(saveFilePath); // Save the scene
}
Everything but the line containing "var mergeResult = targetNode.applyPreset(presetFilePath);" seems to work. I have tried other options like: "Scene.merge(presetFilePath);" and "Scene.mergeInFile(presetFilePath);", but still no cigar.
Is what I'm trying even possible? If so can you point me in the right direction?
Comments
First, clear() is a method not a variable as you have it here. But clearing the scene does just that, like File>New and selecting a blank scene, so it removes the data you had just loaded. That of course means there are no nodes for the next lines to find and so no targets for the presets. Also DzNode does not have an applyPreset( filename ) method - I guess that is ChatGPT inventing stuff again.
Scene.Update() again requires parentheses since it is a method (a function) but I am not sure it is doing anything useful anyway.
Thank you for the input Richard!
I will update the script with the mistakes you pointed out. In fact, I dont think I even need to call the Scene.Clear() function since I'm already loading the scene with the 'false' property.
But... I'm still stuck with not being able to apply the preset after selecting it, because, as you also point out, GPT is inventing nonexisting methods. Any ideas?
Just load (merge) the preset through DzContentMgr - it will be applied to the selected item(s).
I have previously posted an example script to load scene, apply preset to specific node, save scene in this thread, which you should be able to modify to do what you want.
Thank's both of you - this is a great help!