I want to get material from template file and apply it to project follow the sample material name.
Can you show code C++, or Python? .
It is sample video:
Thanks you very much.
as always, please make yourself familiar with how to post questions on this forum: Read Before Posting
I assume a "template file" is just a C4D-file that stores some materials?
You can load a C4D-File with LoadDocument(). Then you can copy the materials found in that loaded document into the active document. See BaseDocument Manual and BaseMaterial Manual.
# select the c4d file to load
filename = c4d.storage.LoadDialog(type=c4d.FILESELECTTYPE_SCENES, title="Choose File.", flags=c4d.FILESELECT_LOAD, force_suffix="c4d")
if filename is None:
# checks for c4d suffix
name, suffix = os.path.splitext(filename)
if suffix != ".c4d":
raise RuntimeError('Invalid file selected.')
# load the document (materials)
loadedDoc = c4d.documents.LoadDocument(filename, c4d.SCENEFILTER_MATERIALS)
if loadedDoc is None:
raise RuntimeError('Could not load document.')
# get all materials
mat = loadedDoc.GetFirstMaterial()
while mat is not None:
# clone material
clone = mat.GetClone()
if clone is None:
raise RuntimeError('Could not clone material.')
# insert clone into the active document
mat = mat.GetNext()
Thanks s_bach very much.