Bodypaint and Python

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 04 April 2014   #1
Bodypaint and Python

I wan to fill "Freeze 3D View" layer with bitmap from hdd.
I don't think it's possible to control "Freeze 3D View" dialog with python but at least I want to automate process of filling it with bitmap selected through explorer window.
I have some problems with c4d.modules.bodypaint.PaintLayerBmp classes.
When I feed ImportFromBaseBitmap() with bitmap object it gives me this error

"TypeError: descriptor 'ImportFromBaseBitmap' requires a 'c4d.modules.bodypaint.PaintLayerBmp' object but received a 'c4d.bitmaps.BaseBitmap'"

In SDK it's clearly written that this function requires BaseBitmap object.

I'm pretty sure I'm doing something fundamentally wrong.

import c4d
  from c4d import gui
  from c4d.modules import bodypaint
  from c4d import bitmaps, gui, storage
  #Welcome to the world of Python
  def main():
  	pl = bodypaint.PaintLayerBmp
  	bb = storage.LoadDialog(type=c4d.FILESELECTTYPE_IMAGES,   title="Please Choose a 32 Bit Image:")
  	orig = bitmaps.BaseBitmap()
  	print orig
  	pl.ImportFromBaseBitmap(orig, None)
  if __name__=='__main__':
Old 04 April 2014   #2
The error message is correct. You didn't create an instance of PaintLayerBitmap. Instead you passed a bitmap object to the function as first argument (for self).

class Foo
    def Bar(self):
        # do fancy stuff

foo = Bar()

# This line...

#... is the same as

So, the correct version would be

pl = bodypaint.PaintLayerBmp()

instead of

pl = bodypaint.PaintLayerBmp

The problem is, PaintLayerBmp cannot be instantiated. Instead you might get an object from somewhere - e.g: from PaintTexture.GetFirstLayer, ... What exactly do you want to do?

Hope this helps.

Cheers, donelgreeko
Old 04 April 2014   #3
I can use all of the bodypaint functions in the C++ SDK without any problems.
But not a single one in the python SDK works for me.

Here's a C++ example of using ImportFromBaseBitmap() to fill the current image in the TV window with a different bitmap image
//This is an example of using ImportFromBaseBitmap() to fill the first layer of a texture with a bitmap

Bool SimplePlugin::Execute(BaseDocument *doc)
	//Get the current image in the texture window
	PaintTexture *pTex = PaintTexture::GetSelectedTexture();
	if(!pTex) return FALSE;	

		Filename fn = Filename("C:\\Program Files\\MAXON\\Your C4D Version Here\\resource\\icons\\interface_icons.tif");
		AutoAlloc<BaseBitmap> bmp;
		if (IMAGERESULT_OK != bmp->Init(fn)) return FALSE;

		//Replace the first layer in the texture with the bitmap
		PaintLayerBmp *plb = (PaintLayerBmp*)pTex->GetLayerDownFirst();
		plb->ImportFromBaseBitmap(bmp, FALSE);

	return TRUE;

In Python.
I can't even do something as simple as grabbing the current image it the TV window because it's telling me I need to have params in my functions. But the docs say the params are void.
And when I try to use help() on them. I get this (...). What the heck does dot,dot,dot mean?
import c4d
import c4d.modules.bodypaint as bp

def main():

	t = bp.PaintTexture

	help (t)  #All of the methods have this in the parms(...) ???		
	pTex = t.GetPaintTexture() #<---error..needs params!?

if __name__=='__main__':

I just assumed all of this weirdness meant that bodypaint wasn't wrapped into Python yet.
But if it is wrapped. Then the current documentation is basically useless. And needs to be updated with some basic examples.

My Gallery
Old 04 April 2014   #4
Thank you guys for help.
I'm just trying to automate process of projection painting on some geometry through over two hundred cameras generated by photogrammetry software.
All those cameras names are matching with photos names so I made a little python generator to display photo on a background object corresponding with active cameras name.
This has greatly improved modeling workflow.

SDK has some nasty holes in it and for someone like me who just want to scratch only a surface of python scripting to be able to automate workflow it is hard sometimes to figure stuff out.

I was able to create something that works quite well.
This one just pastes an image you choose from disk to BP texture window, and no, "CLIPBOARDOWNER_PICTUREVIEWER" is not my mistake.
It appears that "CLIPBOARDOWNER_BODYPAINT" works only for picture viewer and the other one just for bodypaint.

BTW. Is there any chance to fill newly created layer mask with solid black color automatically?

     import c4d
     from c4d import gui
     from c4d import bitmaps, storage
     #Welcome to the world of Python
     def main():
     	bb = storage.LoadDialog(type=c4d.FILESELECTTYPE_IMAGES,   title="Please Choose an Image:")
     	orig = bitmaps.BaseBitmap()
     	c4d.CopyBitmapToClipboard(orig, c4d.CLIPBOARDOWNER_PICTUREVIEWER)
     	c4d.CallCommand(12108) # Paste
     	c4d.CallCommand(170051) # Add Layer Mask
     if __name__=='__main__':
reply share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 07:00 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.