Hello @JH23,
thank you for reaching out to us. While it is possible to use CallCommand
in scripts for the more basic things like creating a material, it is recommended to use the more abstract object-oriented API whenever possible. Below you will find an example script which creates, modifies and assigns a new material to the currently active object.
Cheers,
Ferdinand
"""Example for creating a material and assigning it to the currently active
object.
As discussed in:
https://plugincafe.maxon.net/topic/13357
"""
import c4d
def main():
"""
"""
# op and doc a are module attributes predefined by Cinema 4D for a script
# module. doc is the currently active document, op the currently active
# object in this active document.
if op is None:
raise RuntimeError("Please select an object.")
# Instantiate a standard material and insert it into the document, as
# otherwise we could not use it.
mat = c4d.BaseList2D(c4d.Mmaterial)
doc.InsertMaterial(mat)
# Example for modifying the material, here setting its diffuse color.
mat[c4d.MATERIAL_COLOR_COLOR] = c4d.Vector(1, 0, 0)
# Create a texture tag on the selected object, change the projection mode
# to uvw and link the newly crated material to it.
tag = op.MakeTag(c4d.Ttexture)
tag[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW
tag[c4d.TEXTURETAG_MATERIAL] = mat
# Notify Cinema 4D of the changes made.
c4d.EventAdd()
# Execute main()
if __name__=='__main__':
main()