Solved Setting Material Preview for 1 material

I know it is possible to set the material preview in Preferences by
Material[c4d.PREF_MM_MATSCENE] = 2000001008 #Flat projection

When I try to do this for a single material, it is not working.
What am I doing wrong?

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:
    mat = doc.GetActiveMaterial()
    print (mat.GetName(), mat[c4d.PREF_MM_MATSCENE])
    mat[c4d.PREF_MM_MATSCENE] = 2000001008    #Flat projection
    mat.Update(True, True)

if __name__ == '__main__':
    main()
    c4d.EventAdd()

PS How can I set a post to 'Solved"?

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

MAXON SDK Specialist

MAXON Registered Developer

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

MAXON SDK Specialist

MAXON Registered Developer

Thank you.