I need to implement some sort of custom viewport or a custom material preview window in my object modifier or object generator plugin.
something like this:
Is it possible using python?
As I know, there is a BitmapButtonCustomGui class and maybe it can be used in order to accomplish this task, but I never used it and don't know how it works.
any tips or better ideas?
there is no thing like a custom viewport.
You can render a given scene (BaseDocument) with RenderDocument() using the hardware (OpenGL) renderer. Then you can display the resulting BaseBitmap in the GUI somehow. That is what the material preview is doing.
One way would be to use a GeDialog. In this case you could use a BitmapButtonCustomGui to display a BaseBitmap. This is something you could implement in Python.
Another way could be to add a bitmap button to the description of your object (CUSTOMDATATYPE_BITMAPBUTTON). Such a bitmap button would display a registered icon (BITMAPBUTTON_ICONID1). So you would have to register your bitmap as an icon using RegisterIcon(). But I haven't tried that and I don't know how well that would work.
A third solution would be to use the C++ SDK. Then you could define a custom data type which you could add to your object's parameter description. You could create a custom GUI for that data type that includes a GeUserArea that draws the bitmap the way you want.
You find more information on parameter descriptions in these manuals:
And more information on GeDialogs and GeUserAreas in these manuals:
You find examples on how to create custom data types or custom GUI elements in C++ here:
Seems like I figured it out but I'll keep investigating.
I tried this way and it kinda works. but let's assume that I want to scale the sphere object from my object generator plugin. It works only if I'm updating the render settings or reloading python plugins. Is it possible to update it according to the DIRTY FLAGS of the object generator plugin?
let me know if I'm doing something wrong.
you could set DIRTYFLAGS_DESCRIPTION after an interaction with the TEST_SLIDER parameter (e.g. in SetDParameter or after MSG_DESCRIPTION_POSTSETPARAMETER). That should update the description.
SetDParameter seems to be easier but seems like I'm doing something wrong. Can you provide a code snippet, how to do this properly?
I'm probably doing something wrong.
def SetDParameter(self, node, id, t_data, flags) :
if id.id == c4d.TEST_SLIDER:
it seems to work better if you change the dirty status of the bitmap. Something like this:
def GetDParameter(self, node, id, flags):
if id.id == c4d.THE_BITMAP_BUTTON:
data = c4d.BitmapButtonStruct(node, id, self.bmp.GetDirty())
return (True, data, flags | c4d.DESCFLAGS_GET_PARAM_GET)
def SetDParameter(self, node, id, t_data, flags):
if id.id == c4d.THE_OTHER_PARAMETER:
btw, is it possible to prevent the description from constant updates during manipulating the slider and set the DIRTYFLAGS when the slider is already set to the desired value?
Seems like C4D's material preview is capable of detecting time intervals between manipulations and if the interval is not high enough, no update takes place. Should I import pythons datetime or maybe it is possible to accomplish this task directly from c4d's module?
This goes off topic so I'll make a new post.
The main issue is already solved, thanks to Sebastian!