Hello; I got another Python interface issue...
If I create a BaseMaterial with the parameter c4d.Mmaterial, the return value is a BaseMaterial. Sounds right at first, but actually C4D creates an object of the subclass Material - this is not reflected in the object that the constructor returns though.
Have a look at this script:
import c4d from c4d import gui def main(): doc.StartUndo() myMat = c4d.BaseMaterial(c4d.Mmaterial) print type(myMat), myMat doc.InsertMaterial(myMat,checknames=False) myMat.Message(c4d.MSG_UPDATE) myMat.Update(True, True) doc.AddUndo(c4d.UNDOTYPE_NEW, myMat) doc.EndUndo() c4d.EventAdd() thatMat = doc.GetFirstMaterial() print type(thatMat), thatMat if __name__=='__main__': main()
Run it on an empty scene to ensure that myMat and thatMat are the same material. The two print commands will show that:
<type 'c4d.BaseMaterial'> <c4d.BaseMaterial object called 'Mat/Mat' with ID 5703 at 0x000001CB50DC3D10> <type 'c4d.Material'> <c4d.Material object called 'Mat/Mat' with ID 5703 at 0x000001CB50DC3C30>
Two different types for the same object. Obviously the constructor call ignores the subclass in Python, and generates a BaseMaterial object on the Python side that is connected to a C++ Material object.
I'm not sure whether this can cause issues...
As a solution, I can naturally just use the Material constructor, but it looks like a bug, considering that the same does NOT happen with BaseObject:
import c4d from c4d import gui def main(): doc.StartUndo() myObj = c4d.BaseObject(c4d.Ocamera) print type(myObj), myObj doc.InsertObject(myObj,checknames=False) doc.AddUndo(c4d.UNDOTYPE_NEW, myObj) doc.EndUndo() c4d.EventAdd() thatObj = doc.GetFirstObject() print type(thatObj), thatObj if __name__=='__main__': main()
returns (as expected)
<type 'c4d.CameraObject'> <c4d.CameraObject object called 'Camera/Camera' with ID 5103 at 0x000001CB624FF2B0> <type 'c4d.CameraObject'> <c4d.CameraObject object called 'Camera/Camera' with ID 5103 at 0x000001CB50DA42B0>
So, the Python "interfacing layer" is able to create the correct class, it's just not doing that for the BaseMaterial.
Note that I found several conflicting information in the forum here, including that c4d.Material is deprecated (this is obviously not the case as it contains the functions for Reflectance), and that several functions return a BaseMaterial instead of a Material (confirmed in an old thread; no idea whether this is still the case).