Python Preview Plugin Help

On 26/11/2015 at 10:51, xxxxxxxx wrote:

Hey guys 🙂

So, I am trying to make a preview plugin like Magic Preview, butI just can't figure out, how to add a preview render to a dialog. I would like to make this, becuase I am making a lighting tool with alot of HDRI's and all that sort of stuff. It is pretty much completed, but I really want to make such a litle preview dialog for this tool. 
If anyone could help me ... that would be really awesome 😄

Have a good day, 

On 27/11/2015 at 10:22, xxxxxxxx wrote:


welcome to the Plugin Café forums 🙂

You will have to do this in two steps:

  1. Render your preview. Have a look at RenderDocument(), there's also some example code.
  2. Display the rendered image in your dialog. The easiest way is probably to use the BitmapButtonCustomGui. There are a bunch of threads in this forum regarding BitmapButtons. Like for example Add image to GUI.

I hope this helps.

On 28/11/2015 at 06:42, xxxxxxxx wrote:

Hey Andreas,

thanks for your reply helped me alot ^^
I managed to make everything "kinda" working, but my problem now is, that my Cinema 4D crashes when I click on my button to render that image and diasplay it on the button. I have no Idea why this is. Do you have an idea, or anyone?

but thanks anyway!


On 28/11/2015 at 06:55, xxxxxxxx wrote:

Well, depends on your code, really. 😉

On 28/11/2015 at 07:32, xxxxxxxx wrote:

I am fairly new to coding in CInema 4D and python so my code isn't the nicest and the most efficient one 😄 
This is my Code:

class OwlView(gui.GeDialog) :   
    def CreateLayout(self) :
        self.SetTitle("Owl View")

self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 0, 0, "Owl View", 0)
        path, fn = os.path.split(__file__)
        path = os.path.join(path, "res/icons/", "pre.tif")
        bc = c4d.BaseContainer()                                       
        bc.SetFilename(MY_BITMAP_BUTTON, path)              
        self.myBitButton=self.AddCustomGui(MY_BITMAP_BUTTON, c4d.CUSTOMGUI_BITMAPBUTTON, "PReview", c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT | c4d.BFH_CENTER | c4d.BFV_CENTER | c4d.BFV_BOTTOM, 30, 30, bc)
        self.myBitButton.SetImage(path, False)             
        return True

def Command(self, id, msg=None) :
        if id==MY_BITMAP_BUTTON:
           doc = documents.GetActiveDocument()
           rd = doc.GetActiveRenderData().GetData()
           xres = int(rd[c4d.RDATA_XRES])    
           yres = int(rd[c4d.RDATA_YRES])
           bmp = bitmaps.BaseBitmap()
           outp = documents.RenderDocument(doc, rd, bmp, c4d.RENDERFLAGS_EXTERNAL)
           if outp ==c4d.RENDERRESULT_OK:
                self.myBitButton.SetImage(bmp, False) 
                return True 
           return True

I don't know what I have done wrong, or not as supposed, and I know your not here to correct my code but I don't understand everything so that I could correct it myself ^^