Community
Arnold for Cinema 4D Forum
Rendering with Arnold in CINEMA 4D using the C4DtoA plug-in.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

C4DtoA : Get diffuse color of standard_surface with python

5 REPLIES 5
Reply
Message 1 of 6
brokanteur
551 Views, 5 Replies

C4DtoA : Get diffuse color of standard_surface with python

Hello,

Is there a way to get the diffuse color of standard_surface with python ?

I have tried in a python node :

matlist = doc.GetMaterials()

mat = doc.SearchMaterial("AR Tire Sculpture (Ford A)")

print mat[c4d.MATERIAL_COLOR_COLOR]

But I get none, I think it's only for c4d basematerial

Thanks you

Tags (2)
Labels (2)
5 REPLIES 5
Message 2 of 6
Stephen.Blair
in reply to: brokanteur

You mean the base color? See "Modifying Parameters" here: https://support.solidangle.com/x/lgBeAg



// Stephen Blair
// Arnold Renderer Support
Message 3 of 6
brokanteur
in reply to: brokanteur

Thank you Stephen

However, I feel a little lost with this code as I have tried this but I get an error "NameError: global name 'C4DTOA_MSG_TYPE' is not defined"

I would like to get the vector value (color) of the arnold material named "standard_surface"

Is there any library to import ?

Thanks

import c4d
from c4d import gui
#Welcome to the world of Python


def main():

mat = doc.SearchMaterial("standard_surface")
print mat

# query the network
msg = c4d.BaseContainer()
msg.SetInt32(C4DTOA_MSG_TYPE, C4DTOA_MSG_QUERY_SHADER_NETWORK)
mat.Message(c4d.MSG_BASECONTAINER, msg)

# modify parameter
shader = msg.GetLink(C4DTOA_MSG_RESP3)
C4DAIP_STANDARD_SURFACE_BASE_COLOR = 1044225467
shader[C4DAIP_STANDARD_SURFACE_BASE_COLOR] = c4d.Vector(0.9, 0.9, 0.4)

# trigger update
c4d.EventAdd()

if __name__=='__main__':
main()

Message 4 of 6
brokanteur
in reply to: brokanteur

reCPATCHA sucks

Message 5 of 6
brokanteur
in reply to: brokanteur

got it, I have to declare some missing constants :

import c4d
from c4d import gui
#Welcome to the world of Python
# from res/description/ainode_image.h
C4DAIP_IMAGE_FILENAME = 1737748425
C4DTOA_MSG_TYPE = 1000         
C4DTOA_MSG_RESP3 = 2013
C4DTOA_MSG_QUERY_SHADER_NETWORK = 1028
C4DAIP_STANDARD_SURFACE_BASE_COLOR = 1044225467
def main():
    mat = doc.SearchMaterial("standard_surface")
    print mat
    # query the network
    msg = c4d.BaseContainer()
    msg.SetInt32(C4DTOA_MSG_TYPE, C4DTOA_MSG_QUERY_SHADER_NETWORK)
    mat.Message(c4d.MSG_BASECONTAINER, msg)
    # modify parameter
    shader = msg.GetLink(C4DTOA_MSG_RESP3)
    print shader[C4DAIP_STANDARD_SURFACE_BASE_COLOR]
    # trigger update
    c4d.EventAdd()
if __name__=='__main__':
    main()
Message 6 of 6

The shader network is an Xpresso graph attached to the material, which is a custom solution and the C4D python SDK does not offer any method to access it directly. That's why it works now via messages. If I have some time I will move this code to a module, so you don't have to worry about sending messages and ids and whatnot.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report