Picture in UserData
-
On 11/05/2014 at 13:08, xxxxxxxx wrote:
Ok thanks.
I can't figure out how to apply the image to the button. In my C++ code I use SetImage() but it's not working in my UserData.import c4d,os def main() : fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path path = os.path.join(fn,'myimage.jpg') #The path to the image bc = c4d.GetCustomDatatypeDefault(c4d.CUSTOMDATATYPE_BITMAPBUTTON) bc[c4d.DESC_NAME] = 'my image' bc.SetFilename(12345, path) bc.SetImage(path, False) #<---Error...How do we add the image? entry = op.AddUserData(bc) c4d.SendCoreMessage(c4d.COREMSG_CINEMA, c4d.BaseContainer(c4d.COREMSG_CINEMA_FORCE_AM_UPDATE)) c4d.EventAdd() if __name__=='__main__': main()
-ScottA
-
On 11/05/2014 at 13:40, xxxxxxxx wrote:
First, the image needs to be loaded, of course. I use:
pic=bitmaps.BaseBitmap()
pic.InitWith(image_path)Then, the image needs to be registered with an unique ID (get it from plugincafe) :
c4d.gui.UnregisterIcon(UNIQUE_ID)
Now, place it in the UserData (or in the description) with something like this:
mypic=c4d.GetCustomDataTypeDefault(c4d.DTYPE_BOOL)
mypic[c4d.DESC_NAME] = "Preview"
mypic[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_BITMAPBUTTON
mypic[c4d.BITMAPBUTTON_ICONID1]=UNIQUE_ID
mypic[c4d.BITMAPBUTTON_ICONID2]=UNIQUE_ID
mypic[c4d.DESC_PARENTGROUP] = node.GetUserDataContainer()[0][0]
preview=node.AddUserData(pic)
node[preview]=1 -
On 11/05/2014 at 15:16, xxxxxxxx wrote:
Thanks Rui.
I didn't know we had to use registered IDs for images too.Here's a script example in case anyone needs it:
import c4d, os from c4d import gui, bitmaps def main() : #WARNING: Register your image with a unique ID from the plugincafe.com instead of 12345!! imageID = 12345 fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path path = os.path.join(fn,'myimage.jpg') #The path to the image image = bitmaps.BaseBitmap() image.InitWith(path) gui.RegisterIcon(imageID, image) obj = doc.GetActiveObject() if not obj: return False container = c4d.GetCustomDataTypeDefault(c4d.DTYPE_BOOL) container.SetString(c4d.DESC_NAME, "My Image") container.SetLong(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_BITMAPBUTTON) container.SetString(c4d.BITMAPBUTTON_TOOLTIP, "Click ME!") #container.SetLong(c4d.BITMAPBUTTON_BORDER, c4d.BORDER_OUT) #Creates a raised button border if that's desired container.SetLong(c4d.BITMAPBUTTON_BUTTON, True) #Creates indented border when the button is clicked container.SetLong(c4d.BITMAPBUTTON_ICONID1, 12345) #Off state: Puts your custom image on the button container.SetLong(c4d.BITMAPBUTTON_ICONID2, 5159) #On State: Puts a cube icon image on the button obj.AddUserData(container) #Adds the userData to the object c4d.EventAdd() if __name__=='__main__': main()
-ScottA
-
On 11/05/2014 at 15:40, xxxxxxxx wrote:
Using just c4d.EventAdd() to refresh the document is not enough.
We need to force an AM refresh with:c4d.SendCoreMessage(c4d.COREMSG_CINEMA, c4d.BaseContainer(c4d.COREMSG_CINEMA_FORCE_AM_UPDATE))
c4d.EventAdd() -
On 11/05/2014 at 16:53, xxxxxxxx wrote:
Does it not work for you without it?
It works fine for me without that code.The only time I've needed to use that code is when I'm deleting, or changing existing UserData items.
Mostly when I delete one UD item and leave other ones behind in the manager.
I've never needed to use that code when creating new UD items.-ScottA
-
On 11/05/2014 at 16:56, xxxxxxxx wrote:
Well, in my plugin I have to delete them all. So, I really need to force a refresh of the AM.
-
On 12/05/2014 at 00:38, xxxxxxxx wrote:
Hi ScottA
Is there maybe a way to resize the image button of that code of yours???
-
On 12/05/2014 at 07:57, xxxxxxxx wrote:
For which one?
CUSTOMGUI_BITMAPBUTTON - Changes it's size automatically depending on the size of the image used.
CUSTOMGUI_BITMAPBOOL - Displays an icon size of your image. Something like 32x32.I don't see any way to manually set the sizes for either of them.
But I could be wrong.-ScottA
-
On 12/05/2014 at 22:34, xxxxxxxx wrote:
Hi ScottA
I see this piece of code manually set the size off the button:
container.SetLong(c4d.BITMAPBUTTON_FORCE_SIZE, 64)
-
On 13/05/2014 at 08:10, xxxxxxxx wrote:
Good find. Thanks for posting it.
The SDK lists that as private. So I never tried it.-ScottA