Hi @m_adam, Thank you I used py-texture_baker_r18 and I wanted to display an image preview inside the dialog, so I added a custom GUI to the dialog
bc = c4d.BaseContainer()
bc.SetBool(c4d.BITMAPBUTTON_BUTTON, False)
bc.SetLong(c4d.BITMAPBUTTON_BORDER, c4d.BORDER_THIN_IN)
self.myBitButton=self.AddCustomGui(self.BAKE_PREVIEW, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFH_LEFT | c4d.BFV_TOP, 512, 256, bc)
And from the CoreMessage() when the baking is finished I save the baked bitmap and then I set it as Image to my custom GUI Button
bmp.Save(self.filename, self.fileformat, c4d.BaseContainer(), c4d.SAVEBIT_ALPHA)
self.myBitButton.SetImage(self.filename, False)
The problem is that my saved image is largest then the GUI button size. And I want to resize this image to fit my custom bitmap button, and without using an external python library.
Or is it possible to set the baked bitmap as image without saving it. and then resizing it to ensure that fit the bitmap button.
# this doesn't work
bmp = self.textureBakerThread.bakeBmp """ bmp = <Objet c4d.bitmaps.MultipassBitmap à 0x000000001BF75850>"""
self.myBitButton.SetImage(bmp, False)
Here is the full example:
class TextureBakerThread(c4d.threading.C4DThread):
def __init__(self, doc, textags, texuvws, destuvws):
...
def Begin(self):
# Defines baking setting
bakeData = c4d.BaseContainer()
bakeData[c4d.BAKE_TEX_WIDTH] = 1024
bakeData[c4d.BAKE_TEX_HEIGHT] = 512
...
self.bakeData = bakeData
# Initializes bake process
bakeInfo = c4d.utils.InitBakeTexture(self.doc, self.textags, self.texuvws, self.destuvws, self.bakeData, self.Get())
self.bakeDoc = bakeInfo[0]
self.bakeError = bakeInfo[1]
if self.bakeError != c4d.BAKE_TEX_ERR_NONE or self.bakeDoc is None:
return False
# Starts bake thread
self.Start(c4d.THREADMODE_ASYNC, c4d.THREADPRIORITY_BELOW)
return True
def BakeTextureHook(self, info):
...
def Main(self):
...
class TextureBakerDlg(c4d.gui.GeDialog, TextureBakerHelper):
BUTTON_BAKE = 1000
BUTTON_ABORT = 1001
BAKE_PREVIEW = 1002
aborted = False
textureBakerThread = None
infoText = None
def CreateLayout(self):
# Defines the title
self.SetTitle("Texture Baker")
# Creates 2 buttons for Bake / Abort button
if self.GroupBegin(id=0, flags=c4d.BFH_SCALEFIT, rows=1, title="", cols=2, groupflags=0):
self.AddButton(id=self.BUTTON_BAKE, flags=c4d.BFH_LEFT, initw=100, inith=25, name="Bake")
self.AddButton(id=self.BUTTON_ABORT, flags=c4d.BFH_LEFT, initw=100, inith=25, name="Abort")
self.GroupEnd()
# Creates an image preview
bc = c4d.BaseContainer()
bc.SetBool(c4d.BITMAPBUTTON_BUTTON, False)
bc.SetLong(c4d.BITMAPBUTTON_BORDER, c4d.BORDER_THIN_IN)
self.myBitButton=self.AddCustomGui(self.BAKE_PREVIEW, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFH_LEFT | c4d.BFV_TOP, 512, 256, bc)
# Creates a statics text for the status
if self.GroupBegin(id=0, flags=c4d.BFH_SCALEFIT, rows=1, title="", cols=1, groupflags=0):
self.infoText = self.AddStaticText(id=0, initw=0, inith=0, name="", borderstyle=0, flags=c4d.BFH_SCALEFIT)
self.GroupEnd()
# Sets Button enable states so only bake button can be pressed
self.EnableButtons(False)
return True
def CoreMessage(self, id, msg):
# Checks if texture baking has finished
if id == PLUGIN_ID:
# Checks if texture baking has finished
if id == PLUGIN_ID:
# Sets Button enable states so only bake button can be pressed
self.EnableButtons(False)
# If not aborted, means the baking finished
if not self.aborted:
# Updates the information status
self.SetString(self.infoText, str("Baking Finished"))
# Retrieves the baked bitmap
bmp = self.textureBakerThread.bakeBmp
if bmp is None:
raise RuntimeError("Failed to retrieve the baked bitmap.")
# Displays the bitmap
c4d.bitmaps.ShowBitmap(bmp)
# Save the bitmap
bmp.Save(self.filename, self.fileformat, c4d.BaseContainer(), c4d.SAVEBIT_ALPHA)
self.myBitButton.SetImage(self.filename, False)
# Removes the reference to the C4D Thread, so the memory used is free
self.textureBakerThread = None
return True
else:
# If baking is aborted, updates the information status
self.SetString(self.infoText, str("Baking Aborted"))
return True
return c4d.gui.GeDialog.CoreMessage(self, id, msg)