[Python] InitResourceBitmap
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/10/2011 at 14:30, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 12
Platform: Windows ;
Language(s) :---------
I think there is a mistake in the example given for using icons on the c4d.bitmaps page.It reads:
icon=bitmaps.IconResourceBitmap(c4d.RESOURCEIMAGE_MOVE)
Which results in the error: 'module' object has no attribute 'IconResourceBitmap'
I believe it's supposed to be:icon = bitmaps.InitResourceBitmap(c4d.RESOURCEIMAGE_MOVE)
Even after this is fixed. The example given still does not work as expected.
Simple R12 example:
def CreateLayout(self) : self.SetTitle("My Python Dialog") self.GroupBegin(999, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT) icon = bitmaps.InitResourceBitmap(c4d.RESOURCEIMAGE_MOVE) self.AddComboBox(1002, c4d.BFH_RIGHT) self.AddChild(1002, 0, icon) #<---Does not load the icon..It loads the string c4d.bitmaps.BaseBitmap object at 0x0FC040E0>!!! self.AddChild(1002, 1, "second option") self.GroupEnd() return True
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 24/10/2011 at 02:30, xxxxxxxx wrote:
Originally posted by xxxxxxxx
I think there is a mistake in the example given for using icons on the c4d.bitmaps page.
It reads:
icon=bitmaps.IconResourceBitmap(c4d.RESOURCEIMAGE_MOVE)
Which results in the error: 'module' object has no attribute 'IconResourceBitmap'
I believe it's supposed to be:icon = bitmaps.InitResourceBitmap(c4d.RESOURCEIMAGE_MOVE)
Thank you for reporting this mistake in the docs. I will fix that.
Originally posted by xxxxxxxx
Even after this is fixed. The example given still does not work as expected.
Simple R12 example:
def CreateLayout(self) : self.SetTitle("My Python Dialog") self.GroupBegin(999, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT) icon = bitmaps.InitResourceBitmap(c4d.RESOURCEIMAGE_MOVE) self.AddComboBox(1002, c4d.BFH_RIGHT) self.AddChild(1002, 0, icon) #<---Does not load the icon..It loads the string c4d.bitmaps.BaseBitmap object at 0x0FC040E0>!!! self.AddChild(1002, 1, "second option") self.GroupEnd() return True
Well in fact it works as expected .
GeDialog.AddChild() can only add strings to combo boxes or popup buttons. So in this case, it converts the bitmap to its string representation. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 24/10/2011 at 08:56, xxxxxxxx wrote:
It says: "Loads the global icon with ID resource_id."
It doesn't say it loads the icon's text information...It says it loads the icon.Then the example says: "returns bitmap from the list below"
The list below then shows the icon images and their ID#S.
All of this is implying that it's talking about adding icon images to things. Strings are never mentioned at all.The reason why this is so important to get right is because I've found no way to put an icon image on a button through the same means used in COFFEE & C++.
In C++ the convention is as follows:
GroupBegin(0,BFH_LEFT,2,0,"",0); { AddComboBox(MY_COMBOBUTTON2, BFH_SCALEFIT); AddChild(MY_COMBOBUTTON2, 0, GeLoadString(IDS_CUBE)+"&i"+LongToString(Ocube)+"&"); //IDS_CUBE is declared in the c4d_symbols.h file.& the text is in c4d_strings.str } GroupEnd();
That code will put the sphere icon on the button.
I can't find any variation of this to work in Python. Not even in a Resource based dialog plugin.
In fact. The only way I've been able to load an icon at all with python is to use the descriptions in the .res file like this:LONG MULTIBUTTON { CYCLE { MULTI_ONE; MULTI_TWO~1234567; //The id# for the icon that's displayed on my button } }
My efforts to load icons through any other means has not worked.
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 24/10/2011 at 10:08, xxxxxxxx wrote:
Originally posted by xxxxxxxx
It says: "Loads the global icon with ID resource_id."
It doesn't say it loads the icon's text information...It says it loads the icon.Originally posted by xxxxxxxx
GeDialog.AddChild() can only add strings to combo boxes or popup buttons. So in this case, it converts the bitmap to its string representation.
I said that about this line:
self.AddChild(1002, 0, icon) #<---Does not load the icon..It loads the string c4d.bitmaps.BaseBitmap object at 0x0FC040E0>!!!
I wasn't talking about InitResourceBitmap().
Originally posted by xxxxxxxx
The reason why this is so important to get right is because I've found no way to put an icon image on a button through the same means used in COFFEE & C++.
In C++ the convention is as follows:
GroupBegin(0,BFH_LEFT,2,0,"",0); { AddComboBox(MY_COMBOBUTTON2, BFH_SCALEFIT); AddChild(MY_COMBOBUTTON2, 0, GeLoadString(IDS_CUBE)+"&i"+LongToString(Ocube)+"&"); //IDS_CUBE is declared in the c4d_symbols.h file.& the text is in c4d_strings.str } GroupEnd();
That code will put the sphere icon on the button.
I can't find any variation of this to work in Python. Not even in a Resource based dialog plugin.
In fact. The only way I've been able to load an icon at all with python is to use the descriptions in the .res file like this:LONG MULTIBUTTON { CYCLE { MULTI_ONE; MULTI_TWO~1234567; //The id# for the icon that's displayed on my button } }
My efforts to load icons through any other means has not worked.
OK I understand better now. One can pass icon IDs or even bitmap pointers in the child string passed to GeDialog.AddChild().
I'll talk with Sebastian because this could be a bug.
EDIT:
OK, found a solution. No need of InitResourceBitmap() :
self.AddChild(1002, 0, "first option&i" + str(c4d.RESOURCEIMAGE_MOVE) + "&")
It seems the "child" string parameter should be always formatted as 2 concatenated strings with '&'. The first string is the child item text, the second is the bitmap data. And 'i' is added to tell the string parser that it has to retrieve an icon ID not a bitmap.
And the pointer version:
self.AddChild(1002, 0, "first option&" + str(icon) + "&")
does not work as expected. I don't know if this is normal or a bug.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 24/10/2011 at 10:46, xxxxxxxx wrote:
Excellent!
I can make due without the pointer version.Thanks a lot.
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/10/2011 at 04:55, xxxxxxxx wrote:
Hi,
If you want to use a custom icon, you have to register it with RegisterIcon (id, bmp). You can then use this custom ID the same way as CINEMA 4D icon IDs to identify the registered icon.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/10/2011 at 09:41, xxxxxxxx wrote:
Yeah. I already know how that from doing it in C++.
But thank you for the advice.As long as we're talking about icons and images here. There's one last thing about them I haven't figured out yet.
I haven't been able to use icons on the standard buttons (Not the drop down ComboBox type of buttons) in either C++ or Python.
Neither the AddButton() method. Or using an external resource BUTTON way lets me do it like I've been doing it with ComboBox buttons.Is there a way to use icons on those buttons?
Or is it a known limitation?-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/10/2011 at 12:06, xxxxxxxx wrote:
Originally posted by xxxxxxxx
As long as we're talking about icons and images here. There's one last thing about them I haven't figured out yet.
I haven't been able to use icons on the standard buttons (Not the drop down ComboBox type of buttons) in either C++ or Python.
Neither the AddButton() method. Or using an external resource BUTTON way lets me do it like I've been doing it with ComboBox buttons.Is there a way to use icons on those buttons?
Or is it a known limitation?As far as I know, the only way to display icons on buttons is with the BitmapButtonCustomGui.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/10/2011 at 12:15, xxxxxxxx wrote:
That's what I thought.
But I needed to get "official" confirmation on it.Thanks,
-ScottA -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/02/2012 at 09:00, xxxxxxxx wrote:
I too am having trouble with custom buttons and I havent been able to find any good examples of "BitmapButtonCustomGui". Any suggestions? I simply want to add one of the c4d resource button icons to a button I have created in my GeDialog.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/02/2012 at 19:10, xxxxxxxx wrote:
I'm afraid I can't give you any answers to that one marc.
In C++ it's very simple like this://C++ example that puts a sphere icon on a customGui button GroupBegin(0,BFH_LEFT,2,0,"MySecondGroup",0); { BaseContainer bc; //Create a container to hold our custom button gizmo bc.SetLong(BITMAPBUTTON_BORDER, BORDER_OUT); //Make the button style raised so it looks like a button bc.SetBool(BITMAPBUTTON_BUTTON, TRUE); //Make it act like a button myButton = (BitmapButtonCustomGui* )AddCustomGui(10001,CUSTOMGUI_BITMAPBUTTON,"MY BUTTON", 0L,80,80,bc); //Adds the BitmapButton GUI to the dialog myButton->SetImage(Osphere, FALSE); //Adds the sphere icon to the button } GroupEnd();
But in python there is no casting. And the SDK has no code to help in the conversion.
#Python version that does **not** work #Keeps saying SetImage() is using the wrong type self.GroupBegin(0, c4d.BFH_SCALEFIT|c4d.BFH_SCALEFIT, 1, 1, "Bitmap Example",0) bc = c4d.BaseContainer() #Create a new container to store the button image bc.SetLong(c4d.BITMAPBUTTON_BORDER, c4d.BORDER_OUT) #Sets the border to look like a button bc.SetBool(c4d.BITMAPBUTTON_BUTTON, True) #<-------------------#Does not seem to to work in R13? self.myBitButton=self.AddCustomGui(MY_BITMAP_BUTTON, c4d.CUSTOMGUI_BITMAPBUTTON, "Bitmap Button", c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 30, 30, bc) self.myBitButton = gui.BitmapButtonCustomGui self.myBitButton.SetImage(c4d.Osphere, False,False) #<----Error: Not the right object type!!! self.GroupEnd()
I've been using a direct file path method to load images(even icons). And waiting for someone to post a working example of BitmapButtonCustomGui with python.
If nobody helps you. And you need an alternative(using hard a coded path). I'll post my file path method if you need it.
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/02/2012 at 01:26, xxxxxxxx wrote:
Originally posted by xxxxxxxx
But in python there is no casting. And the SDK has no code to help in the conversion.
#Python version that does **not** work #Keeps saying SetImage() is using the wrong type self.myBitButton=self.AddCustomGui(MY_BITMAP_BUTTON, c4d.CUSTOMGUI_BITMAPBUTTON, "Bitmap Button", c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 30, 30, bc) self.myBitButton = gui.BitmapButtonCustomGui self.myBitButton.SetImage(c4d.Osphere, False,False) #<----Error: Not the right object type!!!
I've been using a direct file path method to load images(even icons). And waiting for someone to post a working example of BitmapButtonCustomGui with python.
AddCustomGui() returns a BitmapButtonCustomGui object in this case... Python has no casting but it's dynamic.
Originally posted by xxxxxxxx
self.myBitButton = gui.BitmapButtonCustomGui
And with this line you just assign BitmapButtonCustomGui type.
BitmapButtonCustomGui.SetImage() is used to load custom images from a filename string, bitmap or icon data dictionary. To load an image from an ID there's BITMAPBUTTON_ICONID1 and BITMAPBUTTON_ICONID2 container entries of the settings for the BitmapButtonCustomGui:
bc.SetLong(c4d.BITMAPBUTTON_ICONID1, c4d.Osphere)
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/02/2012 at 07:20, xxxxxxxx wrote:
Scott...Thanks so much for the help! I am a total newbie at this and you were a tremendous help!
Yannick...YOU ROCK!!!!!
I am very much a beginner at all of this. I am a designer by trade and choice, but am using Python to push my abilities in C4D. I must say that this was a hurdle I wasn't sure if I could beat, but you have saved the day! MANY MANY THANKS!
This worked like a charm:
self.GroupBegin(0, c4d.BFH_CENTER | c4d.BFH_CENTER, 2, 0, "", 0) #id, flags, cols, rows, title, groupflags
############# ICON BUTTON ###################
bc = c4d.BaseContainer() ######Create a new container to store the button image
bc.SetLong(c4d.BITMAPBUTTON_ICONID1, c4d.RESOURCEIMAGE_MOVE) #####Sets Button Icon
bc.SetBool(c4d.BITMAPBUTTON_BUTTON, True)
self.myBitButton=self.AddCustomGui(BUTTON_SELECT_MOVE, c4d.CUSTOMGUI_BITMAPBUTTON, "Bend", c4d.BFH_CENTER | c4d.BFV_CENTER, 32, 32, bc)
self.myBitButton = gui.BitmapButtonCustomGui -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/02/2012 at 07:23, xxxxxxxx wrote:
add this with the info on :
http://chicagoc4d.com/C4DPythonSDK/modules/c4d.bitmaps/index.html?highlight=initresource#c4d.bitmaps.InitResourceBitmapand thats it!
Again, THANKS GUYS!
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/02/2012 at 08:02, xxxxxxxx wrote:
Now I just have to find the objects that arent on that list haha. I know they exist b/c C4D uses icons for them lol.
The hunt continues...
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/02/2012 at 08:18, xxxxxxxx wrote:
Search your MAXON folder for this file: "interface_icons.txt"
It has a list of the icons and their ID#s.You also don't need this line of code:self.myBitButton = gui.BitmapButtonCustomGui
I only posted it because I didn't know how to work it into the solution. I just put in there so whoever wanted to take a look at the problem had all the pieces to work with.Here a complete R13 script example of a button with an icon on it:
import c4d,os from c4d import gui,bitmaps MY_BITMAP_BUTTON = 1003 class MyDialog(c4d.gui.GeDialog) : def CreateLayout(self) : self.SetTitle("My Python Dialog") self.GroupBegin(0, c4d.BFH_SCALEFIT|c4d.BFH_SCALEFIT, 1, 1, "Bitmap Example",0) bc = c4d.BaseContainer() ######Create a new container to store the button image bc.SetLong(c4d.BITMAPBUTTON_BORDER, c4d.BORDER_OUT) #Sets the border to look like a button bc.SetLong(c4d.BITMAPBUTTON_ICONID1, c4d.RESOURCEIMAGE_MOVE) #####Sets Button Icon bc.SetBool(c4d.BITMAPBUTTON_BUTTON, True) #<---Does Not animate in R13!? self.myBitButton=self.AddCustomGui(MY_BITMAP_BUTTON, c4d.CUSTOMGUI_BITMAPBUTTON, "My Button", c4d.BFH_CENTER | c4d.BFV_CENTER, 50, 50, bc) self.GroupEnd() return True #Do something when the button is pressed def Command(self, id, msg=None) : if id==MY_BITMAP_BUTTON: print "Hello" return True if __name__=='__main__': dlg = MyDialog() dlg.Open(c4d.DLG_TYPE_ASYNC, defaultw=100, defaulth=100)
I still don't know why buttons don't animate when it's clicked in R13. Like they used to do in 12.
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/02/2012 at 08:39, xxxxxxxx wrote:
Thanks Scott!
I was just being stupid haha. I already had the ID's for those elsewhere in my code...all I had to do was scroll down haha.
Thanks again! HUGE help
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/02/2012 at 08:40, xxxxxxxx wrote:
btw...when you say "animate"...do you mean the down/toggle state. When the user clicks it?
I am using R13 and when I click these they have what appears to be a "down" state.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/02/2012 at 08:57, xxxxxxxx wrote:
Yeah. That's what I'm referring to.
It does not animate in R13 for me if I use: bc.SetLong(c4d.BITMAPBUTTON_BORDER, c4d.BORDER_OUT)However, It does animate using this layout format in R12.
Something must have changed.
I'm not sure if it's a bug or not. But I prefer the way it worked in R12.-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 14/02/2012 at 12:00, xxxxxxxx wrote:
Scott,
I have the icons implemented and they are working great!
When I click on the icon, a border appears around it while the mouse button is held down... giving it the impression of a downstate. The appearance of the icon itself doesnt change, but the border indicates the down state. Tested in R12 and R13 and the functionality is the same in both.
I see what you are saying about the toggle state in your case. You want to add the BORDER_OUT to make it look more like a button, and you want that to change when clicked.
I will keep my eyes peeled and if I run across something I will post it here