help with a script idea (IOR value insert) , and I no idea how to write one

StratDragonStratDragon 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.

  • StratDragonStratDragon Posts: 3,273

    Richard Haseltine said:

    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!

  • StratDragonStratDragon Posts: 3,273

    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?

     

    // Daz Studio Script to Change IOR Based on Selected Material// Define IOR values for common materialsvar iorList = {    "Air": 1.0003,    "Water": 1.333,    "Glass": 1.5,    "Diamond": 2.42,    "Diamond (High)": 2.42,    "Rubber": 1.45,    "Metal": 2.5,    "Oil": 1.46};// Function to create a dialog for the user to select IOR valuefunction selectIORValue() {    var dialog = new DzDialog();    dialog.setTitle("Select IOR Value");    // Create a combo box to choose the material    var comboBox = new DzComboBox(dialog);    comboBox.setGeometry(10, 10, 200, 25);    comboBox.setEditable(false);    // Populate combo box with IOR material names    for (var material in iorList) {        comboBox.addItem(material);    }    // Create OK button    var okButton = new DzPushButton(dialog);    okButton.setGeometry(10, 50, 75, 30);    okButton.setText("OK");    // Create Cancel button    var cancelButton = new DzPushButton(dialog);    cancelButton.setGeometry(100, 50, 75, 30);    cancelButton.setText("Cancel");    // Show the dialog and wait for user interaction    dialog.exec();    if (dialog.result() === 1) {  // OK button clicked        return comboBox.currentText(); // Return the selected material    } else {        return null;  // Return null if Cancel is clicked    }}// Main functionfunction setIOROnSelectedSurface() {    // Get the currently selected nodes in the scene    var selectedNodes = Scene.getSelectedNodes();    if (selectedNodes.length === 0) {        // Display error if no nodes are selected        MessageBox.error("No surface selected. Please select a surface first.");        return;    }    // Get the first selected node    var selectedNode = selectedNodes[0];    // Check if the node has a surface (it must be a mesh object or similar)    if (!selectedNode.isMesh()) {        MessageBox.error("The selected node does not have a surface.");        return;    }    // Get the selected surface (first surface for simplicity)    var surface = selectedNode.getSurface(0);  // Get the first surface    // Get IOR value by user selection    var selectedMaterial = selectIORValue();    if (selectedMaterial === null) {        return;  // User canceled, exit the script    }    // Get the corresponding IOR value from the list    var iorValue = iorList[selectedMaterial];    if (iorValue === undefined) {        MessageBox.error("Selected material does not have an IOR value.");        return;    }    // Set the IOR value to the selected surface    surface.setIndexOfRefraction(iorValue);    // Confirm the change    MessageBox.information("The IOR for " + selectedMaterial + " has been applied.");}// Run the main functionsetIOROnSelectedSurface();

     

  • 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.

  • StratDragonStratDragon Posts: 3,273

    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.

  • cain-xcain-x Posts: 206

    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.

  • sidcarton1587sidcarton1587 Posts: 54
    edited October 21

    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. 

    Post edited by sidcarton1587 on
  • TugpsxTugpsx Posts: 792

    sidcarton1587 said:

    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. 

  • Tugpsx said:

    sidcarton1587 said:

    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. 

Sign In or Register to comment.