How do I get the Color value from an RGB node with Python?












6












$begingroup$


I'm a seasoned programmer, but fairly new to blender and 3D-modeling in general. So to get an understanding of different properties I want to write python scripts to create multiple renderings with different settings of various values.



In the example below I have figured out how to change the Volume Absorption Density, ex:



bpy.data.materials['MyMaterial'].node_tree.nodes['Volume Absorption'].inputs['Density'].default_value = 100


But not the RGB-node. It seems I cant even get the current values out of it. Some things I have tried:



bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color
bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color.r
bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color.outputs['Color']


How do I get and set output values of the RGB-node in py python-script?



enter image description here










share|improve this question









New contributor




UlfR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    just fyi here's a script showing how you can build your nodes directly from python: blender.stackexchange.com/q/35436/5334 and here's another blender.stackexchange.com/q/34609/5334
    $endgroup$
    – uhoh
    12 hours ago
















6












$begingroup$


I'm a seasoned programmer, but fairly new to blender and 3D-modeling in general. So to get an understanding of different properties I want to write python scripts to create multiple renderings with different settings of various values.



In the example below I have figured out how to change the Volume Absorption Density, ex:



bpy.data.materials['MyMaterial'].node_tree.nodes['Volume Absorption'].inputs['Density'].default_value = 100


But not the RGB-node. It seems I cant even get the current values out of it. Some things I have tried:



bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color
bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color.r
bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color.outputs['Color']


How do I get and set output values of the RGB-node in py python-script?



enter image description here










share|improve this question









New contributor




UlfR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    just fyi here's a script showing how you can build your nodes directly from python: blender.stackexchange.com/q/35436/5334 and here's another blender.stackexchange.com/q/34609/5334
    $endgroup$
    – uhoh
    12 hours ago














6












6








6


1



$begingroup$


I'm a seasoned programmer, but fairly new to blender and 3D-modeling in general. So to get an understanding of different properties I want to write python scripts to create multiple renderings with different settings of various values.



In the example below I have figured out how to change the Volume Absorption Density, ex:



bpy.data.materials['MyMaterial'].node_tree.nodes['Volume Absorption'].inputs['Density'].default_value = 100


But not the RGB-node. It seems I cant even get the current values out of it. Some things I have tried:



bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color
bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color.r
bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color.outputs['Color']


How do I get and set output values of the RGB-node in py python-script?



enter image description here










share|improve this question









New contributor




UlfR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




I'm a seasoned programmer, but fairly new to blender and 3D-modeling in general. So to get an understanding of different properties I want to write python scripts to create multiple renderings with different settings of various values.



In the example below I have figured out how to change the Volume Absorption Density, ex:



bpy.data.materials['MyMaterial'].node_tree.nodes['Volume Absorption'].inputs['Density'].default_value = 100


But not the RGB-node. It seems I cant even get the current values out of it. Some things I have tried:



bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color
bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color.r
bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].color.outputs['Color']


How do I get and set output values of the RGB-node in py python-script?



enter image description here







python scripting nodes






share|improve this question









New contributor




UlfR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




UlfR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 17 hours ago









Ray Mairlot

22.3k56395




22.3k56395






New contributor




UlfR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 18 hours ago









UlfRUlfR

1334




1334




New contributor




UlfR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





UlfR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






UlfR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • $begingroup$
    just fyi here's a script showing how you can build your nodes directly from python: blender.stackexchange.com/q/35436/5334 and here's another blender.stackexchange.com/q/34609/5334
    $endgroup$
    – uhoh
    12 hours ago


















  • $begingroup$
    just fyi here's a script showing how you can build your nodes directly from python: blender.stackexchange.com/q/35436/5334 and here's another blender.stackexchange.com/q/34609/5334
    $endgroup$
    – uhoh
    12 hours ago
















$begingroup$
just fyi here's a script showing how you can build your nodes directly from python: blender.stackexchange.com/q/35436/5334 and here's another blender.stackexchange.com/q/34609/5334
$endgroup$
– uhoh
12 hours ago




$begingroup$
just fyi here's a script showing how you can build your nodes directly from python: blender.stackexchange.com/q/35436/5334 and here's another blender.stackexchange.com/q/34609/5334
$endgroup$
– uhoh
12 hours ago










2 Answers
2






active

oldest

votes


















9












$begingroup$

Welcome to Blender.SE, UlfR.



Finding out a property in Blender is relatively easy. Make sure, you have python tooltips enabled (in the user preferences).



Then hover your mouse cursor over the property (in this case the color). A tooltip containing the python command will appear.



tooltip



The property you seek seems to be outputs[0].default_value.



def_rgb = bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].outputs[0].default_value


It is a bpy_prop_array by default, so you may want to convert it to a list.



float_values = list(def_rgb)





share|improve this answer









$endgroup$













  • $begingroup$
    Miceterminator beat me to it by 3 minutes. I will leave this answer up, as it mentions the python tooltip and his doesn't you could accept his answer as the correct one however.
    $endgroup$
    – Leander
    17 hours ago










  • $begingroup$
    my problem was that bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value = (1.0,1.0,0.5,1.0) works but bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value produces nothing in the Python console. Converting it to list then displayed the hidden values.
    $endgroup$
    – rob
    17 hours ago










  • $begingroup$
    You can also access the individual values directly from the bpy_prop_array via their indices, such as def_rgb[0].
    $endgroup$
    – Leander
    7 hours ago





















6












$begingroup$

As you already found you way to the node tree, the "Copy data path" option is generally very helpful:



Right click on the field you want to access and use the "Copy data path" option.



bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].outputs[0].default_value



You can also look at the answers here and here



How to get data access to the data path






share|improve this answer











$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "502"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    UlfR is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fblender.stackexchange.com%2fquestions%2f132142%2fhow-do-i-get-the-color-value-from-an-rgb-node-with-python%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    9












    $begingroup$

    Welcome to Blender.SE, UlfR.



    Finding out a property in Blender is relatively easy. Make sure, you have python tooltips enabled (in the user preferences).



    Then hover your mouse cursor over the property (in this case the color). A tooltip containing the python command will appear.



    tooltip



    The property you seek seems to be outputs[0].default_value.



    def_rgb = bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].outputs[0].default_value


    It is a bpy_prop_array by default, so you may want to convert it to a list.



    float_values = list(def_rgb)





    share|improve this answer









    $endgroup$













    • $begingroup$
      Miceterminator beat me to it by 3 minutes. I will leave this answer up, as it mentions the python tooltip and his doesn't you could accept his answer as the correct one however.
      $endgroup$
      – Leander
      17 hours ago










    • $begingroup$
      my problem was that bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value = (1.0,1.0,0.5,1.0) works but bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value produces nothing in the Python console. Converting it to list then displayed the hidden values.
      $endgroup$
      – rob
      17 hours ago










    • $begingroup$
      You can also access the individual values directly from the bpy_prop_array via their indices, such as def_rgb[0].
      $endgroup$
      – Leander
      7 hours ago


















    9












    $begingroup$

    Welcome to Blender.SE, UlfR.



    Finding out a property in Blender is relatively easy. Make sure, you have python tooltips enabled (in the user preferences).



    Then hover your mouse cursor over the property (in this case the color). A tooltip containing the python command will appear.



    tooltip



    The property you seek seems to be outputs[0].default_value.



    def_rgb = bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].outputs[0].default_value


    It is a bpy_prop_array by default, so you may want to convert it to a list.



    float_values = list(def_rgb)





    share|improve this answer









    $endgroup$













    • $begingroup$
      Miceterminator beat me to it by 3 minutes. I will leave this answer up, as it mentions the python tooltip and his doesn't you could accept his answer as the correct one however.
      $endgroup$
      – Leander
      17 hours ago










    • $begingroup$
      my problem was that bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value = (1.0,1.0,0.5,1.0) works but bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value produces nothing in the Python console. Converting it to list then displayed the hidden values.
      $endgroup$
      – rob
      17 hours ago










    • $begingroup$
      You can also access the individual values directly from the bpy_prop_array via their indices, such as def_rgb[0].
      $endgroup$
      – Leander
      7 hours ago
















    9












    9








    9





    $begingroup$

    Welcome to Blender.SE, UlfR.



    Finding out a property in Blender is relatively easy. Make sure, you have python tooltips enabled (in the user preferences).



    Then hover your mouse cursor over the property (in this case the color). A tooltip containing the python command will appear.



    tooltip



    The property you seek seems to be outputs[0].default_value.



    def_rgb = bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].outputs[0].default_value


    It is a bpy_prop_array by default, so you may want to convert it to a list.



    float_values = list(def_rgb)





    share|improve this answer









    $endgroup$



    Welcome to Blender.SE, UlfR.



    Finding out a property in Blender is relatively easy. Make sure, you have python tooltips enabled (in the user preferences).



    Then hover your mouse cursor over the property (in this case the color). A tooltip containing the python command will appear.



    tooltip



    The property you seek seems to be outputs[0].default_value.



    def_rgb = bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].outputs[0].default_value


    It is a bpy_prop_array by default, so you may want to convert it to a list.



    float_values = list(def_rgb)






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 17 hours ago









    LeanderLeander

    12.2k11549




    12.2k11549












    • $begingroup$
      Miceterminator beat me to it by 3 minutes. I will leave this answer up, as it mentions the python tooltip and his doesn't you could accept his answer as the correct one however.
      $endgroup$
      – Leander
      17 hours ago










    • $begingroup$
      my problem was that bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value = (1.0,1.0,0.5,1.0) works but bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value produces nothing in the Python console. Converting it to list then displayed the hidden values.
      $endgroup$
      – rob
      17 hours ago










    • $begingroup$
      You can also access the individual values directly from the bpy_prop_array via their indices, such as def_rgb[0].
      $endgroup$
      – Leander
      7 hours ago




















    • $begingroup$
      Miceterminator beat me to it by 3 minutes. I will leave this answer up, as it mentions the python tooltip and his doesn't you could accept his answer as the correct one however.
      $endgroup$
      – Leander
      17 hours ago










    • $begingroup$
      my problem was that bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value = (1.0,1.0,0.5,1.0) works but bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value produces nothing in the Python console. Converting it to list then displayed the hidden values.
      $endgroup$
      – rob
      17 hours ago










    • $begingroup$
      You can also access the individual values directly from the bpy_prop_array via their indices, such as def_rgb[0].
      $endgroup$
      – Leander
      7 hours ago


















    $begingroup$
    Miceterminator beat me to it by 3 minutes. I will leave this answer up, as it mentions the python tooltip and his doesn't you could accept his answer as the correct one however.
    $endgroup$
    – Leander
    17 hours ago




    $begingroup$
    Miceterminator beat me to it by 3 minutes. I will leave this answer up, as it mentions the python tooltip and his doesn't you could accept his answer as the correct one however.
    $endgroup$
    – Leander
    17 hours ago












    $begingroup$
    my problem was that bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value = (1.0,1.0,0.5,1.0) works but bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value produces nothing in the Python console. Converting it to list then displayed the hidden values.
    $endgroup$
    – rob
    17 hours ago




    $begingroup$
    my problem was that bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value = (1.0,1.0,0.5,1.0) works but bpy.data.materials[1].node_tree.nodes['RGB'].outputs[0].default_value produces nothing in the Python console. Converting it to list then displayed the hidden values.
    $endgroup$
    – rob
    17 hours ago












    $begingroup$
    You can also access the individual values directly from the bpy_prop_array via their indices, such as def_rgb[0].
    $endgroup$
    – Leander
    7 hours ago






    $begingroup$
    You can also access the individual values directly from the bpy_prop_array via their indices, such as def_rgb[0].
    $endgroup$
    – Leander
    7 hours ago















    6












    $begingroup$

    As you already found you way to the node tree, the "Copy data path" option is generally very helpful:



    Right click on the field you want to access and use the "Copy data path" option.



    bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].outputs[0].default_value



    You can also look at the answers here and here



    How to get data access to the data path






    share|improve this answer











    $endgroup$


















      6












      $begingroup$

      As you already found you way to the node tree, the "Copy data path" option is generally very helpful:



      Right click on the field you want to access and use the "Copy data path" option.



      bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].outputs[0].default_value



      You can also look at the answers here and here



      How to get data access to the data path






      share|improve this answer











      $endgroup$
















        6












        6








        6





        $begingroup$

        As you already found you way to the node tree, the "Copy data path" option is generally very helpful:



        Right click on the field you want to access and use the "Copy data path" option.



        bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].outputs[0].default_value



        You can also look at the answers here and here



        How to get data access to the data path






        share|improve this answer











        $endgroup$



        As you already found you way to the node tree, the "Copy data path" option is generally very helpful:



        Right click on the field you want to access and use the "Copy data path" option.



        bpy.data.materials['MyMaterial'].node_tree.nodes['RGB'].outputs[0].default_value



        You can also look at the answers here and here



        How to get data access to the data path







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 17 hours ago

























        answered 17 hours ago









        miceterminatormiceterminator

        1,94621124




        1,94621124






















            UlfR is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            UlfR is a new contributor. Be nice, and check out our Code of Conduct.













            UlfR is a new contributor. Be nice, and check out our Code of Conduct.












            UlfR is a new contributor. Be nice, and check out our Code of Conduct.
















            Thanks for contributing an answer to Blender Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fblender.stackexchange.com%2fquestions%2f132142%2fhow-do-i-get-the-color-value-from-an-rgb-node-with-python%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Polycentropodidae

            Magento 2 Error message: Invalid state change requested

            Paulmy