Hi,
If you want to change the default material preview scene, the one in the preferences, you must do the following.
wc = c4d.GetWorldContainerInstance()
wc[c4d.WPREF_MATPREVIEW_DEFAULTOBJECT_MAT] = c4d.MatPreviewSphere
The ID that needs to be used can be found here. We have a code that will add 2000000000 to this value if the value is lower than MatPreviewUser (1050). If i remember correctly, users were able to add their own scene preview. With the nodematerial this is not possible anymore.
If you want to change the material preview of a standard material, you must retrieve the material preview data of the material. Unfortunately, this DataType is not implemented in python so this is not possible.
It is possible to change the value of this preview in the preferences and create the material, but it doesn't work if you set back the value that was defined.
from typing import Optional
import c4d
doc: c4d.documents.BaseDocument # The active document
op: Optional[c4d.BaseObject] # The active object, None if unselected
def main() -> None:
wc = c4d.GetWorldContainerInstance()
saveValue = wc[c4d.WPREF_MATPREVIEW_DEFAULTOBJECT_MAT]
wc[c4d.WPREF_MATPREVIEW_DEFAULTOBJECT_MAT] = c4d.MatPreviewSphere
material = c4d.BaseMaterial(c4d.Mmaterial)
doc.InsertMaterial(material)
# this line will make the material preview modification not working
# wc[c4d.WPREF_MATPREVIEW_DEFAULTOBJECT_MAT] = saveValue
c4d.EventAdd()
if __name__ == '__main__':
main()
c4d.EventAdd()
The question about marking a thread as solved, you can have a look at our forum guidelines
Cheers,
Manuel