help with a script idea (IOR value insert) , and I no idea how to write one
StratDragon
Posts: 3,273
I made a list of IOR values and the material names. I would like to create a script that lists the names and the values that allows the opperator to select the value and it will change only the IOR value in whatever shader you have. Can this be done? Is this aready done? Does no one want this done? thank you.
Post edited by Richard Haseltine on

Comments
Moved to the Script Development forum since it si not an offer of a freebie.
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/properties/material_properties/start shows how to access material properties, several other scripts in http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/start#properties show how to manipulate properties.
http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/general_ui/simple_dialog/start shows how to build a simple dialogue
If you use sections of there make sure you respect the the CC 3 license terms, as linked from each page, should you wish to share the results.
thanks!
for clarity I asked chatgpt to write this for me but I get Script Error:
Line 53 TypeError: Result of expression 'Scene.getSelectedNodes' [undefined] is not a function.
Stack Trace: ()@:53
I've asked chat gpt to find and fix the error but it has not been successful. based on the original ask in this thread can anyone see what is the point(s) of failure?
Well, trusting ChatGPT....
Specifically, check the things it is doing - if you go to DzScene http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/scene_dz then you will see that indeed there is no getSelectedNodes() method, What there is is a getSelctedNodeList method http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/scene_dz#a_1aed50f135a75070c3a9a06e851e97941f
You might also want to look at DzNode, which has no getSurface( index ) or isMesh members so the script would fail there too. Nor does DzMaterial have a function for settings an IoR - that is not a basic feature, you would need instead to find the proeprty using the emthod for the base DzElement, and you woiuld need to get the nodes shape to get its materials in the first place.
At least ChatGPT got soemthing like the correct format (in the past it has produced Python scripts) but it is still confabulating, inventing methods to match the general pattern of the scripts it has digested and the names that are triggered by the prompt - it has no actual knowledge on which to build and is incapable of any kind of critical evaluation of its output.
Sorry to beat this at length, but if you want soemthing that hasn't already been done - with slight variantions - multiple times before you are unlikely to get usable code out of generative AI.
truth be told, I'm not a fan of AI, but one forum suggested it, I figured I'd give it a shot. thanks again.
Current chatgpt knows javascript very well, but not specifically DAZ script and its functions. It will get you 75% of the way there, the rest is on you to make sure the code looks good and works. Reading and troubleshooting code will be required.
Would it be an issue with the CC license for the API documentation to be fed into an LLM so that it could generate more correct code? Not from a product point of view or for public facing thing, but it seems like if the the API documentation was in a format that could be digested by an LLM as "instructional context", it would generate more accurate scripts. Not sure what the licensing concerns are there though.
EDIT: I ran a little experiment, and I was able to use the public API documentation, refactoring it into a TypeScript API spec, as a context for an LLM and instruct it to generate a DAZ script, which worked perfectly. The example prompt was:
I am writing a DAZ script. Please use the attached TypeScript definition file, named daz_api_reference.d.ts, as the API reference for all the code you generate.
Typescript
// Paste API spec file here
Now, please write a script that performs the following task:
Do a batch render of the current scene, doing an individual render for each visible camera in the scene. The result of each render should be saved to a separate file, with the file name format as: scene file name + _ + camera label + .png
It generated a well documented DAZ script which executed the batch render and saved each file with the filename as instructed. This is a very simple script, and I'm sure more complex tasks would not work as perfectly, but it would be very interesting to see how far you could push it. I should note that the token cost for the API reference is substantial (on the order of 400K), so you're not going to be able to do this with LLM models that don't have a very large context window. I used Google Gemini 2.5-pro for my test.
Did AI tell you that there is a script that does that for you already by mCasual and myself. Check out mCasual pages. We have a few versions of script that will render each camera in your scene to a separate folder and some will even create MOV or GIF file from the results.
Of course, I am well familiar with your scripts! The goal was to see how well AI works to interpret the Typescript specification for DAZ scripting API. It definitely has some quirks, but as a first pass to create the bones of a script it's actually not that bad. For instance, just using the specification as is without further context refinements more often than not creates scripts with errors in very specific ways -- how to handle App and Scene globals for one.