CGTalk > Software > Maxon Cinema 4D
Login register
reply share thread « Previous Thread | Next Thread »  
Thread Tools Search this Thread Display Modes
Old 04-12-2014, 04:01 PM   #1
AdsovonMelk's Avatar
Join Date: Apr 2006
Posts: 230
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() orig.InitWith(bb) print orig pl.ImportFromBaseBitmap(orig, None) if __name__=='__main__': main()
Old 04-13-2014, 10:23 PM   #2
This line is rentable
Montréal, Canada
Join Date: Nov 2005
Posts: 301
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... foo.Bar() #... 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-14-2014, 07:09 PM   #3
Scott Ayers
Kaiju Creator
Scott Ayers
Join Date: Feb 2005
Posts: 1,033
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; if(pTex) { 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); } EventAdd(); 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__': 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-14-2014, 08:54 PM   #4
AdsovonMelk's Avatar
Join Date: Apr 2006
Posts: 230
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() orig.InitWith(bb) c4d.CopyBitmapToClipboard(orig, c4d.CLIPBOARDOWNER_PICTUREVIEWER) c4d.CallCommand(12108) # Paste c4d.CallCommand(170051) # Add Layer Mask if __name__=='__main__': main()
reply share thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 01:50 PM.

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