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

StratDragonStratDragon Posts: 3,245

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,245

    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,245

    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();

     

  • Richard HaseltineRichard Haseltine Posts: 101,422

    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,245

    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: 192

    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.

Sign In or Register to comment.