Trying to access color vectors via python (color v



  • On 25/04/2017 at 02:49, xxxxxxxx wrote:

    A seemingly simple task: trying to copy the color value from one material to another via a python tag. I'm able to access and copy most other attributes, but the color value, represented as a vector, is a little over my head.

    If I look at the material's color value in the console via the print command, such as:

    print material_1[c4d.MATERIAL_COLOR] 
    I get a return of: Vector(0.7,0.5,0.5)

    I can manually assign these values to another material via the c4d.Vector() command, however I can't figure out the correct syntax to pass them to a variable or item via python.

    While the [c4d.MATERIAL_COLOR] seems to hold the correct vector values, it's not recognized by python as a vector. I've been playing with the Vector__getitem__() command, but so far I've botched it.

    any insight would be appreciated. (ps. I'm not a python guy, so if it gets too invloved, I can always do the ol' set driver/set driven expresso dance, but I'm trying to reduce my clicks.

    thanks,
    Mike



  • On 25/04/2017 at 03:41, xxxxxxxx wrote:

    Take a look at https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d/Vector/index.html?highlight=vector

    Basicly if you want to acces to the first value you have to say

    material_1[c4d.MATERIAL_COLOR].x #will be 0.7
    

    You can do

    myVariable = material_1[c4d.MATERIAL_COLOR] #myVariable will store the current data of material_1[c4d.MATERIAL_COLOR]
      
    #assign the value to another mat
    material_2[c4d.MATERIAL_COLOR] = myVariable
      
    #notify the scene has changed
    c4d.EventAdd()
    


  • On 25/04/2017 at 06:20, xxxxxxxx wrote:

    Thanks for the help. I did some troubleshooting and realized that the ID I was using was coming from the tag name rather than the material name. Now  I'm getting proper vector values.

    -Mike



  • On 25/04/2017 at 08:14, xxxxxxxx wrote:

    I might have spoken too soon. I've gotten the function to work for C4D materials, but trying to use this tag with Arnold shaders is causing problems. What I'm trying to do is take the color value from the texture tag and apply it to the object's "use color" attribute. This way I can see my material colors in the editor while using Arnold shaders (which default to white). Below is my working code for C4D materials and my non-working code for using Arnold shaders:

    Works with standard C4D shaders, takes the color from the first tag:

    def main() :
        obj = op.GetObject()
        SourceTag = obj.GetFirstTag()
        SourceName = SourceTag[c4d.ID_BASELIST_NAME]
        MatName = SourceTag[c4d.TEXTURETAG_MATERIAL]
        SourceVector = c4d.Vector(MatName[c4d.MATERIAL_COLOR_COLOR])

    obj[c4d.ID_BASELIST_NAME] = SourceTag[c4d.ID_BASELIST_NAME]
        obj[c4d.ID_BASEOBJECT_USECOLOR] = 2
        obj[c4d.ID_BASEOBJECT_COLOR] = SourceVector

    Trying to do the same with Arnold Shaders, but drilling down into the standard_surface node isn't working:

    def main() :
        obj = op.GetObject()
        SourceTag = obj.GetFirstTag()
        TextureName = SourceTag[c4d.ID_BASELIST_NAME]
        MatName = SourceTag[c4d.TEXTURETAG_MATERIAL]
        ShaderName = MatName[c4d.C4DAI_SNMATERIAL_SHADER]
        ArnoldVector = c4d.Vector(ShaderName[1044225467])

    obj[c4d.ID_BASELIST_NAME] = SourceTag[c4d.ID_BASELIST_NAME]
        obj[c4d.ID_BASEOBJECT_USECOLOR] = 2
        obj[c4d.ID_BASEOBJECT_COLOR] = ArnoldVector



  • On 25/04/2017 at 09:56, xxxxxxxx wrote:

    Since arnold is node based it use a custom shader and it's why it doesn't work
    Have a look at their api https://support.solidangle.com/display/AFCUG/Shader+Network+|+Python



  • On 26/04/2017 at 10:02, xxxxxxxx wrote:

    Hi Mike,

    welcome to our Plugin Café forums 🙂

    Good to see, how gr4ph0s is doing our job here. Thanks, gr4ph0s!

    In general MAXON's SDK Team can't provide support for 3rd party plugins and gr4ph0s is absolutely right, Solid Angle will be your best source of information here.

    As I saw you were first asking on CGTalk, I'd just like to mention our Developers Blog, as it may contain a few links to for example documentation, you may find useful.



  • On 09/06/2017 at 20:24, xxxxxxxx wrote:

    Hi Mike!

    I've made this script to work with the colors materials from arnold or any render engine: Geo Color v1.0

    Cheers!


Log in to reply