You can do it this way:
Code: Select allimport c4d
ID_MXMATERIAL = 1021237;
ID_MXMFILENAME = 1002;
def main():
material = c4d.BaseMaterial(ID_MXMATERIAL);
material[ID_MXMFILENAME] = "C:\\carpaint_cherry.mxm";
doc.InsertMaterial(material);
doc.SetActiveMaterial(material);
c4d.EventAdd();
if __name__=='__main__':
main()
There is a slight problem with this, though, since it sets the path through the material's description; what will happen is that the plugin will pop up a dialog asking you if you really want to overwrite the material with the specified MXM. This is because switching from embedded mode to linked mode is a destructive action, even if the material in question was just created a half-second ago. To get around that, you can pre-set the MXM path to a different, valid path first, directly through the material's BaseContainer, then set the path you actually want, like this:
Code: Select allimport c4d
ID_MXMATERIAL = 1021237;
ID_MXMFILENAME = 1002;
def main():
material = c4d.BaseMaterial(ID_MXMATERIAL);
data = material.GetDataInstance();
data.SetFilename(ID_MXMFILENAME, "C:\\dummy.mxm");
material[ID_MXMFILENAME] = "C:\\carpaint_cherry.mxm";
doc.InsertMaterial(material);
doc.SetActiveMaterial(material);
c4d.EventAdd();
if __name__=='__main__':
main()
In this case, the plugin will not warn you about damaging an existing embedded material, since the material already links to a different MXM file.