On 10/01/2016 at 08:26, xxxxxxxx wrote:
Hi,
In order to automate my workflow I am trying the create a new Bodypaint Texture for multiple objects in the scene.
Starting with a single object I am getting nowhere.
import c4d
import c4d.modules.bodypaint as BP
def main() :
c4d.CallCommand(13957) # Clear Console
doc = c4d.documents.GetActiveDocument() # Get the open document
obj = doc.GetActiveObject()
if not obj.CheckType(c4d.Opolygon) :
return
doc.StartUndo()
filename = "C:\\Temp\\CreateNewTexture via python.png"
settings = c4d.BaseContainer()
settings[c4d.TEXTURE_FILEFORMAT] = c4d.FILTER_PNG
settings[c4d.TEXTURE_WIDTH] = 1024
settings[c4d.TEXTURE_HEIGHT] = 1024
settings[c4d.TEXTURE_MODE] = c4d.COLORMODE_RGB
tex = BP.PaintTexture.CreateNewTexture(filename, settings)
if tex:
layer = tex.GetFirstLayer()
if layer and layer.IsInstanceOf(c4d.OBJECT_PAINTLAYERBMP) :
print layer.GetBw(), layer.GetBh()
BP.PaintTexture.SetSelected_Texture(layer, ???) <-- 'None' is not allowed as second parameter, but PaintMaterial can not be instantiated
doc.EndUndo()
c4d.EventAdd()
print "Done"
if __name__=='__main__':
main()
From the different discussions on this forum I have been able to assemble the above code, which was reported would work with the C++ SDK. However, I am unable to select the texture after having created it, since the second argument is the issue. The documentation mentions to use 'None' but that isn't accepted.
After I run the script I can see the newly created texture listed in the Texture menuitem of the TextureView of the UVedit layout. However, if I try to select this texture the application freezes.
Another trial and error results in the same issue.
...
tex = BP.PaintTexture.CreateNewTexture(filename, settings)
if tex:
layer = tex.GetFirstLayer()
if layer and layer.IsInstanceOf(c4d.OBJECT_PAINTLAYERBMP) :
tex.SetActiveLayer(layer, activatetexture=True, show=True) <-- Makes application unresponsive
print layer.GetBw(), layer.GetBh()
doc.EndUndo()
c4d.EventAdd()
print "Done"
if __name__=='__main__':
main()
The discussions mentions that the PaintTexture wasn't really working a few years ago, and bugs where reported (i.e AddLayerBmp() would not accept 'None') ... has anything changed since, or am I forced to switch to C++ just as all the others?