question

ratus ra avatar image
ratus ra asked ·

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

colorpython
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Stephen Blair avatar image
Stephen Blair answered ·

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

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

ratus ra avatar image
ratus ra answered ·

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

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

ratus ra avatar image
ratus ra answered ·

reCPATCHA sucks

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

ratus ra avatar image
ratus ra answered ·

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()
Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Peter Horvath avatar image
Peter Horvath answered ·

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.

Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.