How does one use PaintTexture
On 10/01/2016 at 08:26, xxxxxxxx wrote:
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?
On 11/01/2016 at 03:59, xxxxxxxx wrote:
AddLayerBmp() should accept insertafter=None since R16 SP3. Could you link to the other threads you are referring to?
In a script of the Script Manger you don't have to call GetActiveDocument() and GetActiveObject() since "doc" and "op" are already defined.
To access the PaintMaterial one would have to use PaintMaterial::GetPaintMaterial() which is apparently currently not implemented in Python.
I can confirm that SetSelected_Texture() does not accept None. A bug report was filed. It is currently probably the best solution to switch to C++.
On 11/01/2016 at 07:11, xxxxxxxx wrote:
Thanks for the reply Sebastian.
Glad to see that AddLayerBmp was fixed.
As for the discussions I was referring to, I didn't bookmark them all, but here are a few:
Also, a big thank you to reminding me about the GetActiveDocument() and GetActiveObject() in a script. A bad habit I have, as I first try to write small portions that work as a script, and then combine all into a plugin. I guess I was already thinking in terms of the plugin.
So, for a plugin I will need to turn to C++, but for a quick script it seems there is no possibility to make it work in Python. Any alternative for scripts?