Picture in UserData
-
On 11/05/2014 at 07:25, xxxxxxxx wrote:
I guess this may work. However, I need to find a way to load a bitmap (that I know how to do) and assign it an ID to use with this CUSTOMGUI.
I know it needs to be a using ID (I already got it from Maxon). But, how to I assign an ID to an image so that I can reference it? -
On 11/05/2014 at 07:43, xxxxxxxx wrote:
Ok, found out how to assign an ID to a bitmap with gui.RegisterIcon
But the CUSTOMGUI_BITMAPBOOL only shows very small bitmaps. I need to show a 256x256 pixels bitmap. -
On 11/05/2014 at 07:45, xxxxxxxx wrote:
Ok! Found it!!!
CUSTOMGUI_BITMAPBUTTON
-
On 11/05/2014 at 07:51, xxxxxxxx wrote:
The problem with the method I posted Rui is that they are very small icon images. And I don't think it's possible to make them larger.
They are meant to be used on the small buttons. And can also be put on ComboButtons too.The only way I know how to make a 256x256 image in the AM is to use descriptions with a .res file. And using the GetDDescription() method in C++ to create a CUSTOMGUI_BITMAPBUTTON button with the image on it. Which can be scaled up very large. And can be set to non-clickable.
I have no idea how to do this in the UserData.
If you talk to Maxon again. You might want to ask them if it's possible to create a CUSTOMGUI_BITMAPBUTTON button in UD. Because that one will let you scale it up.Here's how to register your own icon so you can use an image on your buttons:
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!! #Or use your plugin ID# iconid = 12345 icon = bitmaps.BaseBitmap() icon.InitWith('C:\\Users\\User\\Desktop\\myimage.jpg') gui.RegisterIcon(iconid,icon) obj = doc.GetFirstObject() container = c4d.GetCustomDataTypeDefault(c4d.DTYPE_BOOL) container.SetString(c4d.DESC_NAME, "My UD") container.SetLong(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_BITMAPBOOL) container.SetLong(c4d.BITMAPBOOL_INACTIVE, 5159) #Sets the Ocube icon for the off state container.SetLong(c4d.BITMAPBOOL_ACTIVE, 12345) #Sets the image for the on state obj.AddUserData(container) obj[c4d.ID_USERDATA, 1] = 1 #Sets the default on/off state when UD is created c4d.EventAdd() if __name__=='__main__': main()
-ScottA
Edit- Lol. I wasn't fast enough again.
If you do figure out how to create a CUSTOMGUI_BITMAPBUTTON button in UD. Please share it. I'd like to know how to do that one too. -
On 11/05/2014 at 07:55, xxxxxxxx wrote:
I will share it. It is quite simple
Unfortunately I have to leave now for a meeting. But I will share it as soon as I get back. -
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